21041
|
1 |
/*
|
|
2 |
* @test /nodynamiccopyright/
|
|
3 |
* @bug 8006733 8006775
|
|
4 |
* @summary Ensure behavior for nested types is correct.
|
|
5 |
* @author Werner Dietl
|
|
6 |
* @compile/fail/ref=CantAnnotateScoping.out -XDrawDiagnostics CantAnnotateScoping.java
|
|
7 |
*/
|
|
8 |
|
|
9 |
import java.util.List;
|
|
10 |
import java.util.ArrayList;
|
|
11 |
|
|
12 |
import java.lang.annotation.*;
|
|
13 |
|
|
14 |
@Target({ElementType.TYPE_USE})
|
|
15 |
@interface TA {}
|
|
16 |
@Target({ElementType.TYPE_USE})
|
|
17 |
@interface TA2 {}
|
|
18 |
|
|
19 |
@Target({ElementType.FIELD})
|
|
20 |
@interface DA {}
|
|
21 |
@Target({ElementType.FIELD})
|
|
22 |
@interface DA2 {}
|
|
23 |
|
|
24 |
@Target({ElementType.TYPE_USE, ElementType.FIELD})
|
|
25 |
@interface DTA {}
|
|
26 |
@Target({ElementType.TYPE_USE, ElementType.FIELD})
|
|
27 |
@interface DTA2 {}
|
|
28 |
|
|
29 |
class Test {
|
|
30 |
static class Outer {
|
|
31 |
static class SInner {}
|
|
32 |
}
|
|
33 |
|
|
34 |
// Legal
|
|
35 |
List<Outer. @TA SInner> li;
|
|
36 |
|
|
37 |
// Illegal
|
|
38 |
@TA Outer.SInner osi;
|
|
39 |
// Illegal
|
|
40 |
List<@TA Outer.SInner> aloi;
|
|
41 |
// Illegal
|
|
42 |
Object o1 = new @TA @DA @TA2 Outer.SInner();
|
|
43 |
// Illegal
|
|
44 |
Object o = new ArrayList<@TA @DA Outer.SInner>();
|
|
45 |
|
|
46 |
// Illegal: @TA is only a type-use annotation
|
|
47 |
@TA java.lang.Object f1;
|
|
48 |
|
|
49 |
// Legal: @DA is only a declaration annotation
|
|
50 |
@DA java.lang.Object f2;
|
|
51 |
|
|
52 |
// Legal: @DTA is both a type-use and declaration annotation
|
|
53 |
@DTA java.lang.Object f3;
|
|
54 |
|
|
55 |
// Illegal: @TA and @TA2 are only type-use annotations
|
|
56 |
@DTA @DA @TA @DA2 @TA2 java.lang.Object f4;
|
|
57 |
|
|
58 |
// Illegal: Do we want one or two messages?
|
|
59 |
// 1: @DA in invalid location
|
|
60 |
// 2: Not finding class "lang"
|
|
61 |
java. @DA lang.Object f5;
|
|
62 |
|
|
63 |
// Illegal: Do we want one or two messages?
|
|
64 |
// 1: @DA in invalid location
|
|
65 |
// 2: Not finding class "XXX"
|
|
66 |
java. @DA XXX.Object f6;
|
|
67 |
|
|
68 |
// Illegal: Can't find class "lang".
|
|
69 |
// Would a different error message be desirable?
|
|
70 |
java. @TA lang.Object f7;
|
|
71 |
}
|