Skip to content

Commit

Permalink
Merge pull request #2368 from Haehnchen/feature/controller-maker
Browse files Browse the repository at this point in the history
reduce calling ControllerMethodLineMarkerProvider collect usages
  • Loading branch information
Haehnchen committed Apr 28, 2024
2 parents 542c7be + cc86367 commit 8adc707
Showing 1 changed file with 27 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,43 +35,54 @@ public LineMarkerInfo<?> getLineMarkerInfo(@NotNull PsiElement psiElement) {
return null;
}

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

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

List<GotoRelatedItem> gotoRelatedItems = getGotoRelatedItems((Method) method);
LineMarkerInfo<?> lineMarkerInfo = collect(psiElement, method);
if (lineMarkerInfo != null) {
results.add(lineMarkerInfo);
}
}
}

if(gotoRelatedItems.isEmpty()) {
@Nullable
public LineMarkerInfo<?> collect(@NotNull PsiElement psiElement, Method method) {
if (!method.getAccess().isPublic()) {
return null;
}

// only one item dont need popover
if(gotoRelatedItems.size() == 1) {
List<GotoRelatedItem> gotoRelatedItems = getGotoRelatedItems(method);
if (gotoRelatedItems.isEmpty()) {
return null;
}

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

// hell: find any possible small icon
Icon icon = null;
if(gotoRelatedItem instanceof RelatedPopupGotoLineMarker.PopupGotoRelatedItem) {
if (gotoRelatedItem instanceof RelatedPopupGotoLineMarker.PopupGotoRelatedItem) {
icon = ((RelatedPopupGotoLineMarker.PopupGotoRelatedItem) gotoRelatedItem).getSmallIcon();
}

if(icon == null) {
if (icon == null) {
icon = Symfony2Icons.SYMFONY_LINE_MARKER;
}

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

String customName = gotoRelatedItems.get(0).getCustomName();
if(customName != null) {
if (customName != null) {
builder.setTooltipText(customName);
}

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

public static List<GotoRelatedItem> getGotoRelatedItems(Method method) {

List<GotoRelatedItem> gotoRelatedItems = new ArrayList<>();

ControllerActionGotoRelatedCollectorParameter parameter = new ControllerActionGotoRelatedCollectorParameter(method, gotoRelatedItems);
for(ControllerActionGotoRelatedCollector extension : EP_NAME.getExtensions()) {
for (ControllerActionGotoRelatedCollector extension : EP_NAME.getExtensions()) {
extension.collectGotoRelatedItems(parameter);
}

return gotoRelatedItems;
}

@Override
public void collectSlowLineMarkers(@NotNull List<? extends PsiElement> psiElements, @NotNull Collection<? super LineMarkerInfo<?>> results) {

for(PsiElement psiElement: psiElements) {
LineMarkerInfo<?> lineMarkerInfo = collect(psiElement);
if(lineMarkerInfo != null) {
results.add(lineMarkerInfo);
}
}

}

}

0 comments on commit 8adc707

Please sign in to comment.