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 (-16 / +140 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[] { 210, 211 };
43
//		TESTS_RANGE = new int[] { 169, 180 };
43
//		TESTS_RANGE = new int[] { 169, 180 };
44
	}
44
	}
45
45
Lines 521-532 Link Here
521
			"1. ERROR in X.java (at line 2)\n" + 
521
			"1. ERROR in X.java (at line 2)\n" + 
522
			"	int value() default X.val();\n" + 
522
			"	int value() default X.val();\n" + 
523
			"	                    ^^^^^^^\n" + 
523
			"	                    ^^^^^^^\n" + 
524
			"The value for annotation attribute Foo.value must be a constant expression\n" + 
524
			"The value for annotation attribute Foo.value must be an enum constant expression\n" + 
525
			"----------\n" + 
525
			"----------\n" + 
526
			"2. ERROR in X.java (at line 6)\n" + 
526
			"2. ERROR in X.java (at line 6)\n" + 
527
			"	@Foo( val() )\n" + 
527
			"	@Foo( val() )\n" + 
528
			"	      ^^^^^\n" + 
528
			"	      ^^^^^\n" + 
529
			"The value for annotation attribute Foo.value must be a constant expression\n" + 
529
			"The value for annotation attribute Foo.value must be an enum constant expression\n" + 
530
			"----------\n");
530
			"----------\n");
531
	}		
531
	}		
532
	// check String annotation member value must be a constant
532
	// check String annotation member value must be a constant
Lines 548-559 Link Here
548
			"1. ERROR in X.java (at line 2)\n" + 
548
			"1. ERROR in X.java (at line 2)\n" + 
549
			"	String value() default X.val();\n" + 
549
			"	String value() default X.val();\n" + 
550
			"	                       ^^^^^^^\n" + 
550
			"	                       ^^^^^^^\n" + 
551
			"The value for annotation attribute Foo.value must be a constant expression\n" + 
551
			"The value for annotation attribute Foo.value must be an enum constant expression\n" + 
552
			"----------\n" + 
552
			"----------\n" + 
553
			"2. ERROR in X.java (at line 6)\n" + 
553
			"2. ERROR in X.java (at line 6)\n" + 
554
			"	@Foo( val() )\n" + 
554
			"	@Foo( val() )\n" + 
555
			"	      ^^^^^\n" + 
555
			"	      ^^^^^\n" + 
556
			"The value for annotation attribute Foo.value must be a constant expression\n" + 
556
			"The value for annotation attribute Foo.value must be an enum constant expression\n" + 
557
			"----------\n");
557
			"----------\n");
558
	}		
558
	}		
559
	
559
	
Lines 575-586 Link Here
575
			"1. ERROR in X.java (at line 2)\n" + 
575
			"1. ERROR in X.java (at line 2)\n" + 
576
			"	String[] value() default null;\n" + 
576
			"	String[] value() default null;\n" + 
577
			"	                         ^^^^\n" + 
577
			"	                         ^^^^\n" + 
578
			"The value for annotation attribute Foo.value must be a constant expression\n" + 
578
			"The value for annotation attribute Foo.value must be an enum constant expression\n" + 
579
			"----------\n" + 
579
			"----------\n" + 
580
			"2. ERROR in X.java (at line 6)\n" + 
580
			"2. ERROR in X.java (at line 6)\n" + 
581
			"	@Foo( null )\n" + 
581
			"	@Foo( null )\n" + 
582
			"	      ^^^^\n" + 
582
			"	      ^^^^\n" + 
583
			"The value for annotation attribute Foo.value must be a constant expression\n" + 
583
			"The value for annotation attribute Foo.value must be an enum constant expression\n" + 
584
			"----------\n");
584
			"----------\n");
585
	}			
585
	}			
586
	
586
	
Lines 1122-1128 Link Here
1122
		"1. ERROR in X.java (at line 10)\n" + 
1122
		"1. ERROR in X.java (at line 10)\n" + 
1123
		"	@I(val = bar()) void foo() {\n" + 
1123
		"	@I(val = bar()) void foo() {\n" + 
1124
		"	         ^^^^^\n" + 
1124
		"	         ^^^^^\n" + 
1125
		"The value for annotation attribute I.val must be a constant expression\n" + 
1125
		"The value for annotation attribute I.val must be an enum constant expression\n" + 
1126
		"----------\n");
1126
		"----------\n");
1127
	}
1127
	}
1128
	
1128
	
Lines 1198-1204 Link Here
1198
		"1. ERROR in X.java (at line 6)\n" + 
1198
		"1. ERROR in X.java (at line 6)\n" + 
1199
		"	@I(value={false, X.class != null }) void foo() {\n" + 
1199
		"	@I(value={false, X.class != null }) void foo() {\n" + 
1200
		"	                 ^^^^^^^^^^^^^^^\n" + 
1200
		"	                 ^^^^^^^^^^^^^^^\n" + 
1201
		"The value for annotation attribute I.value must be a constant expression\n" + 
1201
		"The value for annotation attribute I.value must be an enum constant expression\n" + 
1202
		"----------\n");
1202
		"----------\n");
1203
	}			
1203
	}			
1204
	
1204
	
Lines 2116-2127 Link Here
2116
			"4. ERROR in X.java (at line 8)\n" + 
2116
			"4. ERROR in X.java (at line 8)\n" + 
2117
			"	@I(ids = {{1 , 2}, { 3 }}) public void foo(){\n" + 
2117
			"	@I(ids = {{1 , 2}, { 3 }}) public void foo(){\n" + 
2118
			"	          ^^^^^^^\n" + 
2118
			"	          ^^^^^^^\n" + 
2119
			"The value for annotation attribute I.ids must be a constant expression\n" + 
2119
			"The value for annotation attribute I.ids must be an enum constant expression\n" + 
2120
			"----------\n" + 
2120
			"----------\n" + 
2121
			"5. ERROR in X.java (at line 8)\n" + 
2121
			"5. ERROR in X.java (at line 8)\n" + 
2122
			"	@I(ids = {{1 , 2}, { 3 }}) public void foo(){\n" + 
2122
			"	@I(ids = {{1 , 2}, { 3 }}) public void foo(){\n" + 
2123
			"	                   ^^^^^\n" + 
2123
			"	                   ^^^^^\n" + 
2124
			"The value for annotation attribute I.ids must be a constant expression\n" + 
2124
			"The value for annotation attribute I.ids must be an enum constant expression\n" + 
2125
			"----------\n");
2125
			"----------\n");
2126
	}	
2126
	}	
2127
2127
Lines 3320-3326 Link Here
3320
			"1. ERROR in X.java (at line 2)\n" + 
3320
			"1. ERROR in X.java (at line 2)\n" + 
3321
			"	int[] bar() default null;\n" + 
3321
			"	int[] bar() default null;\n" + 
3322
			"	                    ^^^^\n" + 
3322
			"	                    ^^^^\n" + 
3323
			"The value for annotation attribute X.bar must be a constant expression\n" + 
3323
			"The value for annotation attribute X.bar must be an enum constant expression\n" + 
3324
			"----------\n");
3324
			"----------\n");
3325
    }
3325
    }
3326
    
3326
    
Lines 3338-3344 Link Here
3338
			"1. ERROR in X.java (at line 4)\n" + 
3338
			"1. ERROR in X.java (at line 4)\n" + 
3339
			"	@Ann(bar=null) class X {}\n" + 
3339
			"	@Ann(bar=null) class X {}\n" + 
3340
			"	         ^^^^\n" + 
3340
			"	         ^^^^\n" + 
3341
			"The value for annotation attribute Ann.bar must be a constant expression\n" + 
3341
			"The value for annotation attribute Ann.bar must be an enum constant expression\n" + 
3342
			"----------\n");
3342
			"----------\n");
3343
    }
3343
    }
3344
    
3344
    
Lines 3574-3580 Link Here
3574
			"1. ERROR in X.java (at line 4)\n" + 
3574
			"1. ERROR in X.java (at line 4)\n" + 
3575
			"	@Annot( foo = new String(){} )\n" + 
3575
			"	@Annot( foo = new String(){} )\n" + 
3576
			"	              ^^^^^^^^^^^^^^\n" + 
3576
			"	              ^^^^^^^^^^^^^^\n" + 
3577
			"The value for annotation attribute Annot.foo must be a constant expression\n" + 
3577
			"The value for annotation attribute Annot.foo must be an enum constant expression\n" + 
3578
			"----------\n" + 
3578
			"----------\n" + 
3579
			"2. ERROR in X.java (at line 4)\n" + 
3579
			"2. ERROR in X.java (at line 4)\n" + 
3580
			"	@Annot( foo = new String(){} )\n" + 
3580
			"	@Annot( foo = new String(){} )\n" + 
Lines 4876-4882 Link Here
4876
			"1. ERROR in X.java (at line 6)\n" + 
4876
			"1. ERROR in X.java (at line 6)\n" + 
4877
			"	@Annot(foo = kkk)\n" + 
4877
			"	@Annot(foo = kkk)\n" + 
4878
			"	             ^^^\n" + 
4878
			"	             ^^^\n" + 
4879
			"The value for annotation attribute Annot.foo must be a constant expression\n" + 
4879
			"The value for annotation attribute Annot.foo must be an enum constant expression\n" + 
4880
			"----------\n" + 
4880
			"----------\n" + 
4881
			"2. ERROR in X.java (at line 10)\n" + 
4881
			"2. ERROR in X.java (at line 10)\n" + 
4882
			"	@Annot(foo = fff)\n" + 
4882
			"	@Annot(foo = fff)\n" + 
Lines 6482-6488 Link Here
6482
		"1. ERROR in X.java (at line 5)\n" + 
6482
		"1. ERROR in X.java (at line 5)\n" + 
6483
		"	public MyEnum theValue() default null;\n" + 
6483
		"	public MyEnum theValue() default null;\n" + 
6484
		"	                                 ^^^^\n" + 
6484
		"	                                 ^^^^\n" + 
6485
		"The value for annotation attribute X.theValue must be a constant expression\n" + 
6485
		"The value for annotation attribute X.theValue must be an enum constant expression\n" + 
6486
		"----------\n");
6486
		"----------\n");
6487
}
6487
}
6488
// no override between package private methods
6488
// no override between package private methods
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 an enum 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 an enum 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 an enum 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 an enum constant expression\n" + 
6940
		"----------\n");
6818
}
6941
}
6942
}

Return to bug 149751