|
1 /* |
|
2 * Copyright (c) 2009 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 */ |
|
23 import java.lang.annotation.*; |
|
24 import static java.lang.annotation.ElementType.*; |
|
25 import static java.lang.annotation.RetentionPolicy.*; |
|
26 |
|
27 import java.util.*; |
|
28 import java.io.*; |
|
29 |
|
30 /* |
|
31 * @test |
|
32 * @summary compiler accepts all values |
|
33 * @author Mahmood Ali |
|
34 * @author Yuri Gaevsky |
|
35 * @compile TargetTypes.java |
|
36 */ |
|
37 |
|
38 @Target({TYPE_USE, TYPE_PARAMETER, TYPE}) |
|
39 @Retention(RetentionPolicy.RUNTIME) |
|
40 @interface A {} |
|
41 |
|
42 /** wildcard bound */ |
|
43 class T0x1C { |
|
44 void m0x1C(List<? extends @A String> lst) {} |
|
45 } |
|
46 |
|
47 /** wildcard bound generic/array */ |
|
48 class T0x1D<T> { |
|
49 void m0x1D(List<? extends @A List<int[]>> lst) {} |
|
50 } |
|
51 |
|
52 /** typecast */ |
|
53 class T0x00 { |
|
54 void m0x00(Long l1) { |
|
55 Object l2 = (@A Long) l1; |
|
56 } |
|
57 } |
|
58 |
|
59 /** typecast generic/array */ |
|
60 class T0x01<T> { |
|
61 void m0x01(List<T> list) { |
|
62 List<T> l = (List<@A T>) list; |
|
63 } |
|
64 } |
|
65 |
|
66 /** instanceof */ |
|
67 class T0x02 { |
|
68 boolean m0x02(String s) { |
|
69 return (s instanceof @A String); |
|
70 } |
|
71 } |
|
72 |
|
73 /** object creation (new) */ |
|
74 class T0x04 { |
|
75 void m0x04() { |
|
76 new @A ArrayList<String>(); |
|
77 } |
|
78 } |
|
79 |
|
80 /** local variable */ |
|
81 class T0x08 { |
|
82 void m0x08() { |
|
83 @A String s = null; |
|
84 } |
|
85 } |
|
86 |
|
87 /** method parameter generic/array */ |
|
88 class T0x0D { |
|
89 void m0x0D(HashMap<@A Object, List<@A List<@A Class>>> s1) {} |
|
90 } |
|
91 |
|
92 /** method receiver */ |
|
93 class T0x06 { |
|
94 void m0x06(@A T0x06 this) {} |
|
95 } |
|
96 |
|
97 /** method return type generic/array */ |
|
98 class T0x0B { |
|
99 Class<@A Object> m0x0B() { return null; } |
|
100 } |
|
101 |
|
102 /** field generic/array */ |
|
103 class T0x0F { |
|
104 HashMap<@A Object, @A Object> c1; |
|
105 } |
|
106 |
|
107 /** method type parameter */ |
|
108 class T0x20<T, U> { |
|
109 <@A T, @A U> void m0x20() {} |
|
110 } |
|
111 |
|
112 /** class type parameter */ |
|
113 class T0x22<@A T, @A U> { |
|
114 } |
|
115 |
|
116 /** class type parameter bound */ |
|
117 class T0x10<T extends @A Object> { |
|
118 } |
|
119 |
|
120 /** method type parameter bound */ |
|
121 class T0x12<T> { |
|
122 <T extends @A Object> void m0x12() {} |
|
123 } |
|
124 |
|
125 /** class type parameter bound generic/array */ |
|
126 class T0x11<T extends List<@A T>> { |
|
127 } |
|
128 |
|
129 |
|
130 /** method type parameter bound generic/array */ |
|
131 class T0x13 { |
|
132 static <T extends Comparable<@A T>> T m0x13() { |
|
133 return null; |
|
134 } |
|
135 } |
|
136 |
|
137 /** class extends/implements generic/array */ |
|
138 class T0x15<T> extends ArrayList<@A T> { |
|
139 } |
|
140 |
|
141 /** type test (instanceof) generic/array */ |
|
142 class T0x03<T> { |
|
143 void m0x03(T typeObj, Object obj) { |
|
144 boolean ok = obj instanceof String @A []; |
|
145 } |
|
146 } |
|
147 |
|
148 /** object creation (new) generic/array */ |
|
149 class T0x05<T> { |
|
150 void m0x05() { |
|
151 new ArrayList<@A T>(); |
|
152 } |
|
153 } |
|
154 |
|
155 /** local variable generic/array */ |
|
156 class T0x09<T> { |
|
157 void g() { |
|
158 List<@A String> l = null; |
|
159 } |
|
160 |
|
161 void a() { |
|
162 String @A [] as = null; |
|
163 } |
|
164 } |
|
165 |
|
166 /** type argument in constructor call generic/array */ |
|
167 class T0x19 { |
|
168 <T> T0x19() {} |
|
169 |
|
170 void g() { |
|
171 new <List<@A String>> T0x19(); |
|
172 } |
|
173 } |
|
174 |
|
175 /** type argument in method call generic/array */ |
|
176 class T0x1B<T> { |
|
177 void m0x1B() { |
|
178 Collections.<T @A []>emptyList(); |
|
179 } |
|
180 } |
|
181 |
|
182 /** type argument in constructor call */ |
|
183 class T0x18<T> { |
|
184 <T> T0x18() {} |
|
185 |
|
186 void m() { |
|
187 new <@A Integer> T0x18(); |
|
188 } |
|
189 } |
|
190 |
|
191 /** type argument in method call */ |
|
192 class T0x1A<T,U> { |
|
193 public static <T, U> T m() { return null; } |
|
194 static void m0x1A() { |
|
195 T0x1A.<@A Integer, @A Short>m(); |
|
196 } |
|
197 } |
|
198 |
|
199 /** class extends/implements */ |
|
200 class T0x14 extends @A Object implements @A Serializable, @A Cloneable { |
|
201 } |
|
202 |
|
203 /** exception type in throws */ |
|
204 class T0x16 { |
|
205 void m0x16() throws @A Exception {} |
|
206 } |