changeset 2213:4a815e93138d

Expand tests for when declaration annotations are legal and add missing TYPE_USE Targets.
author wmdietl
date Sun, 17 Feb 2013 20:32:21 -0800
parents b503e62ca0e7
children dbef4179abd8
files test/tools/javac/annotations/typeAnnotations/attribution/Scopes.java test/tools/javac/annotations/typeAnnotations/failures/StaticMethods.java test/tools/javac/annotations/typeAnnotations/failures/StaticMethods.out test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.java test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.out test/tools/javac/annotations/typeAnnotations/failures/common/receiver/DeclarationAnnotation.java test/tools/javac/annotations/typeAnnotations/failures/common/receiver/DeclarationAnnotation.out test/tools/javac/annotations/typeAnnotations/failures/common/receiver/Nesting.java test/tools/javac/annotations/typeAnnotations/failures/common/receiver/StaticThings.out test/tools/javac/annotations/typeAnnotations/failures/common/receiver/WrongType.java test/tools/javac/annotations/typeAnnotations/failures/common/receiver/WrongType.out test/tools/javac/annotations/typeAnnotations/failures/common/rest/MissingAnnotationValue.java
diffstat 12 files changed, 81 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/test/tools/javac/annotations/typeAnnotations/attribution/Scopes.java	Sun Feb 17 20:29:15 2013 -0800
+++ b/test/tools/javac/annotations/typeAnnotations/attribution/Scopes.java	Sun Feb 17 20:32:21 2013 -0800
@@ -28,11 +28,17 @@
  * @author Mahmood Ali
  * @compile Scopes.java
  */
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
 class Scopes {
 
   void test(@A(VALUE) Scopes this) { }
   void test1(@A(value=VALUE) Scopes this) { }
 
   private static final int VALUE = 1;
+
+  @Target(ElementType.TYPE_USE)
   @interface A { int value(); }
 }
--- a/test/tools/javac/annotations/typeAnnotations/failures/StaticMethods.java	Sun Feb 17 20:29:15 2013 -0800
+++ b/test/tools/javac/annotations/typeAnnotations/failures/StaticMethods.java	Sun Feb 17 20:32:21 2013 -0800
@@ -6,7 +6,7 @@
  * @compile/fail/ref=StaticMethods.out -XDrawDiagnostics StaticMethods.java
  */
 class StaticMethods {
-  static void main(@A StaticMethods this) { }
+  static void main(StaticMethods this) { }
 }
 
 @interface A { }
--- a/test/tools/javac/annotations/typeAnnotations/failures/StaticMethods.out	Sun Feb 17 20:29:15 2013 -0800
+++ b/test/tools/javac/annotations/typeAnnotations/failures/StaticMethods.out	Sun Feb 17 20:32:21 2013 -0800
@@ -1,2 +1,2 @@
-StaticMethods.java:9:37: compiler.err.annotation.type.not.applicable
-1 error
+StaticMethods.java:9:34: compiler.err.receiver.parameter.not.applicable
+1 error
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.java	Sun Feb 17 20:32:21 2013 -0800
@@ -0,0 +1,19 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 1234567
+ * @summary ensure that declaration annotations are not allowed on
+ *   new array expressions
+ * @author Werner Dietl
+ * @compile/fail/ref=DeclarationAnnotation.out -XDrawDiagnostics DeclarationAnnotation.java
+ */
+class DeclarationAnnotation {
+    Object e1 = new @DA int[5];
+    Object e2 = new @DA String[42];
+    Object e3 = new @DA Object();
+
+    // The declaration annotation is only allowed for
+    // an anonymous class creation.
+    Object ok = new @DA Object() { };
+}
+
+@interface DA { }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.out	Sun Feb 17 20:32:21 2013 -0800
@@ -0,0 +1,4 @@
+DeclarationAnnotation.java:10:21: compiler.err.annotation.type.not.applicable
+DeclarationAnnotation.java:11:21: compiler.err.annotation.type.not.applicable
+DeclarationAnnotation.java:12:21: compiler.err.annotation.type.not.applicable
+3 errors
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/DeclarationAnnotation.java	Sun Feb 17 20:32:21 2013 -0800
@@ -0,0 +1,21 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 1234567
+ * @summary ensure that declaration annotations are not allowed on
+ *   method receiver types
+ * @author Werner Dietl
+ * @compile/fail/ref=DeclarationAnnotation.out -XDrawDiagnostics DeclarationAnnotation.java
+ */
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+class DeclarationAnnotation {
+    void bad(@DA DeclarationAnnotation this) {}
+    void good(@TA DeclarationAnnotation this) {}
+}
+
+@interface DA { }
+
+@Target(ElementType.TYPE_USE)
+@interface TA { }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/DeclarationAnnotation.out	Sun Feb 17 20:32:21 2013 -0800
@@ -0,0 +1,2 @@
+DeclarationAnnotation.java:14:14: compiler.err.annotation.type.not.applicable
+1 error
--- a/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/Nesting.java	Sun Feb 17 20:29:15 2013 -0800
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/Nesting.java	Sun Feb 17 20:32:21 2013 -0800
@@ -28,6 +28,11 @@
  * @author Werner Dietl
  * @compile Nesting.java
  */
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE_USE)
 @interface A { }
 
 class Nesting {
--- a/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/StaticThings.out	Sun Feb 17 20:29:15 2013 -0800
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/StaticThings.out	Sun Feb 17 20:32:21 2013 -0800
@@ -1,5 +1,5 @@
-StaticThings.java:52:32: compiler.err.annotation.type.not.applicable
-StaticThings.java:54:37: compiler.err.annotation.type.not.applicable
-StaticThings.java:33:26: compiler.err.annotation.type.not.applicable
-StaticThings.java:36:28: compiler.err.annotation.type.not.applicable
+StaticThings.java:52:32: compiler.err.receiver.parameter.not.applicable
+StaticThings.java:54:37: compiler.err.receiver.parameter.not.applicable
+StaticThings.java:33:26: compiler.err.receiver.parameter.not.applicable
+StaticThings.java:36:28: compiler.err.receiver.parameter.not.applicable
 4 errors
\ No newline at end of file
--- a/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/WrongType.java	Sun Feb 17 20:29:15 2013 -0800
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/WrongType.java	Sun Feb 17 20:32:21 2013 -0800
@@ -29,6 +29,10 @@
  * @compile/fail/ref=WrongType.out -XDrawDiagnostics WrongType.java
  */
 
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE_USE)
 @interface A {}
 
 class WrongType {
--- a/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/WrongType.out	Sun Feb 17 20:29:15 2013 -0800
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/WrongType.out	Sun Feb 17 20:32:21 2013 -0800
@@ -1,9 +1,9 @@
-WrongType.java:51:15: compiler.err.cant.resolve.location: kindname.class, XYZ, , , (compiler.misc.location: kindname.class, WrongType, null)
-WrongType.java:61:27: compiler.err.doesnt.exist: Outer
-WrongType.java:62:31: compiler.err.cant.resolve.location: kindname.class, XY, , , (compiler.misc.location: kindname.class, WrongType, null)
-WrongType.java:44:23: compiler.err.incorrect.receiver.type
-WrongType.java:46:23: compiler.err.incorrect.receiver.type
-WrongType.java:59:33: compiler.err.incorrect.receiver.type
-WrongType.java:60:31: compiler.err.incorrect.receiver.type
-WrongType.java:66:28: compiler.err.incorrect.receiver.type
+WrongType.java:55:15: compiler.err.cant.resolve.location: kindname.class, XYZ, , , (compiler.misc.location: kindname.class, WrongType, null)
+WrongType.java:65:27: compiler.err.doesnt.exist: Outer
+WrongType.java:66:31: compiler.err.cant.resolve.location: kindname.class, XY, , , (compiler.misc.location: kindname.class, WrongType, null)
+WrongType.java:48:23: compiler.err.incorrect.receiver.type
+WrongType.java:50:23: compiler.err.incorrect.receiver.type
+WrongType.java:63:33: compiler.err.incorrect.receiver.type
+WrongType.java:64:31: compiler.err.incorrect.receiver.type
+WrongType.java:70:28: compiler.err.incorrect.receiver.type
 8 errors
\ No newline at end of file
--- a/test/tools/javac/annotations/typeAnnotations/failures/common/rest/MissingAnnotationValue.java	Sun Feb 17 20:29:15 2013 -0800
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/rest/MissingAnnotationValue.java	Sun Feb 17 20:32:21 2013 -0800
@@ -5,10 +5,15 @@
  * @author Mahmood Ali
  * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics MissingAnnotationValue.java
  */
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
 class MissingAnnotationValue {
   void test() {
     new @A String();
   }
 }
 
+@Target(ElementType.TYPE_USE)
 @interface A { int field(); }