### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java,v retrieving revision 1.153 diff -u -r1.153 AnnotationTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java 8 Jun 2006 13:07:58 -0000 1.153 +++ src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java 12 Sep 2006 19:10:07 -0000 @@ -39,7 +39,7 @@ // All specified tests which do not belong to the class are skipped... static { // TESTS_NAMES = new String[] { "test127" }; -// TESTS_NUMBERS = new int[] { 196 }; +// TESTS_NUMBERS = new int[] { 212, 213 }; // TESTS_RANGE = new int[] { 169, 180 }; } @@ -6158,7 +6158,7 @@ "1. ERROR in X.java (at line 4)\n" + " @A1(values = new int[] { 1, 2 })\n" + " ^^^^^^^^^^^^^^^^^^\n" + - "The array creation is unnecessary in an annotation value; only an array initializer is allowed\n" + + "The value for annotation attribute A1.values must be an array initializer\n" + "----------\n"); } // partial recompile - keep a binary @@ -6482,7 +6482,7 @@ "1. ERROR in X.java (at line 5)\n" + " public MyEnum theValue() default null;\n" + " ^^^^\n" + - "The value for annotation attribute X.theValue must be a constant expression\n" + + "The value for annotation attribute X.theValue must be an enum constant expression\n" + "----------\n"); } // no override between package private methods @@ -6815,4 +6815,189 @@ "NonExisting cannot be resolved to a type\n" + "----------\n"); } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149751 +public void test208() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "@Retention(RUNTIME) @interface MyAnnotation {\n" + + " public MyEnum value();\n" + + "}\n" + + "enum MyEnum {\n" + + " ONE, TWO, THREE\n" + + "}\n" + + "@MyAnnotation(X.FOO) class MyClass {\n" + + "}\n" + + "public class X {\n" + + " public static final MyEnum FOO = MyEnum.TWO;\n" + + " public static void main(String[] args) {\n" + + " MyAnnotation annotation =\n" + + " MyClass.class.getAnnotation(MyAnnotation.class);\n" + + " System.out.println(annotation.value().toString());\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " @MyAnnotation(X.FOO) class MyClass {\n" + + " ^^^^^\n" + + "The value for annotation attribute MyAnnotation.value must be an enum constant expression\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149751 +public void test209() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "@Retention(RUNTIME) @interface MyAnnotation {\n" + + " public MyEnum value();\n" + + "}\n" + + "enum MyEnum {\n" + + " ONE, TWO, THREE\n" + + "}\n" + + "@MyAnnotation(value=X.FOO) class MyClass {\n" + + "}\n" + + "public class X {\n" + + " public static final MyEnum FOO = MyEnum.TWO;\n" + + " public static void main(String[] args) {\n" + + " MyAnnotation annotation =\n" + + " MyClass.class.getAnnotation(MyAnnotation.class);\n" + + " System.out.println(annotation.value().toString());\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " @MyAnnotation(value=X.FOO) class MyClass {\n" + + " ^^^^^\n" + + "The value for annotation attribute MyAnnotation.value must be an enum constant expression\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149751 +public void test210() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "@Retention(RUNTIME) @interface MyAnnotation {\n" + + " public MyEnum[] value();\n" + + "}\n" + + "enum MyEnum {\n" + + " ONE, TWO, THREE\n" + + "}\n" + + "@MyAnnotation(value= { X.FOO }) class MyClass {\n" + + "}\n" + + "public class X {\n" + + " public static final MyEnum FOO = MyEnum.TWO;\n" + + " public static void main(String[] args) {\n" + + " MyAnnotation annotation =\n" + + " MyClass.class.getAnnotation(MyAnnotation.class);\n" + + " System.out.println(annotation.value().toString());\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " @MyAnnotation(value= { X.FOO }) class MyClass {\n" + + " ^^^^^\n" + + "The value for annotation attribute MyAnnotation.value must be an enum constant expression\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149751 +public void test211() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "@Retention(RUNTIME) @interface MyAnnotation {\n" + + " public MyEnum[] value();\n" + + "}\n" + + "enum MyEnum {\n" + + " ONE, TWO, THREE\n" + + "}\n" + + "@MyAnnotation(value= { null }) class MyClass {\n" + + "}\n" + + "public class X {\n" + + " public static final MyEnum FOO = MyEnum.TWO;\n" + + " public static void main(String[] args) {\n" + + " MyAnnotation annotation =\n" + + " MyClass.class.getAnnotation(MyAnnotation.class);\n" + + " System.out.println(annotation.value().toString());\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " @MyAnnotation(value= { null }) class MyClass {\n" + + " ^^^^\n" + + "The value for annotation attribute MyAnnotation.value must be an enum constant expression\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156891 +public void test212() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "@Retention(RUNTIME) @interface MyAnnotation {\n" + + " public MyEnum[] values();\n" + + "}\n" + + "enum MyEnum {\n" + + " ONE, TWO, THREE\n" + + "}\n" + + "public class X {\n" + + "\n" + + " private static final MyEnum[] myValues = { MyEnum.ONE, MyEnum.TWO };\n" + + " @MyAnnotation(values=myValues) \n" + + " public void dothetrick(){} \n" + + "\n" + + " public static void main(String[] args)throws Exception {\n" + + " MyAnnotation sluck = X.class.getMethod(\"dothetrick\", new Class[0]).getAnnotation(MyAnnotation.class);\n" + + " System.out.println(sluck.values().length);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " @MyAnnotation(values=myValues) \n" + + " ^^^^^^^^\n" + + "The value for annotation attribute MyAnnotation.values must be an array initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156891 +public void test213() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "@Retention(RUNTIME) @interface MyAnnotation {\n" + + " public int[] values();\n" + + "}\n" + + "public class X {\n" + + "\n" + + " private static final int[] myValues = { 1, 2, 3 };\n" + + " @MyAnnotation(values=myValues) \n" + + " public void dothetrick(){} \n" + + "\n" + + " public static void main(String[] args)throws Exception {\n" + + " MyAnnotation sluck = X.class.getMethod(\"dothetrick\", new Class[0]).getAnnotation(MyAnnotation.class);\n" + + " System.out.println(sluck.values().length);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " @MyAnnotation(values=myValues) \n" + + " ^^^^^^^^\n" + + "The value for annotation attribute MyAnnotation.values must be an array initializer\n" + + "----------\n"); +} }