From aae9aae5043cf46b3f5f68b6523e65c260138672 Mon Sep 17 00:00:00 2001 From: Shawn Hurley Date: Wed, 22 Oct 2025 01:19:19 -0400 Subject: [PATCH 1/3] Fixing annotation searching by getting the FQDN from the compliation. * Falls back to trying to use the code actions to get the FQDN Signed-off-by: Shawn Hurley --- .../symbol/AnnotationSymbolProvider.java | 37 +++++++++++++++++-- 1 file changed, 33 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 10c6559..562560d 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 @@ -3,17 +3,16 @@ import static org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin.logInfo; import java.util.ArrayList; +import java.util.Arrays; 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.IJavaElement; +import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.compiler.IProblem; import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTParser; @@ -26,6 +25,9 @@ import org.eclipse.lsp4j.Location; import org.eclipse.lsp4j.SymbolInformation; +import io.konveyor.tackle.core.internal.query.AnnotationQuery; +import io.konveyor.tackle.core.internal.symbol.CustomASTVisitor.QueryLocation; + public class AnnotationSymbolProvider implements SymbolProvider, WithQuery, WithAnnotationQuery { private AnnotationQuery annotationQuery; @@ -54,6 +56,34 @@ public List get(SearchMatch match) throws CoreException { unit = cls.getWorkingCopy(new WorkingCopyOwnerImpl(), null); } } + IType t = unit.getType(annotationElement.getElementName()); + String fqdn = ""; + if (!t.isResolved()) { + var elements = unit.codeSelect(match.getOffset(), match.getLength()); + for (IJavaElement e: Arrays.asList(elements)) { + if (e instanceof IType) { + var newT = (IType) e; + if (newT.isResolved()) { + fqdn = newT.getFullyQualifiedName('.'); + logInfo("FQDN from code select: " + fqdn); + } + } + } + } else { + fqdn = t.getFullyQualifiedName('.'); + logInfo("resolved type: " + fqdn); + } + if (query.matches(fqdn)) { + symbols.add(symbol); + return symbols; + } + if (fqdn.matches(query)) { + symbols.add(symbol); + return symbols; + } + + logInfo("falling back to resolving via AST"); + 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); @@ -106,7 +136,6 @@ public List get(SearchMatch match) throws CoreException { symbols.add(symbol); } } - } return symbols; } catch (Exception e) { From 10f72c4eb6145def0238258c764937eee3a21ec9 Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Wed, 22 Oct 2025 11:24:48 +0200 Subject: [PATCH 2/3] Couple of fixes Signed-off-by: Juan Manuel Leflet Estrada --- .../symbol/AnnotationSymbolProvider.java | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 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 562560d..8f8542a 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 @@ -56,30 +56,32 @@ public List get(SearchMatch match) throws CoreException { unit = cls.getWorkingCopy(new WorkingCopyOwnerImpl(), null); } } - IType t = unit.getType(annotationElement.getElementName()); - String fqdn = ""; - if (!t.isResolved()) { - var elements = unit.codeSelect(match.getOffset(), match.getLength()); - for (IJavaElement e: Arrays.asList(elements)) { - if (e instanceof IType) { - var newT = (IType) e; - if (newT.isResolved()) { - fqdn = newT.getFullyQualifiedName('.'); - logInfo("FQDN from code select: " + fqdn); + if (unit != null) { + IType t = unit.getType(annotationElement.getElementName()); + String fqdn = ""; + if (!t.isResolved()) { + var elements = unit.codeSelect(match.getOffset(), match.getLength()); + for (IJavaElement e: Arrays.asList(elements)) { + if (e instanceof IType) { + var newT = (IType) e; + if (newT.isResolved()) { + fqdn = newT.getFullyQualifiedName('.'); + logInfo("FQDN from code select: " + fqdn); + } } } + } else { + fqdn = t.getFullyQualifiedName('.'); + logInfo("resolved type: " + fqdn); + } + if (query.matches(fqdn) || fqdn.matches(query)) { + if (unit.isWorkingCopy()) { + unit.discardWorkingCopy(); + unit.close(); + } + symbols.add(symbol); + return symbols; } - } else { - fqdn = t.getFullyQualifiedName('.'); - logInfo("resolved type: " + fqdn); - } - if (query.matches(fqdn)) { - symbols.add(symbol); - return symbols; - } - if (fqdn.matches(query)) { - symbols.add(symbol); - return symbols; } logInfo("falling back to resolving via AST"); From b4c6f222fcb8b5b850cdb20262dc47ba09e398c2 Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Wed, 22 Oct 2025 13:05:42 +0200 Subject: [PATCH 3/3] Respect annotated feature Signed-off-by: Juan Manuel Leflet Estrada --- .../symbol/AnnotationSymbolProvider.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 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 8f8542a..e2365bc 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 @@ -33,6 +33,13 @@ public class AnnotationSymbolProvider implements SymbolProvider, WithQuery, With private AnnotationQuery annotationQuery; private String query; + private static final List> ACCEPTED_CLASSES = new ArrayList<>(); + static { + ACCEPTED_CLASSES.add(ResolvedSourceMethod.class); + ACCEPTED_CLASSES.add(ResolvedSourceField.class); + ACCEPTED_CLASSES.add(ResolvedSourceType.class); + } + @Override public List get(SearchMatch match) throws CoreException { List symbols = new ArrayList<>(); @@ -79,7 +86,10 @@ public List get(SearchMatch match) throws CoreException { unit.discardWorkingCopy(); unit.close(); } - symbols.add(symbol); + + if (matchesAnnotationQuery(match, ACCEPTED_CLASSES)) { + symbols.add(symbol); + } return symbols; } } @@ -109,11 +119,7 @@ public List get(SearchMatch match) throws CoreException { cu.accept(visitor); if (visitor.symbolMatches()) { if (annotationQuery != null) { - List> classes = new ArrayList<>(); - classes.add(ResolvedSourceMethod.class); - classes.add(ResolvedSourceField.class); - classes.add(ResolvedSourceType.class); - if (matchesAnnotationQuery(match, classes)) { + if (matchesAnnotationQuery(match, ACCEPTED_CLASSES)) { symbols.add(symbol); } } else { @@ -127,11 +133,7 @@ public List get(SearchMatch match) throws CoreException { } } else { if (annotationQuery != null) { - List> classes = new ArrayList<>(); - classes.add(ResolvedSourceMethod.class); - classes.add(ResolvedSourceField.class); - classes.add(ResolvedSourceType.class); - if (matchesAnnotationQuery(match, classes)) { + if (matchesAnnotationQuery(match, ACCEPTED_CLASSES)) { symbols.add(symbol); } } else {