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