Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Commit

Permalink
Optimize line marker provider (#93)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Tomasz Pasternak authored Aug 31, 2020
1 parent c98bff0 commit 92950d1
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,10 +32,20 @@
public class GoToThriftDefinitionMarkerProvider extends RelatedItemLineMarkerProvider {
static Logger logger = Logger.getInstance(GoToThriftDefinition.class);

private static Set<String> 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<? super RelatedItemLineMarkerInfo<?>> result) {
if (element instanceof PsiClass) {
if (element instanceof PsiClass && isThriftStruct((PsiClass)element)) {
PsiClass psiClass = (PsiClass) element;
String name = psiClass.getName();
if (name != null) {
Expand Down

0 comments on commit 92950d1

Please sign in to comment.