From 92950d14d0524a5875f3760c2b0b57c06518ebd9 Mon Sep 17 00:00:00 2001 From: Tomasz Pasternak Date: Mon, 31 Aug 2020 14:17:51 +0200 Subject: [PATCH] Optimize line marker provider (#93) There's no need to check anything in the Thrift index if the class does not implement a Thrift base class. Thrift base class name may differ among compilers. For now, the supported ones are: Apache Thrift compiler and Scrooge --- .../editor/GoToThriftDefinitionMarkerProvider.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/thrift/src/main/java/com/intellij/plugins/thrift/editor/GoToThriftDefinitionMarkerProvider.java b/thrift/src/main/java/com/intellij/plugins/thrift/editor/GoToThriftDefinitionMarkerProvider.java index 9e8e66db..b23f6863 100644 --- a/thrift/src/main/java/com/intellij/plugins/thrift/editor/GoToThriftDefinitionMarkerProvider.java +++ b/thrift/src/main/java/com/intellij/plugins/thrift/editor/GoToThriftDefinitionMarkerProvider.java @@ -8,8 +8,10 @@ import java.util.Collection; import java.util.List; import java.util.Optional; +import java.util.Set; import com.google.common.base.Stopwatch; +import com.google.common.collect.Sets; import com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo; import com.intellij.codeInsight.daemon.RelatedItemLineMarkerProvider; import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder; @@ -30,10 +32,20 @@ public class GoToThriftDefinitionMarkerProvider extends RelatedItemLineMarkerProvider { static Logger logger = Logger.getInstance(GoToThriftDefinition.class); + private static Set thriftStructBaseClasses = + Sets.newHashSet( + "com.twitter.scrooge.ThriftStruct", + "org.apache.thrift.TBase" + ); + + private boolean isThriftStruct(PsiClass element) { + return Arrays.stream(element.getSupers()).anyMatch(superClass -> thriftStructBaseClasses.contains(superClass.getQualifiedName())); + } + @Override protected void collectNavigationMarkers(@NotNull PsiElement element, @NotNull Collection> result) { - if (element instanceof PsiClass) { + if (element instanceof PsiClass && isThriftStruct((PsiClass)element)) { PsiClass psiClass = (PsiClass) element; String name = psiClass.getName(); if (name != null) {