View | Details | Raw Unified | Return to bug 149751 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java (-1 / +186 lines)
Lines 39-45 Link Here
39
	// All specified tests which do not belong to the class are skipped...
39
	// All specified tests which do not belong to the class are skipped...
40
	static {
40
	static {
41
//		TESTS_NAMES = new String[] { "test127" };
41
//		TESTS_NAMES = new String[] { "test127" };
42
//		TESTS_NUMBERS = new int[] { 196 };
42
//		TESTS_NUMBERS = new int[] { 212, 213 };
43
//		TESTS_RANGE = new int[] { 169, 180 };
43
//		TESTS_RANGE = new int[] { 169, 180 };
44
	}
44
	}
45
45
Lines 6815-6818 Link Here
6815
		"NonExisting cannot be resolved to a type\n" + 
6815
		"NonExisting cannot be resolved to a type\n" + 
6816
		"----------\n");
6816
		"----------\n");
6817
}
6817
}
6818
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149751
6819
public void test208() {
6820
    this.runNegativeTest(
6821
        new String[] {
6822
            "X.java",
6823
			"import java.lang.annotation.Retention;\n" + 
6824
			"import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + 
6825
			"@Retention(RUNTIME) @interface MyAnnotation {\n" + 
6826
			"    public MyEnum value();\n" + 
6827
			"}\n" + 
6828
			"enum MyEnum {\n" + 
6829
			"    ONE, TWO, THREE\n" + 
6830
			"}\n" + 
6831
			"@MyAnnotation(X.FOO) class MyClass {\n" + 
6832
			"}\n" + 
6833
			"public class X {\n" + 
6834
			"    public static final MyEnum FOO = MyEnum.TWO;\n" + 
6835
			"    public static void main(String[] args) {\n" + 
6836
			"        MyAnnotation annotation =\n" + 
6837
			"                MyClass.class.getAnnotation(MyAnnotation.class);\n" + 
6838
			"        System.out.println(annotation.value().toString());\n" + 
6839
			"    }\n" + 
6840
			"}",
6841
        },
6842
        "----------\n" + 
6843
		"1. ERROR in X.java (at line 9)\n" + 
6844
		"	@MyAnnotation(X.FOO) class MyClass {\n" + 
6845
		"	              ^^^^^\n" + 
6846
		"The value for annotation attribute MyAnnotation.value must be a constant expression\n" + 
6847
		"----------\n");
6848
}
6849
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149751
6850
public void test209() {
6851
    this.runNegativeTest(
6852
        new String[] {
6853
            "X.java",
6854
			"import java.lang.annotation.Retention;\n" + 
6855
			"import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + 
6856
			"@Retention(RUNTIME) @interface MyAnnotation {\n" + 
6857
			"    public MyEnum value();\n" + 
6858
			"}\n" + 
6859
			"enum MyEnum {\n" + 
6860
			"    ONE, TWO, THREE\n" + 
6861
			"}\n" + 
6862
			"@MyAnnotation(value=X.FOO) class MyClass {\n" + 
6863
			"}\n" + 
6864
			"public class X {\n" + 
6865
			"    public static final MyEnum FOO = MyEnum.TWO;\n" + 
6866
			"    public static void main(String[] args) {\n" + 
6867
			"        MyAnnotation annotation =\n" + 
6868
			"                MyClass.class.getAnnotation(MyAnnotation.class);\n" + 
6869
			"        System.out.println(annotation.value().toString());\n" + 
6870
			"    }\n" + 
6871
			"}",
6872
        },
6873
        "----------\n" + 
6874
		"1. ERROR in X.java (at line 9)\n" + 
6875
		"	@MyAnnotation(value=X.FOO) class MyClass {\n" + 
6876
		"	                    ^^^^^\n" + 
6877
		"The value for annotation attribute MyAnnotation.value must be a constant expression\n" + 
6878
		"----------\n");
6879
}
6880
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149751
6881
public void test210() {
6882
    this.runNegativeTest(
6883
        new String[] {
6884
            "X.java",
6885
			"import java.lang.annotation.Retention;\n" + 
6886
			"import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + 
6887
			"@Retention(RUNTIME) @interface MyAnnotation {\n" + 
6888
			"    public MyEnum[] value();\n" + 
6889
			"}\n" + 
6890
			"enum MyEnum {\n" + 
6891
			"    ONE, TWO, THREE\n" + 
6892
			"}\n" + 
6893
			"@MyAnnotation(value= { X.FOO }) class MyClass {\n" + 
6894
			"}\n" + 
6895
			"public class X {\n" + 
6896
			"    public static final MyEnum FOO = MyEnum.TWO;\n" + 
6897
			"    public static void main(String[] args) {\n" + 
6898
			"        MyAnnotation annotation =\n" + 
6899
			"                MyClass.class.getAnnotation(MyAnnotation.class);\n" + 
6900
			"        System.out.println(annotation.value().toString());\n" + 
6901
			"    }\n" + 
6902
			"}",
6903
        },
6904
        "----------\n" + 
6905
		"1. ERROR in X.java (at line 9)\n" + 
6906
		"	@MyAnnotation(value= { X.FOO }) class MyClass {\n" + 
6907
		"	                       ^^^^^\n" + 
6908
		"The value for annotation attribute MyAnnotation.value must be a constant expression\n" + 
6909
		"----------\n");
6910
}
6911
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149751
6912
public void test211() {
6913
    this.runNegativeTest(
6914
        new String[] {
6915
            "X.java",
6916
			"import java.lang.annotation.Retention;\n" + 
6917
			"import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + 
6918
			"@Retention(RUNTIME) @interface MyAnnotation {\n" + 
6919
			"    public MyEnum[] value();\n" + 
6920
			"}\n" + 
6921
			"enum MyEnum {\n" + 
6922
			"    ONE, TWO, THREE\n" + 
6923
			"}\n" + 
6924
			"@MyAnnotation(value= { null }) class MyClass {\n" + 
6925
			"}\n" + 
6926
			"public class X {\n" + 
6927
			"    public static final MyEnum FOO = MyEnum.TWO;\n" + 
6928
			"    public static void main(String[] args) {\n" + 
6929
			"        MyAnnotation annotation =\n" + 
6930
			"                MyClass.class.getAnnotation(MyAnnotation.class);\n" + 
6931
			"        System.out.println(annotation.value().toString());\n" + 
6932
			"    }\n" + 
6933
			"}",
6934
        },
6935
        "----------\n" + 
6936
		"1. ERROR in X.java (at line 9)\n" + 
6937
		"	@MyAnnotation(value= { null }) class MyClass {\n" + 
6938
		"	                       ^^^^\n" + 
6939
		"The value for annotation attribute MyAnnotation.value must be a constant expression\n" + 
6940
		"----------\n");
6941
}
6942
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156891
6943
public void test212() {
6944
    this.runNegativeTest(
6945
        new String[] {
6946
            "X.java",
6947
			"import java.lang.annotation.Retention;\n" + 
6948
			"import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + 
6949
			"@Retention(RUNTIME) @interface MyAnnotation {\n" + 
6950
			"    public MyEnum[] values();\n" + 
6951
			"}\n" + 
6952
			"enum MyEnum {\n" + 
6953
			"    ONE, TWO, THREE\n" + 
6954
			"}\n" + 
6955
			"public class X {\n" + 
6956
			"\n" + 
6957
			"		private static final MyEnum[] myValues = { MyEnum.ONE, MyEnum.TWO };\n" +
6958
			"       @MyAnnotation(values=myValues) \n" + 
6959
			"       public void dothetrick(){} \n" + 
6960
			"\n" + 
6961
			"        public static void main(String[] args)throws Exception {\n" + 
6962
			"                MyAnnotation sluck = X.class.getMethod(\"dothetrick\", new Class[0]).getAnnotation(MyAnnotation.class);\n" + 
6963
			"                System.out.println(sluck.values().length);\n" + 
6964
			"        }\n" + 
6965
			"}",
6966
        },
6967
        "----------\n" + 
6968
		"1. ERROR in X.java (at line 12)\n" + 
6969
		"	@MyAnnotation(values=myValues) \n" + 
6970
		"	                     ^^^^^^^^\n" + 
6971
		"The array creation is unnecessary in an annotation value; only an array initializer is allowed\n" + 
6972
		"----------\n");
6973
}
6974
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156891
6975
public void test213() {
6976
    this.runNegativeTest(
6977
        new String[] {
6978
            "X.java",
6979
			"import java.lang.annotation.Retention;\n" + 
6980
			"import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + 
6981
			"@Retention(RUNTIME) @interface MyAnnotation {\n" + 
6982
			"    public int[] values();\n" + 
6983
			"}\n" + 
6984
			"public class X {\n" + 
6985
			"\n" + 
6986
			"		private static final int[] myValues = { 1, 2, 3 };\n" +
6987
			"       @MyAnnotation(values=myValues) \n" + 
6988
			"       public void dothetrick(){} \n" + 
6989
			"\n" + 
6990
			"        public static void main(String[] args)throws Exception {\n" + 
6991
			"                MyAnnotation sluck = X.class.getMethod(\"dothetrick\", new Class[0]).getAnnotation(MyAnnotation.class);\n" + 
6992
			"                System.out.println(sluck.values().length);\n" + 
6993
			"        }\n" + 
6994
			"}",
6995
        },
6996
        "----------\n" + 
6997
		"1. ERROR in X.java (at line 9)\n" + 
6998
		"	@MyAnnotation(values=myValues) \n" + 
6999
		"	                     ^^^^^^^^\n" + 
7000
		"The array creation is unnecessary in an annotation value; only an array initializer is allowed\n" + 
7001
		"----------\n");
7002
}
6818
}
7003
}

Return to bug 149751