Skip to content

Commit

Permalink
Merge pull request apache#6380 from dbalek/dbalek/mn-symbols-fixes
Browse files Browse the repository at this point in the history
LSP: Micronaut endpoints finder fixes.
  • Loading branch information
dbalek authored Aug 28, 2023
2 parents 61f7242 + 11e5f1e commit 0191888
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public Void visitClass(ClassTree node, String path) {
if (metaAnnotated != null) {
Element annEl = metaAnnotated.first().getAnnotationType().asElement();
if ("io.micronaut.http.annotation.Controller".contentEquals(((TypeElement) annEl).getQualifiedName())) {
path = "";
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : metaAnnotated.first().getElementValues().entrySet()) {
if ("value".contentEquals(entry.getKey().getSimpleName())) {
path = (String) entry.getValue().getValue();
Expand All @@ -153,19 +154,34 @@ public Void visitClass(ClassTree node, String path) {

@Override
public Void visitMethod(MethodTree node, String path) {
TreePath treePath = this.getCurrentPath();
MthIterator it = new MthIterator(cc.getTrees().getElement(treePath), cc.getElements(), cc.getTypes());
while (it.hasNext()) {
for (AnnotationMirror ann : it.next().getAnnotationMirrors()) {
String method = getEndpointMethod((TypeElement) ann.getAnnotationType().asElement());
if (method != null) {
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : ann.getElementValues().entrySet()) {
if ("value".contentEquals(entry.getKey().getSimpleName()) || "uri".contentEquals(entry.getKey().getSimpleName())) {
String name = '@' + (path != null ? path : "") + entry.getValue().getValue() + " -- " + method;
if (path != null) {
TreePath treePath = this.getCurrentPath();
MthIterator it = new MthIterator(cc.getTrees().getElement(treePath), cc.getElements(), cc.getTypes());
while (it.hasNext()) {
for (AnnotationMirror ann : it.next().getAnnotationMirrors()) {
String method = getEndpointMethod((TypeElement) ann.getAnnotationType().asElement());
if (method != null) {
List<String> ids = new ArrayList<>();
Map<? extends ExecutableElement, ? extends AnnotationValue> values = ann.getElementValues();
if (values.isEmpty()) {
ids.add("/");
} else {
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : values.entrySet()) {
if ("value".contentEquals(entry.getKey().getSimpleName()) || "uri".contentEquals(entry.getKey().getSimpleName())) {
ids.add((String) entry.getValue().getValue());
} else if ("uris".contentEquals(entry.getKey().getSimpleName())) {
for (AnnotationValue av : (List<AnnotationValue>) entry.getValue().getValue()) {
ids.add((String) av.getValue());
}
}
}
}
for (Object id : ids) {
String name = '@' + path + id + " -- " + method;
int[] span = cc.getTreeUtilities().findNameSpan(node);
ret.add(new SymbolLocation(name, (int) sp.getStartPosition(treePath.getCompilationUnit(), node), (int) sp.getEndPosition(treePath.getCompilationUnit(), node), span[0], span[1]));
return null;
}
return null;
}
}
}
Expand Down Expand Up @@ -193,9 +209,9 @@ private void store(FileObject indexFolder, URL url, String resourceName, List<Sy
pw.print("symbol: ");
pw.print(symbol.name);
pw.print(':'); //NOI18N
pw.print(symbol.start);
pw.print(symbol.selectionStart);
pw.print('-'); //NOI18N
pw.println(symbol.end);
pw.println(symbol.selectionEnd);
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ public void notifyProgress(ProgressParams params) {

@Override
public void telemetryEvent(Object arg0) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,6 @@ private static final class MockLanguageClient extends TestCodeLanguageClient {
this.messages = messages;
}

@Override
public void telemetryEvent(Object object) {
fail();
}

@Override
public void publishDiagnostics(PublishDiagnosticsParams diagnostics) {
fail();
Expand Down

0 comments on commit 0191888

Please sign in to comment.