Skip to content

Commit 8adc707

Browse files
authored
Merge pull request #2368 from Haehnchen/feature/controller-maker
reduce calling ControllerMethodLineMarkerProvider collect usages
2 parents 542c7be + cc86367 commit 8adc707

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/ControllerMethodLineMarkerProvider.java

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,43 +35,54 @@ public LineMarkerInfo<?> getLineMarkerInfo(@NotNull PsiElement psiElement) {
3535
return null;
3636
}
3737

38-
@Nullable
39-
public LineMarkerInfo<?> collect(PsiElement psiElement) {
40-
if(!Symfony2ProjectComponent.isEnabled(psiElement) || psiElement.getNode().getElementType() != PhpTokenTypes.IDENTIFIER) {
41-
return null;
38+
@Override
39+
public void collectSlowLineMarkers(@NotNull List<? extends PsiElement> psiElements, @NotNull Collection<? super LineMarkerInfo<?>> results) {
40+
if (psiElements.isEmpty() || !Symfony2ProjectComponent.isEnabled(psiElements.get(0))) {
41+
return;
4242
}
4343

44-
PsiElement method = psiElement.getParent();
45-
if(!(method instanceof Method) || !((Method) method).getAccess().isPublic()) {
46-
return null;
47-
}
44+
for (PsiElement psiElement: psiElements) {
45+
if (psiElement.getNode().getElementType() != PhpTokenTypes.IDENTIFIER || !(psiElement.getParent() instanceof Method method)) {
46+
continue;
47+
}
4848

49-
List<GotoRelatedItem> gotoRelatedItems = getGotoRelatedItems((Method) method);
49+
LineMarkerInfo<?> lineMarkerInfo = collect(psiElement, method);
50+
if (lineMarkerInfo != null) {
51+
results.add(lineMarkerInfo);
52+
}
53+
}
54+
}
5055

51-
if(gotoRelatedItems.isEmpty()) {
56+
@Nullable
57+
public LineMarkerInfo<?> collect(@NotNull PsiElement psiElement, Method method) {
58+
if (!method.getAccess().isPublic()) {
5259
return null;
5360
}
5461

55-
// only one item dont need popover
56-
if(gotoRelatedItems.size() == 1) {
62+
List<GotoRelatedItem> gotoRelatedItems = getGotoRelatedItems(method);
63+
if (gotoRelatedItems.isEmpty()) {
64+
return null;
65+
}
5766

67+
// only one item don't need popover
68+
if (gotoRelatedItems.size() == 1) {
5869
GotoRelatedItem gotoRelatedItem = gotoRelatedItems.get(0);
5970

6071
// hell: find any possible small icon
6172
Icon icon = null;
62-
if(gotoRelatedItem instanceof RelatedPopupGotoLineMarker.PopupGotoRelatedItem) {
73+
if (gotoRelatedItem instanceof RelatedPopupGotoLineMarker.PopupGotoRelatedItem) {
6374
icon = ((RelatedPopupGotoLineMarker.PopupGotoRelatedItem) gotoRelatedItem).getSmallIcon();
6475
}
6576

66-
if(icon == null) {
77+
if (icon == null) {
6778
icon = Symfony2Icons.SYMFONY_LINE_MARKER;
6879
}
6980

7081
NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(icon).
7182
setTargets(gotoRelatedItems.get(0).getElement());
7283

7384
String customName = gotoRelatedItems.get(0).getCustomName();
74-
if(customName != null) {
85+
if (customName != null) {
7586
builder.setTooltipText(customName);
7687
}
7788

@@ -90,27 +101,12 @@ public LineMarkerInfo<?> collect(PsiElement psiElement) {
90101
}
91102

92103
public static List<GotoRelatedItem> getGotoRelatedItems(Method method) {
93-
94104
List<GotoRelatedItem> gotoRelatedItems = new ArrayList<>();
95-
96105
ControllerActionGotoRelatedCollectorParameter parameter = new ControllerActionGotoRelatedCollectorParameter(method, gotoRelatedItems);
97-
for(ControllerActionGotoRelatedCollector extension : EP_NAME.getExtensions()) {
106+
for (ControllerActionGotoRelatedCollector extension : EP_NAME.getExtensions()) {
98107
extension.collectGotoRelatedItems(parameter);
99108
}
100109

101110
return gotoRelatedItems;
102111
}
103-
104-
@Override
105-
public void collectSlowLineMarkers(@NotNull List<? extends PsiElement> psiElements, @NotNull Collection<? super LineMarkerInfo<?>> results) {
106-
107-
for(PsiElement psiElement: psiElements) {
108-
LineMarkerInfo<?> lineMarkerInfo = collect(psiElement);
109-
if(lineMarkerInfo != null) {
110-
results.add(lineMarkerInfo);
111-
}
112-
}
113-
114-
}
115-
116112
}

0 commit comments

Comments
 (0)