test/tools/javac/annotations/typeAnnotations/newlocations/RepeatingTypeAnnotations.java

Thu, 31 Jan 2013 12:16:03 -0800

author
darcy
date
Thu, 31 Jan 2013 12:16:03 -0800
changeset 1531
8e4c22acebeb
parent 1521
71f35e4b93a5
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8007313: Remove use of {ContainerFor/ContainedBy} from langtools
Reviewed-by: jjg

     1 /*
     2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 import java.lang.annotation.*;
    26 /*
    27  * @test
    28  * @bug 8006775
    29  * @summary repeating type annotations are possible
    30  * @author Werner Dietl
    31  * @compile/fail/ref=RepeatingTypeAnnotations.out -XDrawDiagnostics RepeatingTypeAnnotations.java
    32  */
    34 class RepeatingTypeAnnotations {
    35     // Fields
    36     @RTA @RTA Object fr1 = null;
    37     Object fr2 = new @RTA @RTA Object();
    38     // error
    39     Object fs = new @TA @TA Object();
    40     // error
    41     Object ft = new @TA @TA Object();
    42     Object fe = new @TA @TA Object();
    44     // Local variables
    45     Object foo() {
    46         Object o = new @RTA @RTA Object();
    47         o = new @TA @RTA @RTA Object();
    48         o = new @RTA @TA @RTA Object();
    49         // error
    50         o = new @RTA @TA @RTA @TA Object();
    51         // error
    52         return new @TA @TA Object();
    53     }
    55     // Instance creation
    56     Object bar() {
    57         Object o = new @RTA @RTA MyList<@RTA @RTA Object>();
    58         o = new @TA @RTA MyList<@TA @RTA Object>();
    59         o = new @TA @RTA @RTA MyList<@RTA @TA @RTA Object>();
    60         // error
    61         o = new @TA @TA MyList<@RTA @RTA Object>();
    62         // error
    63         o = new @RTA @RTA MyList<@TA @TA Object>();
    64         // error
    65         return new @TA @TA MyList<@RTA @RTA Object>();
    66     }
    68     // More tests
    69     void oneArg() {
    70         Object o = new @RTA @RTA Object();
    71         // error
    72         o = new @TA @TA Object();
    73         o = new @RTA @TA @RTA Object();
    75         o = new MyList<@RTA @RTA Object>();
    76         // error
    77         o = new MyList<@TA @TA Object>();
    78         // error
    79         o = new @TA @TA MyList<@TA @TA Object>();
    80         // error
    81         this.<@TA @TA String>newList();
    83         this.<@RTA @RTA MyList<@RTA @RTA String>>newList();
    84         // error
    85         this.<@TA @TA MyList<@TA @TA String>>newList();
    87         o = (@RTA @RTA MyList<@RTA @RTA Object>) o;
    88         // error
    89         o = (@TA @TA MyList<@TA @TA Object>) o;
    91         this.<@RTA @RTA String, @RTA @RTA Object>newMap();
    92         // error
    93         this.<@TA @TA String, @TA @TA Object>newMap();
    95         this.<@RTA @RTA String @RTA @RTA []>newList();
    96         // error
    97         this.<@TA @TA String @TA @TA []>newList();
    99         this.<@RTA @RTA String @RTA @RTA [] @RTA @RTA [], MyList<@RTA @RTA String> @RTA @RTA []>newMap();
   100         // error
   101         this.<String @TA @TA [] @TA @TA [], MyList<@TA @TA String> @TA @TA []>newMap();
   102     }
   104     static <E> void newList() { }
   105     static <K, V> void newMap() { }
   106 }
   108 class MyList<E> { }
   111 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
   112 @interface TA { }
   114 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
   115 @interface TAs {
   116     TA[] value();
   117 }
   119 @Repeatable(RTAs.class)
   120 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
   121 @interface RTA { }
   123 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
   124 @interface RTAs {
   125     RTA[] value();
   126 }

mercurial