8214902: Pretty-printing marker annotations add unnecessary parenthesis
authorcushon
Wed, 05 Dec 2018 11:31:20 -0800
changeset 52864 e78890a4c25f
parent 52863 e07bd8ecab45
child 52865 fa3534ce82a1
8214902: Pretty-printing marker annotations add unnecessary parenthesis Reviewed-by: jjg
src/jdk.compiler/share/classes/com/sun/tools/javac/tree/Pretty.java
test/langtools/jdk/javadoc/doclet/testDeprecatedDocs/pkg/DeprecatedClassByAnnotation.java
test/langtools/jdk/javadoc/doclet/testHtmlVersion/pkg2/DeprecatedClassByAnnotation.java
test/langtools/jdk/javadoc/doclet/testSearch/pkg2/DeprecatedClassByAnnotation.java
test/langtools/tools/javac/T8020997/CannotCompileRepeatedAnnoTest.java
test/langtools/tools/javac/annotations/6881115/T6881115.java
test/langtools/tools/javac/annotations/6881115/T6881115.out
test/langtools/tools/javac/annotations/neg/Cycle3.java
test/langtools/tools/javac/annotations/pos/Primitives.java
test/langtools/tools/javac/annotations/repeatingAnnotations/BaseAnnoAsContainerAnno.java
test/langtools/tools/javac/annotations/repeatingAnnotations/MissingContainer.java
test/langtools/tools/javac/annotations/typeAnnotations/api/AnnotatedArrayOrder.java
test/langtools/tools/javac/annotations/typeAnnotations/api/ArrayCreationTree.java
test/langtools/tools/javac/annotations/typeAnnotations/api/ArrayPositionConsistency.java
test/langtools/tools/javac/annotations/typeAnnotations/failures/AnnotatedMethodSelectorTest.java
test/langtools/tools/javac/diags/examples/AnnoNotApplicable.java
test/langtools/tools/javac/tree/TypeAnnotationsPretty.java
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/Pretty.java	Wed Dec 05 17:50:14 2018 -0800
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/Pretty.java	Wed Dec 05 11:31:20 2018 -0800
@@ -1525,9 +1525,11 @@
         try {
             print("@");
             printExpr(tree.annotationType);
-            print("(");
-            printExprs(tree.args);
-            print(")");
+            if (!tree.args.isEmpty()) {
+                print("(");
+                printExprs(tree.args);
+                print(")");
+            }
         } catch (IOException e) {
             throw new UncheckedIOException(e);
         }
--- a/test/langtools/jdk/javadoc/doclet/testDeprecatedDocs/pkg/DeprecatedClassByAnnotation.java	Wed Dec 05 17:50:14 2018 -0800
+++ b/test/langtools/jdk/javadoc/doclet/testDeprecatedDocs/pkg/DeprecatedClassByAnnotation.java	Wed Dec 05 11:31:20 2018 -0800
@@ -23,7 +23,7 @@
 
 package pkg;
 
-@Deprecated()
+@Deprecated
 public class DeprecatedClassByAnnotation {
 
     @Deprecated(forRemoval=true)
@@ -32,6 +32,6 @@
     @Deprecated(forRemoval=true)
     public DeprecatedClassByAnnotation() {}
 
-    @Deprecated()
+    @Deprecated
     public void method() {}
 }
--- a/test/langtools/jdk/javadoc/doclet/testHtmlVersion/pkg2/DeprecatedClassByAnnotation.java	Wed Dec 05 17:50:14 2018 -0800
+++ b/test/langtools/jdk/javadoc/doclet/testHtmlVersion/pkg2/DeprecatedClassByAnnotation.java	Wed Dec 05 11:31:20 2018 -0800
@@ -23,15 +23,15 @@
 
 package pkg2;
 
-@Deprecated()
+@Deprecated
 public class DeprecatedClassByAnnotation {
 
-    @Deprecated()
+    @Deprecated
     public int field;
 
-    @Deprecated()
+    @Deprecated
     public DeprecatedClassByAnnotation() {}
 
-    @Deprecated()
+    @Deprecated
     public void method() {}
 }
--- a/test/langtools/jdk/javadoc/doclet/testSearch/pkg2/DeprecatedClassByAnnotation.java	Wed Dec 05 17:50:14 2018 -0800
+++ b/test/langtools/jdk/javadoc/doclet/testSearch/pkg2/DeprecatedClassByAnnotation.java	Wed Dec 05 11:31:20 2018 -0800
@@ -23,15 +23,15 @@
 
 package pkg2;
 
-@Deprecated()
+@Deprecated
 public class DeprecatedClassByAnnotation {
 
-    @Deprecated()
+    @Deprecated
     public int field;
 
-    @Deprecated()
+    @Deprecated
     public DeprecatedClassByAnnotation() {}
 
-    @Deprecated()
+    @Deprecated
     public void method() {}
 }
--- a/test/langtools/tools/javac/T8020997/CannotCompileRepeatedAnnoTest.java	Wed Dec 05 17:50:14 2018 -0800
+++ b/test/langtools/tools/javac/T8020997/CannotCompileRepeatedAnnoTest.java	Wed Dec 05 11:31:20 2018 -0800
@@ -31,7 +31,7 @@
 import java.lang.annotation.*;
 
 @Anno(req = true)
-@Anno()
+@Anno
 public class CannotCompileRepeatedAnnoTest {
 }
 
--- a/test/langtools/tools/javac/annotations/6881115/T6881115.java	Wed Dec 05 17:50:14 2018 -0800
+++ b/test/langtools/tools/javac/annotations/6881115/T6881115.java	Wed Dec 05 11:31:20 2018 -0800
@@ -12,7 +12,7 @@
 @Target({ElementType.TYPE, ElementType.TYPE_PARAMETER, ElementType.ANNOTATION_TYPE})
 @interface A {
     B b() default @B(b2 = 1, b2 = 2);
-    B[] b_arr() default {@B(), @B(b2 = 1, b2 = 2)};
+    B[] b_arr() default {@B, @B(b2 = 1, b2 = 2)};
 }
 
 @interface B {
@@ -21,6 +21,6 @@
 }
 
 @A(b = @B(b2 = 1, b2 = 2),
-   b_arr = {@B(), @B(b2 = 1, b2 = 2)})
+   b_arr = {@B, @B(b2 = 1, b2 = 2)})
 class T6881115<@A(b = @B(b2 = 1, b2 = 2),
-                  b_arr = {@B(), @B(b2 = 1, b2 = 2)}) X> {}
+                  b_arr = {@B, @B(b2 = 1, b2 = 2)}) X> {}
--- a/test/langtools/tools/javac/annotations/6881115/T6881115.out	Wed Dec 05 17:50:14 2018 -0800
+++ b/test/langtools/tools/javac/annotations/6881115/T6881115.out	Wed Dec 05 11:31:20 2018 -0800
@@ -1,16 +1,16 @@
 T6881115.java:14:30: compiler.err.duplicate.annotation.member.value: b2, B
 T6881115.java:14:19: compiler.err.annotation.missing.default.value: B, b1
 T6881115.java:15:26: compiler.err.annotation.missing.default.value.1: B, b1,b2
-T6881115.java:15:43: compiler.err.duplicate.annotation.member.value: b2, B
-T6881115.java:15:32: compiler.err.annotation.missing.default.value: B, b1
+T6881115.java:15:41: compiler.err.duplicate.annotation.member.value: b2, B
+T6881115.java:15:30: compiler.err.annotation.missing.default.value: B, b1
 T6881115.java:23:19: compiler.err.duplicate.annotation.member.value: b2, B
 T6881115.java:23:8: compiler.err.annotation.missing.default.value: B, b1
 T6881115.java:24:13: compiler.err.annotation.missing.default.value.1: B, b1,b2
-T6881115.java:24:30: compiler.err.duplicate.annotation.member.value: b2, B
-T6881115.java:24:19: compiler.err.annotation.missing.default.value: B, b1
+T6881115.java:24:28: compiler.err.duplicate.annotation.member.value: b2, B
+T6881115.java:24:17: compiler.err.annotation.missing.default.value: B, b1
 T6881115.java:25:34: compiler.err.duplicate.annotation.member.value: b2, B
 T6881115.java:25:23: compiler.err.annotation.missing.default.value: B, b1
 T6881115.java:26:28: compiler.err.annotation.missing.default.value.1: B, b1,b2
-T6881115.java:26:45: compiler.err.duplicate.annotation.member.value: b2, B
-T6881115.java:26:34: compiler.err.annotation.missing.default.value: B, b1
+T6881115.java:26:43: compiler.err.duplicate.annotation.member.value: b2, B
+T6881115.java:26:32: compiler.err.annotation.missing.default.value: B, b1
 15 errors
--- a/test/langtools/tools/javac/annotations/neg/Cycle3.java	Wed Dec 05 17:50:14 2018 -0800
+++ b/test/langtools/tools/javac/annotations/neg/Cycle3.java	Wed Dec 05 11:31:20 2018 -0800
@@ -14,10 +14,10 @@
 
 @Retention(RUNTIME)
 @interface A {
-    A[] values() default { @A() };
+    A[] values() default { @A };
 }
 
-@A()
+@A
 class Main {
     public static void main(String[] args) {
         A a = Main.class.getAnnotation(A.class);
--- a/test/langtools/tools/javac/annotations/pos/Primitives.java	Wed Dec 05 17:50:14 2018 -0800
+++ b/test/langtools/tools/javac/annotations/pos/Primitives.java	Wed Dec 05 11:31:20 2018 -0800
@@ -39,8 +39,8 @@
         Class[] value() default { void.class };
     }
 
-    @A()
-    @B()
+    @A
+    @B
     static class T1 {}
 
     @A(int.class)
--- a/test/langtools/tools/javac/annotations/repeatingAnnotations/BaseAnnoAsContainerAnno.java	Wed Dec 05 17:50:14 2018 -0800
+++ b/test/langtools/tools/javac/annotations/repeatingAnnotations/BaseAnnoAsContainerAnno.java	Wed Dec 05 11:31:20 2018 -0800
@@ -13,6 +13,6 @@
     Foo[] value() default {};
 }
 
-@Foo() @Foo()
+@Foo @Foo
 public class BaseAnnoAsContainerAnno {}
 
--- a/test/langtools/tools/javac/annotations/repeatingAnnotations/MissingContainer.java	Wed Dec 05 17:50:14 2018 -0800
+++ b/test/langtools/tools/javac/annotations/repeatingAnnotations/MissingContainer.java	Wed Dec 05 11:31:20 2018 -0800
@@ -8,7 +8,7 @@
 
 import java.lang.annotation.Repeatable;
 
-@Repeatable()
+@Repeatable
 @interface Foo {}
 
 @interface FooContainer {
--- a/test/langtools/tools/javac/annotations/typeAnnotations/api/AnnotatedArrayOrder.java	Wed Dec 05 17:50:14 2018 -0800
+++ b/test/langtools/tools/javac/annotations/typeAnnotations/api/AnnotatedArrayOrder.java	Wed Dec 05 11:31:20 2018 -0800
@@ -107,30 +107,30 @@
     // visited code
     @A String @C [] @B [] field;
     static {
-        // Shouldn't find @A(), as it is field annotation
-        expectedLocations.put("@B()", 1);
-        expectedLocations.put("@C()", 2);
+        // Shouldn't find @A, as it is field annotation
+        expectedLocations.put("@B", 1);
+        expectedLocations.put("@C", 2);
     }
 
     List<@D String @F [] @E []> typearg;
     static {
-        expectedLocations.put("@D()", 0);
-        expectedLocations.put("@E()", 1);
-        expectedLocations.put("@F()", 2);
+        expectedLocations.put("@D", 0);
+        expectedLocations.put("@E", 1);
+        expectedLocations.put("@F", 2);
     }
 
     void varargSimple(@G String @H ... vararg1) { }
     static {
-        // Shouldn't find @G(), as it is a parameter annotation
-        expectedLocations.put("@H()", 1);
+        // Shouldn't find @G, as it is a parameter annotation
+        expectedLocations.put("@H", 1);
     }
 
     void varargLong(@I String @L [] @K [] @J ... vararg2) { }
     static {
-        // Shouldn't find @I(), as it is a parameter annotation
-        expectedLocations.put("@J()", 1);
-        expectedLocations.put("@K()", 2);
-        expectedLocations.put("@L()", 3);
+        // Shouldn't find @I, as it is a parameter annotation
+        expectedLocations.put("@J", 1);
+        expectedLocations.put("@K", 2);
+        expectedLocations.put("@L", 3);
     }
 
     @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
--- a/test/langtools/tools/javac/annotations/typeAnnotations/api/ArrayCreationTree.java	Wed Dec 05 17:50:14 2018 -0800
+++ b/test/langtools/tools/javac/annotations/typeAnnotations/api/ArrayCreationTree.java	Wed Dec 05 11:31:20 2018 -0800
@@ -84,11 +84,11 @@
             foundAnnotations++;
 
             int expected = -1;
-            if (annotation.equals("@A()"))
+            if (annotation.equals("@A"))
                 expected = 0;
-            else if (annotation.equals("@B()"))
+            else if (annotation.equals("@B"))
                 expected = 1;
-            else if (annotation.equals("@C()"))
+            else if (annotation.equals("@C"))
                 expected = 2;
             else
                 throw new AssertionError("found an unexpected annotation: " + annotation);
--- a/test/langtools/tools/javac/annotations/typeAnnotations/api/ArrayPositionConsistency.java	Wed Dec 05 17:50:14 2018 -0800
+++ b/test/langtools/tools/javac/annotations/typeAnnotations/api/ArrayPositionConsistency.java	Wed Dec 05 11:31:20 2018 -0800
@@ -79,11 +79,11 @@
             foundAnnotations++;
 
             int expected = -1;
-            if (annotation.equals("@A()"))
+            if (annotation.equals("@A"))
                 expected = 0;
-            else if (annotation.equals("@B()"))
+            else if (annotation.equals("@B"))
                 expected = 1;
-            else if (annotation.equals("@C()"))
+            else if (annotation.equals("@C"))
                 expected = 2;
             else
                 throw new AssertionError("found an unexpected annotation: " + annotation);
--- a/test/langtools/tools/javac/annotations/typeAnnotations/failures/AnnotatedMethodSelectorTest.java	Wed Dec 05 17:50:14 2018 -0800
+++ b/test/langtools/tools/javac/annotations/typeAnnotations/failures/AnnotatedMethodSelectorTest.java	Wed Dec 05 11:31:20 2018 -0800
@@ -9,6 +9,6 @@
 class AnnotatedMethodSelectorTest {
     @interface A {}
     static public void main(String... args) {
-        java.util.@A() Arrays.stream(args);
+        java.util.@A Arrays.stream(args);
     }
 }
--- a/test/langtools/tools/javac/diags/examples/AnnoNotApplicable.java	Wed Dec 05 17:50:14 2018 -0800
+++ b/test/langtools/tools/javac/diags/examples/AnnoNotApplicable.java	Wed Dec 05 11:31:20 2018 -0800
@@ -29,5 +29,5 @@
 @interface Anno { }
 
 
-@Anno()
+@Anno
 class AnnoNotApplicable { }
--- a/test/langtools/tools/javac/tree/TypeAnnotationsPretty.java	Wed Dec 05 17:50:14 2018 -0800
+++ b/test/langtools/tools/javac/tree/TypeAnnotationsPretty.java	Wed Dec 05 11:31:20 2018 -0800
@@ -60,26 +60,26 @@
     public static void main(String... args) throws Exception {
         TypeAnnotationsPretty tap = new TypeAnnotationsPretty();
 
-        tap.runField("@TA()\nObject cls = null");
-        tap.runField("@TA()\nObject cls = new @TA() Object()");
+        tap.runField("@TA\nObject cls = null");
+        tap.runField("@TA\nObject cls = new @TA Object()");
 
-        tap.runField("@TA()\nList<@TB() Object> cls = null");
-        tap.runField("@TA()\nList<@TB() Object> cls = new @TA() LinkedList<@TB() Object>()");
+        tap.runField("@TA\nList<@TB Object> cls = null");
+        tap.runField("@TA\nList<@TB Object> cls = new @TA LinkedList<@TB Object>()");
 
         tap.runField("Class[] cls = null");
-        tap.runField("@TA()\nClass[] cls = null");
-        tap.runField("Class @TA() [] cls = null");
-        tap.runField("@TA()\nClass @TB() [] cls = null");
+        tap.runField("@TA\nClass[] cls = null");
+        tap.runField("Class @TA [] cls = null");
+        tap.runField("@TA\nClass @TB [] cls = null");
 
         tap.runField("Class[] cls = new Class[]{Object.class}");
-        tap.runField("@TA()\nClass[] cls = new @TA() Class[]{Object.class}");
-        tap.runField("Class @TB() [] cls = new Class @TB() []{Object.class}");
-        tap.runField("@TA()\nClass @TB() [] cls = new @TA() Class @TB() []{Object.class}");
-        tap.runField("@TA()\nClass @TB() [] @TC() [] cls = new @TA() Class @TB() [10] @TC() []");
-        tap.runField("Class @TB() [] @TC() [] cls = new Class @TB() [10] @TC() []");
-        tap.runField("@TA()\nClass @TB() [] @TC() [] @TD() [] cls = new @TA() Class @TB() [10] @TC() [] @TD() []");
+        tap.runField("@TA\nClass[] cls = new @TA Class[]{Object.class}");
+        tap.runField("Class @TB [] cls = new Class @TB []{Object.class}");
+        tap.runField("@TA\nClass @TB [] cls = new @TA Class @TB []{Object.class}");
+        tap.runField("@TA\nClass @TB [] @TC [] cls = new @TA Class @TB [10] @TC []");
+        tap.runField("Class @TB [] @TC [] cls = new Class @TB [10] @TC []");
+        tap.runField("@TA\nClass @TB [] @TC [] @TD [] cls = new @TA Class @TB [10] @TC [] @TD []");
 
-        tap.runMethod("\n@TA()\nObject test(@TB()\nList<@TC() String> p) {\n" +
+        tap.runMethod("\n@TA\nObject test(@TB\nList<@TC String> p) {\n" +
                 "    return null;\n" +
                 "}");