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