langtools/test/tools/javac/annotations/typeAnnotations/failures/target/DotClass.java
changeset 15385 ee1eebe7e210
child 15557 3e211bbf4094
equal deleted inserted replaced
15384:5a8d00abf076 15385:ee1eebe7e210
       
     1 import static java.lang.annotation.ElementType.TYPE;
       
     2 import static java.lang.annotation.ElementType.TYPE_PARAMETER;
       
     3 import static java.lang.annotation.ElementType.TYPE_USE;
       
     4 
       
     5 import java.lang.annotation.Retention;
       
     6 import java.lang.annotation.RetentionPolicy;
       
     7 import java.lang.annotation.Target;
       
     8 
       
     9 /*
       
    10  * Copyright (c) 2009 Oracle and/or its affiliates. All rights reserved.
       
    11  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
    12  *
       
    13  * This code is free software; you can redistribute it and/or modify it
       
    14  * under the terms of the GNU General Public License version 2 only, as
       
    15  * published by the Free Software Foundation.
       
    16  *
       
    17  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    18  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    19  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    20  * version 2 for more details (a copy is included in the LICENSE file that
       
    21  * accompanied this code).
       
    22  *
       
    23  * You should have received a copy of the GNU General Public License version
       
    24  * 2 along with this work; if not, write to the Free Software Foundation,
       
    25  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    26  *
       
    27  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    28  * or visit www.oracle.com if you need additional information or have any
       
    29  * questions.
       
    30  */
       
    31 
       
    32 /*
       
    33  * @test
       
    34  * @summary Class literals are not type uses and cannot be annotated
       
    35  * @author Werner Dietl
       
    36  * @compile/fail/ref=DotClass.out -XDrawDiagnostics DotClass.java
       
    37  */
       
    38 
       
    39 @Target({TYPE_USE, TYPE_PARAMETER, TYPE})
       
    40 @Retention(RetentionPolicy.RUNTIME)
       
    41 @interface A {}
       
    42 
       
    43 @interface B { int value(); }
       
    44 
       
    45 class T0x1E {
       
    46     void m0x1E() {
       
    47         Class<Object> c = @A Object.class;
       
    48     }
       
    49 
       
    50     Class<?> c = @A String.class;
       
    51 
       
    52     Class<? extends @A String> as = @A String.class;
       
    53 }
       
    54 
       
    55 class ClassLiterals {
       
    56     public static void main(String[] args) {
       
    57         if (String.class != @A String.class) throw new Error();
       
    58         if (@A int.class != int.class) throw new Error();
       
    59         if (@A int.class != Integer.TYPE) throw new Error();
       
    60         if (@A int @B(0) [].class != int[].class) throw new Error();
       
    61 
       
    62         if (String[].class != @A String[].class) throw new Error();
       
    63         if (String[].class != String @A [].class) throw new Error();
       
    64         if (@A int[].class != int[].class) throw new Error();
       
    65         if (@A int @B(0) [].class != int[].class) throw new Error();
       
    66     }
       
    67 
       
    68     Object classLit1 = @A String @C [] @B(0) [].class;
       
    69     Object classLit2 = @A String @C []       [].class;
       
    70     Object classLit3 = @A String    [] @B(0) [].class;
       
    71     Object classLit4 =    String    [] @B(0) [].class;
       
    72     Object classLit5 =    String @C []       [].class;
       
    73     Object classLit6 =    String    []       [].class;
       
    74 }