Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -54,6 +56,36 @@ public List<SymbolInformation> get(SearchMatch match) throws CoreException {
unit = cls.getWorkingCopy(new WorkingCopyOwnerImpl(), null);
}
}
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;
}
}

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);
Expand Down Expand Up @@ -106,7 +138,6 @@ public List<SymbolInformation> get(SearchMatch match) throws CoreException {
symbols.add(symbol);
}
}

}
return symbols;
} catch (Exception e) {
Expand Down
Loading