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