Skip to content

Commit

Permalink
🐛 remove static map, so that each symbol provider for a search is new (
Browse files Browse the repository at this point in the history
…#103)

* 🐛 remove static map, so that each symbol provider for a seach is new

Signed-off-by: Shawn Hurley <[email protected]>

* remove static block from default provider

Signed-off-by: Shawn Hurley <[email protected]>

---------

Signed-off-by: Shawn Hurley <[email protected]>
  • Loading branch information
shawn-hurley authored Jul 16, 2024
1 parent dcae7c2 commit f1fc8a3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class SymbolInformationTypeRequestor extends SearchRequestor {
private int symbolKind;
private String query;
private AnnotationQuery annotationQuery;
private SymbolProviderResolver resolver;


public SymbolInformationTypeRequestor(List<SymbolInformation> symbols, int maxResults, IProgressMonitor monitor, int symbolKind, String query, AnnotationQuery annotationQuery) {
this.symbols = symbols;
Expand All @@ -44,6 +46,7 @@ public SymbolInformationTypeRequestor(List<SymbolInformation> symbols, int maxRe
if (maxResults == 0) {
this.maxResults = 10000;
}
resolver = new SymbolProviderResolver();
}


Expand All @@ -70,7 +73,7 @@ public void acceptSearchMatch(SearchMatch match) throws CoreException {

}

SymbolProvider symbolProvider = SymbolProviderResolver.resolve(this.symbolKind);
SymbolProvider symbolProvider = resolver.resolve(this.symbolKind);
if (symbolProvider instanceof WithQuery) {
((WithQuery) symbolProvider).setQuery(this.query);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public boolean visit(MethodInvocation node) {
this.symbolMatches = true;
return false;
} catch (Exception e) {
logInfo("error visiting MethodInvocation node: " + e);
logInfo("KONVEYOR_LOG: error visiting MethodInvocation node: " + e);
// this is so that we fallback and don't lose a match when we fail
this.symbolMatches = true;
return false;
Expand All @@ -122,7 +122,7 @@ public boolean visit(ConstructorInvocation node) {
// get fqn of the method being called
ITypeBinding declaringClass = binding.getDeclaringClass();
if (declaringClass != null) {
String fullyQualifiedName = declaringClass.getQualifiedName() + "." + binding.getName();
String fullyQualifiedName = declaringClass.getQualifiedName();
// match fqn with query pattern
if (fullyQualifiedName.matches(this.query)) {
this.symbolMatches = true;
Expand All @@ -139,7 +139,7 @@ public boolean visit(ConstructorInvocation node) {
this.symbolMatches = true;
return false;
} catch (Exception e) {
logInfo("error visiting ConstructorInvocation node: " + e);
logInfo("KONVEYOR_LOG: error visiting ConstructorInvocation node: " + e);
// this is so that we fallback and don't lose a match when we fail
this.symbolMatches = true;
return false;
Expand All @@ -162,7 +162,7 @@ public boolean visit(ClassInstanceCreation node) {
// get fqn of the method being called
ITypeBinding declaringClass = binding.getDeclaringClass();
if (declaringClass != null) {
String fullyQualifiedName = declaringClass.getQualifiedName() + "." + binding.getName();
String fullyQualifiedName = declaringClass.getQualifiedName();
// match fqn with query pattern
if (fullyQualifiedName.matches(this.query)) {
this.symbolMatches = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
import org.eclipse.lsp4j.SymbolInformation;

public class DefaultSymbolProvider implements SymbolProvider, WithQuery, WithMaxResults {
private static List<SymbolProvider> defaultProviders;
static {
defaultProviders= new ArrayList<SymbolProvider>();
defaultProviders.add(new MethodCallSymbolProvider());
defaultProviders.add(new ConstructorCallSymbolProvider());
defaultProviders.add(new ImportSymbolProvider());
defaultProviders.add( new TypeSymbolProvider());
private List<SymbolProvider> defaultProviders;

public DefaultSymbolProvider() {
this. defaultProviders= new ArrayList<SymbolProvider>();
this. defaultProviders.add(new MethodCallSymbolProvider());
this.defaultProviders.add(new ConstructorCallSymbolProvider());
this.defaultProviders.add(new ImportSymbolProvider());
this.defaultProviders.add( new TypeSymbolProvider());
}

private int maxResults;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import java.util.Map;
import java.util.Optional;

import org.eclipse.jdt.core.search.SearchMatch;

public class SymbolProviderResolver {
private static Map<Integer, SymbolProvider> map;
static {
private Map<Integer, SymbolProvider> map;

public SymbolProviderResolver() {
map = new HashMap<>();
map.put(1, new InheritanceSymbolProvider());
map.put(2, new MethodCallSymbolProvider());
Expand All @@ -25,7 +24,7 @@ public class SymbolProviderResolver {
map.put(13, new MethodDeclarationSymbolProvider());
}

public static SymbolProvider resolve(Integer i) {
return Optional.ofNullable(map.get(i)).orElse(new DefaultSymbolProvider());
public SymbolProvider resolve(Integer i) {
return Optional.ofNullable(this.map.get(i)).orElse(new DefaultSymbolProvider());
}
}

0 comments on commit f1fc8a3

Please sign in to comment.