From 4e5dfd379da2b9d7d4a5b36cd21d1f6504883dd0 Mon Sep 17 00:00:00 2001 From: Anton Sviridov Date: Tue, 6 Aug 2024 12:25:37 +0100 Subject: [PATCH] Handle parenthesized trees (#733) --- .../semanticdb_javac/SemanticdbTrees.java | 4 ++ .../java/minimized/AnnotationParameters.java | 27 ++++--- .../java/minimized/AnnotationParameters.java | 72 +++++++++++-------- 3 files changed, 64 insertions(+), 39 deletions(-) diff --git a/semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbTrees.java b/semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbTrees.java index 90e5889d..a95a74fb 100644 --- a/semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbTrees.java +++ b/semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbTrees.java @@ -20,6 +20,7 @@ import com.sun.source.tree.LiteralTree; import com.sun.source.tree.NewArrayTree; import com.sun.source.tree.AnnotationTree; +import com.sun.source.tree.ParenthesizedTree; import java.util.HashMap; import java.util.ArrayList; @@ -160,6 +161,9 @@ private Semanticdb.Tree annotationParameter(ExpressionTree expr) { unaryOpTree( semanticdbUnaryOperator(unaryExpr.getKind()), annotationParameter(unaryExpr.getExpression()))); + } else if (expr instanceof ParenthesizedTree) { + ParenthesizedTree parenExpr = (ParenthesizedTree) expr; + return annotationParameter(parenExpr.getExpression()); } throw new IllegalArgumentException( semanticdbUri diff --git a/tests/minimized/src/main/java/minimized/AnnotationParameters.java b/tests/minimized/src/main/java/minimized/AnnotationParameters.java index d2049d3f..af376dff 100644 --- a/tests/minimized/src/main/java/minimized/AnnotationParameters.java +++ b/tests/minimized/src/main/java/minimized/AnnotationParameters.java @@ -1,23 +1,28 @@ package minimized; - @interface Bar { - double value(); + double value(); } @interface BarB { - boolean value(); + boolean value(); +} + +@interface Nullable { + String value() default ""; } interface Foo { - @Bar(-1d) - double test(); + @Bar(-1d) + double test(); - @Bar(~5) - @SuppressWarnings(value = "unchecked") - double test2(); + @Bar(~5) + @SuppressWarnings(value = "unchecked") + double test2(); - @BarB(!true) - double test3(); -} + @BarB(!true) + double test3(); + @Nullable(("what")) + Foo test4(); +} diff --git a/tests/snapshots/src/main/generated/tests/minimized/src/main/java/minimized/AnnotationParameters.java b/tests/snapshots/src/main/generated/tests/minimized/src/main/java/minimized/AnnotationParameters.java index fbb0fbf3..7704629c 100644 --- a/tests/snapshots/src/main/generated/tests/minimized/src/main/java/minimized/AnnotationParameters.java +++ b/tests/snapshots/src/main/generated/tests/minimized/src/main/java/minimized/AnnotationParameters.java @@ -1,13 +1,12 @@ package minimized; - @interface Bar { // ^^^ definition semanticdb maven . . minimized/Bar# // display_name Bar // signature_documentation java @interface Bar // kind Interface // relationship is_implementation semanticdb maven jdk 11 java/lang/annotation/Annotation# - double value(); +→double value(); } @interface BarB { @@ -16,7 +15,16 @@ // signature_documentation java @interface BarB // kind Interface // relationship is_implementation semanticdb maven jdk 11 java/lang/annotation/Annotation# - boolean value(); +→boolean value(); +} + +@interface Nullable { +// ^^^^^^^^ definition semanticdb maven . . minimized/Nullable# +// display_name Nullable +// signature_documentation java @interface Nullable +// kind Interface +// relationship is_implementation semanticdb maven jdk 11 java/lang/annotation/Annotation# +→String value() default ""; } interface Foo { @@ -24,31 +32,39 @@ interface Foo { // display_name Foo // signature_documentation java interface Foo // kind Interface - @Bar(-1d) -// ^^^ reference semanticdb maven . . minimized/Bar# - double test(); -// ^^^^ definition semanticdb maven . . minimized/Foo#test(). -// display_name test -// signature_documentation java @Bar(-1.0)\npublic abstract double test() -// kind AbstractMethod +→@Bar(-1d) +//^^^ reference semanticdb maven . . minimized/Bar# +→double test(); +// ^^^^ definition semanticdb maven . . minimized/Foo#test(). +// display_name test +// signature_documentation java @Bar(-1.0)\npublic abstract double test() +// kind AbstractMethod - @Bar(~5) -// ^^^ reference semanticdb maven . . minimized/Bar# - @SuppressWarnings(value = "unchecked") -// ^^^^^^^^^^^^^^^^ reference semanticdb maven jdk 11 java/lang/SuppressWarnings# -// ^^^^^ reference semanticdb maven jdk 11 java/lang/SuppressWarnings#value(). - double test2(); -// ^^^^^ definition semanticdb maven . . minimized/Foo#test2(). -// display_name test2 -// signature_documentation java @Bar(~5)\n@SuppressWarnings("unchecked")\npublic abstract double test2() -// kind AbstractMethod +→@Bar(~5) +//^^^ reference semanticdb maven . . minimized/Bar# +→@SuppressWarnings(value = "unchecked") +//^^^^^^^^^^^^^^^^ reference semanticdb maven jdk 11 java/lang/SuppressWarnings# +// ^^^^^ reference semanticdb maven jdk 11 java/lang/SuppressWarnings#value(). +→double test2(); +// ^^^^^ definition semanticdb maven . . minimized/Foo#test2(). +// display_name test2 +// signature_documentation java @Bar(~5)\n@SuppressWarnings("unchecked")\npublic abstract double test2() +// kind AbstractMethod - @BarB(!true) -// ^^^^ reference semanticdb maven . . minimized/BarB# - double test3(); -// ^^^^^ definition semanticdb maven . . minimized/Foo#test3(). -// display_name test3 -// signature_documentation java @BarB(!true)\npublic abstract double test3() -// kind AbstractMethod -} +→@BarB(!true) +//^^^^ reference semanticdb maven . . minimized/BarB# +→double test3(); +// ^^^^^ definition semanticdb maven . . minimized/Foo#test3(). +// display_name test3 +// signature_documentation java @BarB(!true)\npublic abstract double test3() +// kind AbstractMethod +→@Nullable(("what")) +//^^^^^^^^ reference semanticdb maven . . minimized/Nullable# +→Foo test4(); +//^^ reference semanticdb maven . . minimized/Foo# +// ^^^^^ definition semanticdb maven . . minimized/Foo#test4(). +// display_name test4 +// signature_documentation java @Nullable("what")\npublic abstract Foo test4() +// kind AbstractMethod +}