Skip to content

Commit

Permalink
🐛 remove static map, so that each symbol provider for a seach is new
Browse files Browse the repository at this point in the history
Signed-off-by: Shawn Hurley <[email protected]>
  • Loading branch information
shawn-hurley committed Jul 15, 2024
1 parent 68082cb commit 5763789
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class SymbolInformationTypeRequestor extends SearchRequestor {
private IProgressMonitor monitor;
private int symbolKind;
private String query;
private SymbolProviderResolver resolver;


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


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

}

SymbolProvider symbolProvider = SymbolProviderResolver.resolve(this.symbolKind, match);
SymbolProvider symbolProvider = resolver.resolve(this.symbolKind, match);
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("KONEYOR_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 @@ -7,8 +7,9 @@
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 @@ -23,7 +24,7 @@ public class SymbolProviderResolver {
map.put(11, new ReferenceSymbolProvider());
}

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

0 comments on commit 5763789

Please sign in to comment.