8214902: Pretty-printing marker annotations add unnecessary parenthesis
Reviewed-by: jjg
This commit is contained in:
parent
54cc30e6c1
commit
7f365fffbd
@ -1525,9 +1525,11 @@ public class Pretty extends JCTree.Visitor {
|
||||
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);
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
package pkg;
|
||||
|
||||
@Deprecated()
|
||||
@Deprecated
|
||||
public class DeprecatedClassByAnnotation {
|
||||
|
||||
@Deprecated(forRemoval=true)
|
||||
@ -32,6 +32,6 @@ public class DeprecatedClassByAnnotation {
|
||||
@Deprecated(forRemoval=true)
|
||||
public DeprecatedClassByAnnotation() {}
|
||||
|
||||
@Deprecated()
|
||||
@Deprecated
|
||||
public void method() {}
|
||||
}
|
||||
|
@ -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() {}
|
||||
}
|
||||
|
@ -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() {}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Anno(req = true)
|
||||
@Anno()
|
||||
@Anno
|
||||
public class CannotCompileRepeatedAnnoTest {
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ import java.lang.annotation.ElementType;
|
||||
@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 @@ import java.lang.annotation.ElementType;
|
||||
}
|
||||
|
||||
@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> {}
|
||||
|
@ -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
|
||||
|
@ -14,10 +14,10 @@ import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
@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);
|
||||
|
@ -39,8 +39,8 @@ public class Primitives {
|
||||
Class[] value() default { void.class };
|
||||
}
|
||||
|
||||
@A()
|
||||
@B()
|
||||
@A
|
||||
@B
|
||||
static class T1 {}
|
||||
|
||||
@A(int.class)
|
||||
|
@ -13,6 +13,6 @@ import java.lang.annotation.Repeatable;
|
||||
Foo[] value() default {};
|
||||
}
|
||||
|
||||
@Foo() @Foo()
|
||||
@Foo @Foo
|
||||
public class BaseAnnoAsContainerAnno {}
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import java.lang.annotation.Repeatable;
|
||||
|
||||
@Repeatable()
|
||||
@Repeatable
|
||||
@interface Foo {}
|
||||
|
||||
@interface FooContainer {
|
||||
|
@ -107,30 +107,30 @@ public class AnnotatedArrayOrder {
|
||||
// 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})
|
||||
|
@ -84,11 +84,11 @@ public class ArrayCreationTree {
|
||||
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);
|
||||
|
@ -79,11 +79,11 @@ public class ArrayPositionConsistency {
|
||||
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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -29,5 +29,5 @@ import java.lang.annotation.*;
|
||||
@interface Anno { }
|
||||
|
||||
|
||||
@Anno()
|
||||
@Anno
|
||||
class AnnoNotApplicable { }
|
||||
|
@ -60,26 +60,26 @@ public class TypeAnnotationsPretty {
|
||||
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" +
|
||||
"}");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user