test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateScoping.java

Tue, 15 Oct 2013 15:57:13 -0700

author
jjg
date
Tue, 15 Oct 2013 15:57:13 -0700
changeset 2134
b0c086cd4520
parent 0
959103a6100f
permissions
-rw-r--r--

8026564: import changes from type-annotations forest
Reviewed-by: jjg
Contributed-by: wdietl@gmail.com, steve.sides@oracle.com

     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  */
     9 import java.util.List;
    10 import java.util.ArrayList;
    12 import java.lang.annotation.*;
    14 @Target({ElementType.TYPE_USE})
    15 @interface TA {}
    16 @Target({ElementType.TYPE_USE})
    17 @interface TA2 {}
    19 @Target({ElementType.FIELD})
    20 @interface DA {}
    21 @Target({ElementType.FIELD})
    22 @interface DA2 {}
    24 @Target({ElementType.TYPE_USE, ElementType.FIELD})
    25 @interface DTA {}
    26 @Target({ElementType.TYPE_USE, ElementType.FIELD})
    27 @interface DTA2 {}
    29 class Test {
    30     static class Outer {
    31         static class SInner {}
    32     }
    34     // Legal
    35     List<Outer. @TA SInner> li;
    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>();
    46     // Illegal: @TA is only a type-use annotation
    47     @TA java.lang.Object f1;
    49     // Legal: @DA is only a declaration annotation
    50     @DA java.lang.Object f2;
    52     // Legal: @DTA is both a type-use and declaration annotation
    53     @DTA java.lang.Object f3;
    55     // Illegal: @TA and @TA2 are only type-use annotations
    56     @DTA @DA @TA @DA2 @TA2 java.lang.Object f4;
    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;
    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;
    68     // Illegal: Can't find class "lang".
    69     // Would a different error message be desirable?
    70     java. @TA lang.Object f7;
    71 }

mercurial