From 6102a1e723eddace3727db044cf5032244146f51 Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Wed, 1 Oct 2025 11:59:36 +0200 Subject: [PATCH 01/13] tmp Signed-off-by: Juan Manuel Leflet Estrada --- .../symbol/AnnotationSymbolProvider.java | 75 ++++++++++++++++++- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java index 4101aa6..13bce03 100644 --- a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java +++ b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java @@ -6,34 +6,84 @@ import java.util.List; import io.konveyor.tackle.core.internal.query.AnnotationQuery; +import io.konveyor.tackle.core.internal.symbol.CustomASTVisitor.QueryLocation; + import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.IAnnotatable; import org.eclipse.jdt.core.IAnnotation; +import org.eclipse.jdt.core.IClassFile; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IMethod; +import org.eclipse.jdt.core.compiler.IProblem; +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ASTParser; +import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.search.SearchMatch; import org.eclipse.jdt.internal.core.ResolvedSourceField; import org.eclipse.jdt.internal.core.ResolvedSourceMethod; import org.eclipse.jdt.internal.core.ResolvedSourceType; import org.eclipse.jdt.internal.core.SourceRefElement; +import org.eclipse.lsp4j.Location; import org.eclipse.lsp4j.SymbolInformation; -public class AnnotationSymbolProvider implements SymbolProvider, WithAnnotationQuery { +public class AnnotationSymbolProvider implements SymbolProvider, WithQuery, WithAnnotationQuery { private AnnotationQuery annotationQuery; + private String query; @Override public List get(SearchMatch match) throws CoreException { List symbols = new ArrayList<>(); try { - IAnnotatable mod = (IAnnotatable) match.getElement(); + IAnnotatable annotatable = (IAnnotatable) match.getElement(); IJavaElement element = (IJavaElement) match.getElement(); - for (IAnnotation annotation : mod.getAnnotations()) { + for (IAnnotation annotation : annotatable.getAnnotations()) { SymbolInformation symbol = new SymbolInformation(); symbol.setName(annotation.getElementName()); symbol.setKind(convertSymbolKind(element)); symbol.setContainerName(annotation.getParent().getElementName()); - symbol.setLocation(getLocation(element, match)); + Location location = getLocation(element, match); + symbol.setLocation(location); + if (this.query.contains(".")) { + ICompilationUnit unit = null; + IClassFile cls = getClassFileForAnnotation(element); + if (cls != null) { + unit = cls.getWorkingCopy(new WorkingCopyOwnerImpl(), null); + } + if (this.queryQualificationMatches(this.query, unit, location)) { + ASTParser astParser = ASTParser.newParser(AST.getJLSLatest()); + astParser.setSource(unit); + astParser.setResolveBindings(true); + CompilationUnit cu = (CompilationUnit) astParser.createAST(null); + CustomASTVisitor visitor = new CustomASTVisitor(query, match, QueryLocation.CONSTRUCTOR_CALL); + // Under tests, resolveConstructorBinding will return null if there are problems + IProblem[] problems = cu.getProblems(); + if (problems != null && problems.length > 0) { + logInfo("KONVEYOR_LOG: " + "Found " + problems.length + " problems while compiling"); + int count = 0; + for (IProblem problem : problems) { + logInfo("KONVEYOR_LOG: Problem - ID: " + problem.getID() + " Message: " + problem.getMessage()); + count++; + if (count >= SymbolProvider.MAX_PROBLEMS_TO_LOG) { + logInfo("KONVEYOR_LOG: Only showing first " + SymbolProvider.MAX_PROBLEMS_TO_LOG + " problems, " + (problems.length - SymbolProvider.MAX_PROBLEMS_TO_LOG) + " more not displayed"); + break; + } + } + } + cu.accept(visitor); + if (visitor.symbolMatches()) { + symbols.add(symbol); + } + } + unit.discardWorkingCopy(); + unit.close(); + } else { + symbols.add(symbol); + } + // TODO: put this above if works if (annotationQuery != null) { List> classes = new ArrayList<>(); classes.add(ResolvedSourceMethod.class); @@ -53,6 +103,18 @@ public List get(SearchMatch match) throws CoreException { } } + private IClassFile getClassFileForAnnotation(IJavaElement element) { + IClassFile clazz = null; + if (element instanceof IClassFile) { + clazz = (IClassFile) element; + } else if (element instanceof IMethod || element instanceof IField) { + IMethod method = (IMethod) element; + clazz = (IClassFile) method.getAncestor(IJavaElement.CLASS_FILE); + } + clazz = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE); + return clazz; + } + public AnnotationQuery getAnnotationQuery() { return annotationQuery; } @@ -60,4 +122,9 @@ public AnnotationQuery getAnnotationQuery() { public void setAnnotationQuery(AnnotationQuery annotationQuery) { this.annotationQuery = annotationQuery; } + + @Override + public void setQuery(String query) { + this.query = query; + } } From 6b645cf64474ed82786f553a2483f7edbde0160c Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Wed, 1 Oct 2025 14:44:26 +0200 Subject: [PATCH 02/13] Working: Signed-off-by: Juan Manuel Leflet Estrada --- .../symbol/AnnotationSymbolProvider.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java index 13bce03..a5108a8 100644 --- a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java +++ b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java @@ -13,9 +13,7 @@ import org.eclipse.jdt.core.IAnnotation; import org.eclipse.jdt.core.IClassFile; import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.compiler.IProblem; import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTParser; @@ -47,10 +45,14 @@ public List get(SearchMatch match) throws CoreException { Location location = getLocation(element, match); symbol.setLocation(location); if (this.query.contains(".")) { - ICompilationUnit unit = null; - IClassFile cls = getClassFileForAnnotation(element); - if (cls != null) { - unit = cls.getWorkingCopy(new WorkingCopyOwnerImpl(), null); + // First try to get compilation unit for source files + ICompilationUnit unit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT); + if (unit == null) { + // If not in source, try to get class file for compiled classes + IClassFile cls = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE); + if (cls != null) { + unit = cls.getWorkingCopy(new WorkingCopyOwnerImpl(), null); + } } if (this.queryQualificationMatches(this.query, unit, location)) { ASTParser astParser = ASTParser.newParser(AST.getJLSLatest()); @@ -104,15 +106,9 @@ public List get(SearchMatch match) throws CoreException { } private IClassFile getClassFileForAnnotation(IJavaElement element) { - IClassFile clazz = null; - if (element instanceof IClassFile) { - clazz = (IClassFile) element; - } else if (element instanceof IMethod || element instanceof IField) { - IMethod method = (IMethod) element; - clazz = (IClassFile) method.getAncestor(IJavaElement.CLASS_FILE); - } - clazz = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE); - return clazz; + // Find the containing class file for elements in compiled classes (JARs) + // This will return null for elements in source files + return } public AnnotationQuery getAnnotationQuery() { From d0da87c91f07ff1314227acd133a2a75dbe0f2c9 Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Wed, 1 Oct 2025 15:37:08 +0200 Subject: [PATCH 03/13] Move in check for annotated classes Signed-off-by: Juan Manuel Leflet Estrada --- .../symbol/AnnotationSymbolProvider.java | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java index a5108a8..9ec549c 100644 --- a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java +++ b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java @@ -76,27 +76,35 @@ public List get(SearchMatch match) throws CoreException { } cu.accept(visitor); if (visitor.symbolMatches()) { - symbols.add(symbol); + if (annotationQuery != null) { + List> classes = new ArrayList<>(); + classes.add(ResolvedSourceMethod.class); + classes.add(ResolvedSourceField.class); + classes.add(ResolvedSourceType.class); + if (matchesAnnotationQuery(match, classes)) { + symbols.add(symbol); + } + } else { + symbols.add(symbol); + } } } unit.discardWorkingCopy(); unit.close(); } else { - symbols.add(symbol); - } - - // TODO: put this above if works - if (annotationQuery != null) { - List> classes = new ArrayList<>(); - classes.add(ResolvedSourceMethod.class); - classes.add(ResolvedSourceField.class); - classes.add(ResolvedSourceType.class); - if (matchesAnnotationQuery(match, classes)) { + if (annotationQuery != null) { + List> classes = new ArrayList<>(); + classes.add(ResolvedSourceMethod.class); + classes.add(ResolvedSourceField.class); + classes.add(ResolvedSourceType.class); + if (matchesAnnotationQuery(match, classes)) { + symbols.add(symbol); + } + } else { symbols.add(symbol); } - } else { - symbols.add(symbol); } + } return symbols; } catch (Exception e) { @@ -105,12 +113,6 @@ public List get(SearchMatch match) throws CoreException { } } - private IClassFile getClassFileForAnnotation(IJavaElement element) { - // Find the containing class file for elements in compiled classes (JARs) - // This will return null for elements in source files - return - } - public AnnotationQuery getAnnotationQuery() { return annotationQuery; } From cafa84869c2b9e6fad9894586437219819947867 Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Thu, 2 Oct 2025 14:37:37 +0200 Subject: [PATCH 04/13] tmp Signed-off-by: Juan Manuel Leflet Estrada --- .../internal/symbol/CustomASTVisitor.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) 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 index 2d06786..368f1bc 100644 --- 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 @@ -6,9 +6,11 @@ import org.eclipse.jdt.core.dom.ASTVisitor; import org.eclipse.jdt.core.dom.ClassInstanceCreation; import org.eclipse.jdt.core.dom.ConstructorInvocation; +import org.eclipse.jdt.core.dom.IAnnotationBinding; 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.dom.NormalAnnotation; import org.eclipse.jdt.core.search.SearchMatch; /* @@ -62,6 +64,45 @@ private boolean shouldVisit(ASTNode node) { (node.getStartPosition() + node.getLength()); } + @Override + public boolean visit(NormalAnnotation node) { + if (!this.shouldVisit(node)) { + return true; + } + try { + IAnnotationBinding binding = node.resolveAnnotationBinding(); + if (binding != null) { + // get fqn + ITypeBinding declaringClass = binding.getAnnotationType(); + if (declaringClass != null) { + // Handle Erasure results + if (declaringClass.getErasure() != null) { + declaringClass = declaringClass.getErasure(); + } + String fullyQualifiedName = declaringClass.getQualifiedName() + "." + binding.getName(); + // match fqn with query pattern + if (fullyQualifiedName.matches(this.query)) { + this.symbolMatches = true; + return false; + } else { + logInfo("method fqn " + fullyQualifiedName + " did not match with " + query); + return true; + } + } + } + logInfo("failed to get accurate info for MethodInvocation, falling back"); + // sometimes binding or declaring class cannot be found, usually due to errors + // in source code. in that case, we will fallback and accept the match + this.symbolMatches = true; + return false; + } catch (Exception 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; + } + } + /* * This is to get information from a MethodInvocation, used for METHOD_CALL * we discard a match only when we can tell for sure. otherwise we accept From 1ab427acbdcf1504a529287a63995539f1727b0a Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Thu, 2 Oct 2025 18:47:57 +0200 Subject: [PATCH 05/13] Fix stuff Signed-off-by: Juan Manuel Leflet Estrada --- .../symbol/AnnotationSymbolProvider.java | 12 +++--- .../internal/symbol/CustomASTVisitor.java | 43 ++++++++++++++++++- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java index 9ec549c..1eb7c86 100644 --- a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java +++ b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java @@ -36,20 +36,20 @@ public List get(SearchMatch match) throws CoreException { List symbols = new ArrayList<>(); try { IAnnotatable annotatable = (IAnnotatable) match.getElement(); - IJavaElement element = (IJavaElement) match.getElement(); for (IAnnotation annotation : annotatable.getAnnotations()) { + IJavaElement annotationElement = annotation.getPrimaryElement(); SymbolInformation symbol = new SymbolInformation(); symbol.setName(annotation.getElementName()); - symbol.setKind(convertSymbolKind(element)); + symbol.setKind(convertSymbolKind(annotationElement)); symbol.setContainerName(annotation.getParent().getElementName()); - Location location = getLocation(element, match); + Location location = getLocation(annotationElement, match); symbol.setLocation(location); if (this.query.contains(".")) { // First try to get compilation unit for source files - ICompilationUnit unit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT); + ICompilationUnit unit = (ICompilationUnit) annotationElement.getAncestor(IJavaElement.COMPILATION_UNIT); if (unit == null) { // If not in source, try to get class file for compiled classes - IClassFile cls = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE); + IClassFile cls = (IClassFile) annotationElement.getAncestor(IJavaElement.CLASS_FILE); if (cls != null) { unit = cls.getWorkingCopy(new WorkingCopyOwnerImpl(), null); } @@ -59,7 +59,7 @@ public List get(SearchMatch match) throws CoreException { astParser.setSource(unit); astParser.setResolveBindings(true); CompilationUnit cu = (CompilationUnit) astParser.createAST(null); - CustomASTVisitor visitor = new CustomASTVisitor(query, match, QueryLocation.CONSTRUCTOR_CALL); + CustomASTVisitor visitor = new CustomASTVisitor(query, match, QueryLocation.ANNOTATION); // Under tests, resolveConstructorBinding will return null if there are problems IProblem[] problems = cu.getProblems(); if (problems != null && problems.length > 0) { 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 index 368f1bc..98b89c9 100644 --- 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 @@ -9,6 +9,7 @@ import org.eclipse.jdt.core.dom.IAnnotationBinding; import org.eclipse.jdt.core.dom.IMethodBinding; import org.eclipse.jdt.core.dom.ITypeBinding; +import org.eclipse.jdt.core.dom.MarkerAnnotation; import org.eclipse.jdt.core.dom.MethodInvocation; import org.eclipse.jdt.core.dom.NormalAnnotation; import org.eclipse.jdt.core.search.SearchMatch; @@ -34,6 +35,7 @@ public class CustomASTVisitor extends ASTVisitor { public enum QueryLocation { METHOD_CALL, CONSTRUCTOR_CALL, + ANNOTATION, } public CustomASTVisitor(String query, SearchMatch match, QueryLocation location) { @@ -64,9 +66,48 @@ private boolean shouldVisit(ASTNode node) { (node.getStartPosition() + node.getLength()); } + @Override + public boolean visit(MarkerAnnotation node) { + if (this.location != QueryLocation.ANNOTATION || !this.shouldVisit(node)) { + return true; + } + try { + IAnnotationBinding binding = node.resolveAnnotationBinding(); + if (binding != null) { + // get fqn + ITypeBinding declaringClass = binding.getAnnotationType(); + if (declaringClass != null) { + // Handle Erasure results + if (declaringClass.getErasure() != null) { + declaringClass = declaringClass.getErasure(); + } + String fullyQualifiedName = declaringClass.getQualifiedName() + "." + binding.getName(); + // match fqn with query pattern + if (fullyQualifiedName.matches(this.query)) { + this.symbolMatches = true; + return false; + } else { + logInfo("method fqn " + fullyQualifiedName + " did not match with " + query); + return true; + } + } + } + logInfo("failed to get accurate info for MethodInvocation, falling back"); + // sometimes binding or declaring class cannot be found, usually due to errors + // in source code. in that case, we will fallback and accept the match + this.symbolMatches = true; + return false; + } catch (Exception 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; + } + } + @Override public boolean visit(NormalAnnotation node) { - if (!this.shouldVisit(node)) { + if (this.location != QueryLocation.ANNOTATION || !this.shouldVisit(node)) { return true; } try { From a05bf5f9a44ad84abd5ec7108d2266189c5e2407 Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Fri, 3 Oct 2025 10:17:01 +0200 Subject: [PATCH 06/13] Final fix Signed-off-by: Juan Manuel Leflet Estrada --- .../internal/symbol/CustomASTVisitor.java | 43 +++---------------- 1 file changed, 7 insertions(+), 36 deletions(-) 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 index 98b89c9..f732668 100644 --- 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 @@ -9,6 +9,7 @@ import org.eclipse.jdt.core.dom.IAnnotationBinding; import org.eclipse.jdt.core.dom.IMethodBinding; import org.eclipse.jdt.core.dom.ITypeBinding; +import org.eclipse.jdt.core.dom.Annotation; import org.eclipse.jdt.core.dom.MarkerAnnotation; import org.eclipse.jdt.core.dom.MethodInvocation; import org.eclipse.jdt.core.dom.NormalAnnotation; @@ -68,45 +69,15 @@ private boolean shouldVisit(ASTNode node) { @Override public boolean visit(MarkerAnnotation node) { - if (this.location != QueryLocation.ANNOTATION || !this.shouldVisit(node)) { - return true; - } - try { - IAnnotationBinding binding = node.resolveAnnotationBinding(); - if (binding != null) { - // get fqn - ITypeBinding declaringClass = binding.getAnnotationType(); - if (declaringClass != null) { - // Handle Erasure results - if (declaringClass.getErasure() != null) { - declaringClass = declaringClass.getErasure(); - } - String fullyQualifiedName = declaringClass.getQualifiedName() + "." + binding.getName(); - // match fqn with query pattern - if (fullyQualifiedName.matches(this.query)) { - this.symbolMatches = true; - return false; - } else { - logInfo("method fqn " + fullyQualifiedName + " did not match with " + query); - return true; - } - } - } - logInfo("failed to get accurate info for MethodInvocation, falling back"); - // sometimes binding or declaring class cannot be found, usually due to errors - // in source code. in that case, we will fallback and accept the match - this.symbolMatches = true; - return false; - } catch (Exception 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; - } + return visit((Annotation) node); } @Override public boolean visit(NormalAnnotation node) { + return visit((Annotation) node); + } + + private boolean visit(Annotation node) { if (this.location != QueryLocation.ANNOTATION || !this.shouldVisit(node)) { return true; } @@ -120,7 +91,7 @@ public boolean visit(NormalAnnotation node) { if (declaringClass.getErasure() != null) { declaringClass = declaringClass.getErasure(); } - String fullyQualifiedName = declaringClass.getQualifiedName() + "." + binding.getName(); + String fullyQualifiedName = declaringClass.getQualifiedName(); // match fqn with query pattern if (fullyQualifiedName.matches(this.query)) { this.symbolMatches = true; From 4e1f545ce576c6766846eae53e73f3c2cb2cab3c Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Fri, 3 Oct 2025 13:11:28 +0200 Subject: [PATCH 07/13] Fix shouldVisit Signed-off-by: Juan Manuel Leflet Estrada --- .../core/internal/symbol/CustomASTVisitor.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 index f732668..f53459e 100644 --- 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 @@ -13,6 +13,7 @@ import org.eclipse.jdt.core.dom.MarkerAnnotation; import org.eclipse.jdt.core.dom.MethodInvocation; import org.eclipse.jdt.core.dom.NormalAnnotation; +import org.eclipse.jdt.core.dom.SingleMemberAnnotation; import org.eclipse.jdt.core.search.SearchMatch; /* @@ -77,8 +78,18 @@ public boolean visit(NormalAnnotation node) { return visit((Annotation) node); } + @Override + public boolean visit(SingleMemberAnnotation node) { + return visit((Annotation) node); + } + private boolean visit(Annotation node) { - if (this.location != QueryLocation.ANNOTATION || !this.shouldVisit(node)) { + // There is a problem with trying to run shouldVisit() here because + // matches on annotations aren't directly on the annotation node, + // but on the annotated one (class, method, field, etc). So we can't + // use shouldVisit() to filter out nodes we don't want to visit. + // TODO: think of a better way to handle this + if (this.location != QueryLocation.ANNOTATION) { return true; } try { From d15171d820d1802033ded87c323ac6b8e1b8af68 Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Fri, 3 Oct 2025 16:23:59 +0200 Subject: [PATCH 08/13] Fix condition Signed-off-by: Juan Manuel Leflet Estrada --- .../tackle/core/internal/SampleDelegateCommandHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SampleDelegateCommandHandler.java b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SampleDelegateCommandHandler.java index 37e9036..f22eab2 100644 --- a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SampleDelegateCommandHandler.java +++ b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SampleDelegateCommandHandler.java @@ -162,7 +162,7 @@ private static SearchPattern mapLocationToSearchPatternLocation(int location, St */ private static SearchPattern getPatternSingleQuery(int location, String query) throws Exception { var pattern = SearchPattern.R_PATTERN_MATCH; - if ((!query.contains("?") || !query.contains("*")) && (location != 11)) { + if ((!query.contains("?") && !query.contains("*")) && (location != 11)) { logInfo("Using full match"); pattern = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE; } From 9fca62b1b5e0f2bcaa69414a61a5769b1397f12b Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Mon, 6 Oct 2025 12:12:01 +0200 Subject: [PATCH 09/13] Undo Signed-off-by: Juan Manuel Leflet Estrada --- java-analyzer-bundle.tp/java-analyzer-bundle.target | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/java-analyzer-bundle.tp/java-analyzer-bundle.target b/java-analyzer-bundle.tp/java-analyzer-bundle.target index 80032b4..219276e 100644 --- a/java-analyzer-bundle.tp/java-analyzer-bundle.target +++ b/java-analyzer-bundle.tp/java-analyzer-bundle.target @@ -2,12 +2,12 @@ - - + @@ -64,7 +64,7 @@ - + From 4ec47b6d03630f6afe93a3a510f5d61717320771 Mon Sep 17 00:00:00 2001 From: Pranav Gaikwad Date: Tue, 14 Oct 2025 10:20:39 -0400 Subject: [PATCH 10/13] make sure that qualification matches considers fqn usage without import and queries like (A|B|C) Signed-off-by: Pranav Gaikwad --- .../internal/symbol/AnnotationSymbolProvider.java | 2 +- .../symbol/ConstructorCallSymbolProvider.java | 2 +- .../internal/symbol/MethodCallSymbolProvider.java | 2 +- .../tackle/core/internal/symbol/SymbolProvider.java | 12 ++++++++++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java index 1eb7c86..2fee613 100644 --- a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java +++ b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java @@ -54,7 +54,7 @@ public List get(SearchMatch match) throws CoreException { unit = cls.getWorkingCopy(new WorkingCopyOwnerImpl(), null); } } - if (this.queryQualificationMatches(this.query, unit, location)) { + if (this.queryQualificationMatches(this.query, annotationElement, unit, location)) { ASTParser astParser = ASTParser.newParser(AST.getJLSLatest()); astParser.setSource(unit); astParser.setResolveBindings(true); 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 8b19b3d..4f4561c 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 @@ -53,7 +53,7 @@ public List get(SearchMatch match) throws CoreException { unit = cls.getWorkingCopy(new WorkingCopyOwnerImpl(), null); } } - if (this.queryQualificationMatches(this.query, unit, location)) { + if (this.queryQualificationMatches(this.query, mod, unit, location)) { ASTParser astParser = ASTParser.newParser(AST.getJLSLatest()); astParser.setSource(unit); astParser.setResolveBindings(true); diff --git a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/MethodCallSymbolProvider.java b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/MethodCallSymbolProvider.java index 257554d..8826eda 100644 --- a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/MethodCallSymbolProvider.java +++ b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/MethodCallSymbolProvider.java @@ -53,7 +53,7 @@ public List get(SearchMatch match) { unit = cls.getWorkingCopy(new WorkingCopyOwnerImpl(), null); } } - if (this.queryQualificationMatches(this.query, unit, location)) { + if (this.queryQualificationMatches(this.query, e, unit, location)) { ASTParser astParser = ASTParser.newParser(AST.getJLSLatest()); astParser.setSource(unit); astParser.setResolveBindings(true); 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 79b0115..449caf9 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 @@ -188,7 +188,7 @@ private static void setPosition(Position position, int[] coords) { * 3. the compilation unit has a package declaration as `konveyor.io.Util` * we do this so that we can rule out a lot of matches before going the AST route */ - default boolean queryQualificationMatches(String query, ICompilationUnit unit, Location location) { + default boolean queryQualificationMatches(String query, IJavaElement matchedElement,ICompilationUnit unit, Location location) { // Make sure that the ICompilationUnit is conistant try { unit.makeConsistent(null); @@ -198,7 +198,7 @@ default boolean queryQualificationMatches(String query, ICompilationUnit unit, L // should consider parameter here // e.g. java.nio.file.Paths.get(String)/java.nio.file.Paths.get(*) -> java.nio.file.Paths.get // Remove any parentheses and their contents - query = query.replaceAll("\\(.*\\)", ""); + query = query.replaceAll("\\([^|]*\\)", ""); query = query.replaceAll("(? 0) { From 3c2c2d1aaf07d326e24c1be20ff903b97585a0a0 Mon Sep 17 00:00:00 2001 From: Pranav Gaikwad Date: Tue, 14 Oct 2025 13:33:54 -0400 Subject: [PATCH 11/13] fix a minor bug in processing regex Signed-off-by: Pranav Gaikwad --- .../tackle/core/internal/SampleDelegateCommandHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SampleDelegateCommandHandler.java b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SampleDelegateCommandHandler.java index f22eab2..7681de9 100644 --- a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SampleDelegateCommandHandler.java +++ b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/SampleDelegateCommandHandler.java @@ -376,7 +376,8 @@ private static List search(String projectName, ArrayList Date: Mon, 20 Oct 2025 20:37:44 +0200 Subject: [PATCH 12/13] Fix regex Signed-off-by: Juan Manuel Leflet Estrada --- .../tackle/core/internal/symbol/AnnotationSymbolProvider.java | 2 +- .../io/konveyor/tackle/core/internal/symbol/SymbolProvider.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java index 2fee613..8b54199 100644 --- a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java +++ b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java @@ -54,7 +54,7 @@ public List get(SearchMatch match) throws CoreException { unit = cls.getWorkingCopy(new WorkingCopyOwnerImpl(), null); } } - if (this.queryQualificationMatches(this.query, annotationElement, unit, location)) { + if (this.queryQualificationMatches(this.query.replaceAll("\\(([A-Za-z_][A-Za-z0-9_]*(\\|[A-Za-z_][A-Za-z0-9_]*)*)\\)", ".*"), annotationElement, unit, location)) { ASTParser astParser = ASTParser.newParser(AST.getJLSLatest()); astParser.setSource(unit); astParser.setResolveBindings(true); 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 449caf9..b86a5d5 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 @@ -198,7 +198,7 @@ default boolean queryQualificationMatches(String query, IJavaElement matchedElem // should consider parameter here // e.g. java.nio.file.Paths.get(String)/java.nio.file.Paths.get(*) -> java.nio.file.Paths.get // Remove any parentheses and their contents - query = query.replaceAll("\\([^|]*\\)", ""); + query = query.replaceAll("\\(.*\\)", ""); query = query.replaceAll("(? Date: Tue, 21 Oct 2025 21:23:37 +0200 Subject: [PATCH 13/13] Fix potential npe Signed-off-by: Juan Manuel Leflet Estrada --- .../core/internal/symbol/AnnotationSymbolProvider.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java index 8b54199..10c6559 100644 --- a/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java +++ b/java-analyzer-bundle.core/src/main/java/io/konveyor/tackle/core/internal/symbol/AnnotationSymbolProvider.java @@ -89,8 +89,10 @@ public List get(SearchMatch match) throws CoreException { } } } - unit.discardWorkingCopy(); - unit.close(); + if (unit != null && unit.isWorkingCopy()) { + unit.discardWorkingCopy(); + unit.close(); + } } else { if (annotationQuery != null) { List> classes = new ArrayList<>();