diff --git a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/ConstructorCallSymbolProvider.java b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/ConstructorCallSymbolProvider.java index 670da70..1bf8cdb 100644 --- a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/ConstructorCallSymbolProvider.java +++ b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/ConstructorCallSymbolProvider.java @@ -48,31 +48,11 @@ public List get(SearchMatch match) throws CoreException { astParser.setSource(unit); astParser.setResolveBindings(true); CompilationUnit cu = (CompilationUnit) astParser.createAST(null); - cu.accept(new ASTVisitor() { - // we are only doing this for MethodInvocation right now - // look into MethodDeclaration if needed - public boolean visit(MethodInvocation node) { - try { - IMethodBinding binding = node.resolveMethodBinding(); - if (binding != null) { - // get fqn of the method being called - ITypeBinding declaringClass = binding.getDeclaringClass(); - if (declaringClass != null) { - String fullyQualifiedName = declaringClass.getQualifiedName() + "." + binding.getName(); - // match fqn with query pattern - if (fullyQualifiedName.matches(getCleanedQuery(query))) { - symbols.add(symbol); - } else { - logInfo("fqn " + fullyQualifiedName + " did not match with " + query); - } - } - } - } catch (Exception e) { - logInfo("error determining accuracy of match: " + e); - } - return true; - } - }); + CustomASTVisitor visitor = new CustomASTVisitor(query, match); + cu.accept(visitor); + if (visitor.symbolMatches()) { + symbols.add(symbol); + } } else { symbols.add(symbol); } diff --git a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/CustomASTVisitor.java b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/CustomASTVisitor.java new file mode 100644 index 0000000..7251e70 --- /dev/null +++ b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/CustomASTVisitor.java @@ -0,0 +1,86 @@ +package io.konveyor.tackle.core.internal.symbol; + +import org.eclipse.jdt.core.dom.ASTVisitor; +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.IMethodBinding; +import org.eclipse.jdt.core.dom.ITypeBinding; +import org.eclipse.jdt.core.dom.MethodInvocation; +import org.eclipse.jdt.core.search.SearchMatch; + +import static org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin.logInfo; + +public class CustomASTVisitor extends ASTVisitor { + private String query; + private SearchMatch match; + private boolean symbolMatches; + + + public CustomASTVisitor(String query, SearchMatch match) { + /* + * When comparing query pattern with an actual java element's fqn + * we need to make sure that * not preceded with a . are replaced + * by .* so that java regex works as expected on them + */ + this.query = query.replaceAll("(? get(SearchMatch match) { astParser.setSource(unit); astParser.setResolveBindings(true); CompilationUnit cu = (CompilationUnit) astParser.createAST(null); - cu.accept(new ASTVisitor() { - // we are only doing this for MethodInvocation right now - // look into MethodDeclaration if needed - public boolean visit(MethodInvocation node) { - try { - IMethodBinding binding = node.resolveMethodBinding(); - if (binding != null) { - // get fqn of the method being called - ITypeBinding declaringClass = binding.getDeclaringClass(); - if (declaringClass != null) { - String fullyQualifiedName = declaringClass.getQualifiedName() + "." + binding.getName(); - // match fqn with query pattern - if (fullyQualifiedName.matches(getCleanedQuery(query))) { - symbols.add(symbol); - } else { - logInfo("fqn " + fullyQualifiedName + " did not match with " + query); - } - } - } - } catch (Exception e) { - logInfo("error determining accuracy of match: " + e); - } - return true; - } - }); + CustomASTVisitor visitor = new CustomASTVisitor(query, match); + cu.accept(visitor); + if (visitor.symbolMatches()) { + symbols.add(symbol); + } } else { symbols.add(symbol); } diff --git a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/SymbolProvider.java b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/SymbolProvider.java index e3331f2..382574b 100644 --- a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/SymbolProvider.java +++ b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/SymbolProvider.java @@ -167,13 +167,4 @@ private static void setPosition(Position position, int[] coords) { position.setLine(coords[0]); position.setCharacter(coords[1]); } - - /* - * When comparing query pattern with an actual found java element's fqn - * we need to make sure that * that are not preceded with a . are replaced - * by .* so that java regex works as expected on them - */ - default String getCleanedQuery(String query) { - return query.replaceAll("(?