1 /*
2 * Copyright (c) 2013, 2015, 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
24 /*
25 * @test
26 * @bug 8004698 8007073 8022343 8054304 8058595
27 * @summary Unit test for type annotations
28 */
29
30 import java.util.*;
31 import java.lang.annotation.*;
32 import java.lang.reflect.*;
33 import java.io.Serializable;
34
35 public class TypeAnnotationReflection {
36 public static void main(String[] args) throws Exception {
37 testSuper();
38 testInterfaces();
39 testReturnType();
40 testNested();
41 testArray();
42 testRunException();
43 testClassTypeVarBounds();
44 testMethodTypeVarBounds();
45 testFields();
46 testClassTypeVar();
47 testMethodTypeVar();
48 testParameterizedType();
49 testNestedParameterizedType();
50 testWildcardType();
51 testParameterTypes();
52 testParameterType();
53 }
54
55 private static void check(boolean b) {
56 if (!b)
57 throw new RuntimeException();
58 }
59
60 private static void testSuper() throws Exception {
61 check(Object.class.getAnnotatedSuperclass() == null);
62 check(Class.class.getAnnotatedSuperclass().getAnnotations().length == 0);
63
64 AnnotatedType a;
65 a = TestClassArray.class.getAnnotatedSuperclass();
66 Annotation[] annos = a.getAnnotations();
67 check(annos.length == 2);
68 check(annos[0].annotationType().equals(TypeAnno.class));
69 check(annos[1].annotationType().equals(TypeAnno2.class));
70 check(((TypeAnno)annos[0]).value().equals("extends"));
71 check(((TypeAnno2)annos[1]).value().equals("extends2"));
72 }
73
74 private static void testInterfaces() throws Exception {
75 AnnotatedType[] as;
76 as = TestClassArray.class.getAnnotatedInterfaces();
77 check(as.length == 3);
78 check(as[1].getAnnotations().length == 0);
79
80 Annotation[] annos;
81 annos = as[0].getAnnotations();
82 check(annos.length == 2);
83 check(annos[0].annotationType().equals(TypeAnno.class));
84 check(annos[1].annotationType().equals(TypeAnno2.class));
85 check(((TypeAnno)annos[0]).value().equals("implements serializable"));
86 check(((TypeAnno2)annos[1]).value().equals("implements2 serializable"));
87
88 annos = as[2].getAnnotations();
89 check(annos.length == 2);
90 check(annos[0].annotationType().equals(TypeAnno.class));
91 check(annos[1].annotationType().equals(TypeAnno2.class));
92 check(((TypeAnno)annos[0]).value().equals("implements cloneable"));
93 check(((TypeAnno2)annos[1]).value().equals("implements2 cloneable"));
94 }
95
96 private static void testReturnType() throws Exception {
97 Method m = TestClassArray.class.getDeclaredMethod("foo", (Class<?>[])null);
98 Annotation[] annos = m.getAnnotatedReturnType().getAnnotations();
99 check(annos.length == 1);
100 check(annos[0].annotationType().equals(TypeAnno.class));
101 check(((TypeAnno)annos[0]).value().equals("return1"));
102 }
103
104 private static void testNested() throws Exception {
105 Method m = TestClassNested.class.getDeclaredMethod("foo", (Class<?>[])null);
106 Annotation[] annos = m.getAnnotatedReturnType().getAnnotations();
107 check(annos.length == 1);
108 check(annos[0].annotationType().equals(TypeAnno.class));
109 check(((TypeAnno)annos[0]).value().equals("array"));
110
111 AnnotatedType t = m.getAnnotatedReturnType();
112 t = ((AnnotatedArrayType)t).getAnnotatedGenericComponentType();
113 annos = t.getAnnotations();
114 check(annos.length == 1);
115 check(annos[0].annotationType().equals(TypeAnno.class));
116 check(((TypeAnno)annos[0]).value().equals("Inner"));
117 }
118
119 private static void testArray() throws Exception {
120 Method m = TestClassArray.class.getDeclaredMethod("foo", (Class<?>[])null);
121 AnnotatedArrayType t = (AnnotatedArrayType) m.getAnnotatedReturnType();
122 Annotation[] annos = t.getAnnotations();
123 check(annos.length == 1);
124 check(annos[0].annotationType().equals(TypeAnno.class));
125 check(((TypeAnno)annos[0]).value().equals("return1"));
126
127 t = (AnnotatedArrayType)t.getAnnotatedGenericComponentType();
128 annos = t.getAnnotations();
129 check(annos.length == 0);
130
131 t = (AnnotatedArrayType)t.getAnnotatedGenericComponentType();
132 annos = t.getAnnotations();
133 check(annos.length == 1);
134 check(annos[0].annotationType().equals(TypeAnno.class));
135 check(((TypeAnno)annos[0]).value().equals("return3"));
136
137 AnnotatedType tt = t.getAnnotatedGenericComponentType();
138 check(!(tt instanceof AnnotatedArrayType));
139 annos = tt.getAnnotations();
140 check(annos.length == 1);
141 check(annos[0].annotationType().equals(TypeAnno.class));
142 check(((TypeAnno)annos[0]).value().equals("return4"));
143 }
144
145 private static void testRunException() throws Exception {
146 Method m = TestClassException.class.getDeclaredMethod("foo", (Class<?>[])null);
147 AnnotatedType[] ts = m.getAnnotatedExceptionTypes();
148 check(ts.length == 3);
149
150 AnnotatedType t;
151 Annotation[] annos;
152 t = ts[0];
153 annos = t.getAnnotations();
154 check(annos.length == 2);
155 check(annos[0].annotationType().equals(TypeAnno.class));
156 check(annos[1].annotationType().equals(TypeAnno2.class));
157 check(((TypeAnno)annos[0]).value().equals("RE"));
158 check(((TypeAnno2)annos[1]).value().equals("RE2"));
159
160 t = ts[1];
161 annos = t.getAnnotations();
162 check(annos.length == 0);
163
164 t = ts[2];
165 annos = t.getAnnotations();
166 check(annos.length == 1);
167 check(annos[0].annotationType().equals(TypeAnno.class));
168 check(((TypeAnno)annos[0]).value().equals("AIOOBE"));
169 }
170
171 private static void testClassTypeVarBounds() throws Exception {
172 Method m = TestClassTypeVarAndField.class.getDeclaredMethod("foo", (Class<?>[])null);
173 AnnotatedType ret = m.getAnnotatedReturnType();
174 Annotation[] annos = ret.getAnnotations();
175 check(annos.length == 2);
176
177 AnnotatedType[] annotatedBounds = ((AnnotatedTypeVariable)ret).getAnnotatedBounds();
178 check(annotatedBounds.length == 2);
179
180 annos = annotatedBounds[0].getAnnotations();
181 check(annos.length == 1);
182 check(annos[0].annotationType().equals(TypeAnno.class));
183 check(((TypeAnno)annos[0]).value().equals("Object1"));
184
185 annos = annotatedBounds[1].getAnnotations();
186 check(annos.length == 2);
187 check(annos[0].annotationType().equals(TypeAnno.class));
188 check(annos[1].annotationType().equals(TypeAnno2.class));
189 check(((TypeAnno)annos[0]).value().equals("Runnable1"));
190 check(((TypeAnno2)annos[1]).value().equals("Runnable2"));
191 }
192
193 private static void testMethodTypeVarBounds() throws Exception {
194 Method m2 = TestClassTypeVarAndField.class.getDeclaredMethod("foo2", (Class<?>[])null);
195 AnnotatedType ret2 = m2.getAnnotatedReturnType();
196 AnnotatedType[] annotatedBounds2 = ((AnnotatedTypeVariable)ret2).getAnnotatedBounds();
197 check(annotatedBounds2.length == 1);
198
199 Annotation[] annos = annotatedBounds2[0].getAnnotations();
200 check(annos.length == 1);
201 check(annos[0].annotationType().equals(TypeAnno.class));
202 check(((TypeAnno)annos[0]).value().equals("M Runnable"));
203
204 // Check that AnnotatedTypeVariable.getAnnotatedBounds() returns jlO for a naked
205 // type variable (i.e no bounds, no annotations)
206 Method m4 = TestClassTypeVarAndField.class.getDeclaredMethod("foo4", (Class<?>[])null);
207 AnnotatedType ret4 = m4.getAnnotatedReturnType();
208 AnnotatedType[] annotatedBounds4 = ((AnnotatedTypeVariable)ret4).getAnnotatedBounds();
209 check(annotatedBounds4.length == 1);
210
211 annos = annotatedBounds4[0].getAnnotations();
212 check(annos.length == 0);
213 check(annotatedBounds4[0].getType().equals(Object.class));
214 }
215
216 private static void testFields() throws Exception {
217 Field f1 = TestClassTypeVarAndField.class.getDeclaredField("field1");
218 AnnotatedType at;
219 Annotation[] annos;
220
221 at = f1.getAnnotatedType();
222 annos = at.getAnnotations();
223 check(annos.length == 2);
224 check(annos[0].annotationType().equals(TypeAnno.class));
225 check(annos[1].annotationType().equals(TypeAnno2.class));
226 check(((TypeAnno)annos[0]).value().equals("T1 field"));
227 check(((TypeAnno2)annos[1]).value().equals("T2 field"));
228
229 Field f2 = TestClassTypeVarAndField.class.getDeclaredField("field2");
230 at = f2.getAnnotatedType();
231 annos = at.getAnnotations();
232 check(annos.length == 0);
233
234 Field f3 = TestClassTypeVarAndField.class.getDeclaredField("field3");
235 at = f3.getAnnotatedType();
236 annos = at.getAnnotations();
237 check(annos.length == 1);
238 check(annos[0].annotationType().equals(TypeAnno.class));
239 check(((TypeAnno)annos[0]).value().equals("Object field"));
240 }
241
242 private static void testClassTypeVar() throws Exception {
243 TypeVariable[] typeVars = TestClassTypeVarAndField.class.getTypeParameters();
244 Annotation[] annos;
245 check(typeVars.length == 3);
246
247 // First TypeVar
248 AnnotatedType[] annotatedBounds = typeVars[0].getAnnotatedBounds();
249 check(annotatedBounds.length == 2);
250
251 annos = annotatedBounds[0].getAnnotations();
252 check(annos.length == 1);
253 check(annos[0].annotationType().equals(TypeAnno.class));
254 check(((TypeAnno)annos[0]).value().equals("Object1"));
255
256 annos = annotatedBounds[1].getAnnotations();
257 check(annos.length == 2);
258 check(annos[0].annotationType().equals(TypeAnno.class));
259 check(annos[1].annotationType().equals(TypeAnno2.class));
260 check(((TypeAnno)annos[0]).value().equals("Runnable1"));
261 check(((TypeAnno2)annos[1]).value().equals("Runnable2"));
262
263 // second TypeVar regular anno
264 Annotation[] regularAnnos = typeVars[1].getAnnotations();
265 check(regularAnnos.length == 1);
266 check(typeVars[1].getAnnotation(TypeAnno.class).value().equals("EE"));
267
268 // second TypeVar
269 annotatedBounds = typeVars[1].getAnnotatedBounds();
270 check(annotatedBounds.length == 1);
271
272 annos = annotatedBounds[0].getAnnotations();
273 check(annos.length == 1);
274 check(annos[0].annotationType().equals(TypeAnno2.class));
275 check(((TypeAnno2)annos[0]).value().equals("EEBound"));
276
277 // third Typevar V declared without explicit bounds should see jlO as its bound.
278 annotatedBounds = typeVars[2].getAnnotatedBounds();
279 check(annotatedBounds.length == 1);
280
281 annos = annotatedBounds[0].getAnnotations();
282 check(annos.length == 0);
283 check(annotatedBounds[0].getType().equals(Object.class));
284 }
285
286 private static void testMethodTypeVar() throws Exception {
287 Method m2 = TestClassTypeVarAndField.class.getDeclaredMethod("foo2", (Class<?>[])null);
288 TypeVariable[] t = m2.getTypeParameters();
289 check(t.length == 1);
290 Annotation[] annos = t[0].getAnnotations();
291 check(annos.length == 0);
292
293 AnnotatedType[] annotatedBounds2 = t[0].getAnnotatedBounds();
294 check(annotatedBounds2.length == 1);
295
296 annos = annotatedBounds2[0].getAnnotations();
297 check(annos.length == 1);
298 check(annos[0].annotationType().equals(TypeAnno.class));
299 check(((TypeAnno)annos[0]).value().equals("M Runnable"));
300
301 // Second method
302 m2 = TestClassTypeVarAndField.class.getDeclaredMethod("foo3", (Class<?>[])null);
303 t = m2.getTypeParameters();
304 check(t.length == 2);
305 annos = t[0].getAnnotations();
306 check(annos.length == 1);
307 check(annos[0].annotationType().equals(TypeAnno.class));
308 check(((TypeAnno)annos[0]).value().equals("K"));
309
310 annotatedBounds2 = t[0].getAnnotatedBounds();
311 check(annotatedBounds2.length == 1);
312
313 annos = annotatedBounds2[0].getAnnotations();
314 check(annos.length == 0);
315
316 // for the naked type variable L of foo3, we should see jlO as its bound.
317 annotatedBounds2 = t[1].getAnnotatedBounds();
318 check(annotatedBounds2.length == 1);
319 check(annotatedBounds2[0].getType().equals(Object.class));
320
321 annos = annotatedBounds2[0].getAnnotations();
322 check(annos.length == 0);
323 }
324
325 private static void testParameterizedType() {
326 // Base
327 AnnotatedType[] as;
328 as = TestParameterizedType.class.getAnnotatedInterfaces();
329 check(as.length == 1);
330 check(as[0].getAnnotations().length == 1);
331 check(as[0].getAnnotation(TypeAnno.class).value().equals("M"));
332
333 Annotation[] annos;
334 as = ((AnnotatedParameterizedType)as[0]).getAnnotatedActualTypeArguments();
335 check(as.length == 2);
336 annos = as[0].getAnnotations();
337 check(annos.length == 1);
338 check(as[0].getAnnotation(TypeAnno.class).value().equals("S"));
339 check(as[0].getAnnotation(TypeAnno2.class) == null);
340
341 annos = as[1].getAnnotations();
342 check(annos.length == 2);
343 check(((TypeAnno)annos[0]).value().equals("I"));
344 check(as[1].getAnnotation(TypeAnno2.class).value().equals("I2"));
345 }
346
347 private static void testNestedParameterizedType() throws Exception {
348 Method m = TestParameterizedType.class.getDeclaredMethod("foo2", (Class<?>[])null);
349 AnnotatedType ret = m.getAnnotatedReturnType();
350 Annotation[] annos;
351 annos = ret.getAnnotations();
352 check(annos.length == 1);
353 check(((TypeAnno)annos[0]).value().equals("I"));
354
355 AnnotatedType[] args = ((AnnotatedParameterizedType)ret).getAnnotatedActualTypeArguments();
356 check(args.length == 1);
357 annos = args[0].getAnnotations();
358 check(annos.length == 2);
359 check(((TypeAnno)annos[0]).value().equals("I1"));
360 check(args[0].getAnnotation(TypeAnno2.class).value().equals("I2"));
361 }
362
363 private static void testWildcardType() throws Exception {
364 Method m = TestWildcardType.class.getDeclaredMethod("foo", (Class<?>[])null);
365 AnnotatedType ret = m.getAnnotatedReturnType();
366 AnnotatedType[] t;
367 t = ((AnnotatedParameterizedType)ret).getAnnotatedActualTypeArguments();
368 check(t.length == 1);
369 ret = t[0];
370
371 Field f = TestWildcardType.class.getDeclaredField("f1");
372 AnnotatedWildcardType w = (AnnotatedWildcardType)((AnnotatedParameterizedType)f
373 .getAnnotatedType()).getAnnotatedActualTypeArguments()[0];
374 t = w.getAnnotatedLowerBounds();
375 check(t.length == 0);
376 t = w.getAnnotatedUpperBounds();
377 check(t.length == 1);
378 Annotation[] annos;
379 annos = t[0].getAnnotations();
380 check(annos.length == 1);
381 check(((TypeAnno)annos[0]).value().equals("2"));
382
383 f = TestWildcardType.class.getDeclaredField("f2");
384 w = (AnnotatedWildcardType)((AnnotatedParameterizedType)f
385 .getAnnotatedType()).getAnnotatedActualTypeArguments()[0];
386 t = w.getAnnotatedUpperBounds();
387 check(t.length == 1);
388 check(t[0].getType().equals(Object.class));
389 annos = t[0].getAnnotations();
390 check(annos.length == 0);
391 t = w.getAnnotatedLowerBounds();
392 check(t.length == 1);
393
394 // for an unbounded wildcard, we should see jlO as its upperbound and null type as its lower bound.
395 f = TestWildcardType.class.getDeclaredField("f3");
396 w = (AnnotatedWildcardType)((AnnotatedParameterizedType)f
397 .getAnnotatedType()).getAnnotatedActualTypeArguments()[0];
398 t = w.getAnnotatedUpperBounds();
399 check(t.length == 1);
400 check(t[0].getType().equals(Object.class));
401 annos = t[0].getAnnotations();
402 check(annos.length == 0);
403 t = w.getAnnotatedLowerBounds();
404 check(t.length == 0);
405 }
406
407 private static void testParameterTypes() throws Exception {
408 // NO PARAMS
409 Method m = Params.class.getDeclaredMethod("noParams", (Class<?>[])null);
410 AnnotatedType[] t = m.getAnnotatedParameterTypes();
411 check(t.length == 0);
412
413 // ONLY ANNOTATED PARAM TYPES
414 Class[] argsArr = {String.class, String.class, String.class};
415 m = Params.class.getDeclaredMethod("onlyAnnotated", (Class<?>[])argsArr);
416 t = m.getAnnotatedParameterTypes();
417 check(t.length == 3);
418
419 check(t[0].getAnnotations().length == 1);
420 check(t[0].getAnnotation(TypeAnno.class) != null);
421 check(t[0].getAnnotationsByType(TypeAnno.class)[0].value().equals("1"));
422
423 check(t[1].getAnnotations().length == 1);
424 check(t[1].getAnnotation(TypeAnno.class) != null);
425 check(t[1].getAnnotationsByType(TypeAnno.class)[0].value().equals("2"));
426
427 check(t[2].getAnnotations().length == 2);
428 check(t[2].getAnnotations()[0].annotationType().equals(TypeAnno.class));
429 check(t[2].getAnnotation(TypeAnno.class) != null);
430 check(t[2].getAnnotation(TypeAnno2.class) != null);
431 check(t[2].getAnnotationsByType(TypeAnno.class)[0].value().equals("3a"));
432 check(t[2].getAnnotationsByType(TypeAnno2.class)[0].value().equals("3b"));
433
434 // MIXED ANNOTATED PARAM TYPES
435 m = Params.class.getDeclaredMethod("mixed", (Class<?>[])argsArr);
436 t = m.getAnnotatedParameterTypes();
437 check(t.length == 3);
438
439 check(t[0].getAnnotations().length == 1);
440 check(t[0].getAnnotation(TypeAnno.class) != null);
441 check(t[0].getAnnotationsByType(TypeAnno.class)[0].value().equals("1"));
442
443 check(t[1].getAnnotations().length == 0);
444 check(t[1].getAnnotation(TypeAnno.class) == null);
445 check(t[1].getAnnotation(TypeAnno2.class) == null);
446
447 check(t[2].getAnnotations().length == 2);
448 check(t[2].getAnnotations()[0].annotationType().equals(TypeAnno.class));
449 check(t[2].getAnnotation(TypeAnno.class) != null);
450 check(t[2].getAnnotation(TypeAnno2.class) != null);
451 check(t[2].getAnnotationsByType(TypeAnno.class)[0].value().equals("3a"));
452 check(t[2].getAnnotationsByType(TypeAnno2.class)[0].value().equals("3b"));
453
454 // NO ANNOTATED PARAM TYPES
455 m = Params.class.getDeclaredMethod("unAnnotated", (Class<?>[])argsArr);
456 t = m.getAnnotatedParameterTypes();
457 check(t.length == 3);
458
459 check(t[0].getAnnotations().length == 0);
460 check(t[0].getAnnotation(TypeAnno.class) == null);
461 check(t[0].getAnnotation(TypeAnno2.class) == null);
462
463 check(t[1].getAnnotations().length == 0);
464 check(t[1].getAnnotation(TypeAnno.class) == null);
465 check(t[1].getAnnotation(TypeAnno2.class) == null);
466
467 check(t[2].getAnnotations().length == 0);
468 check(t[2].getAnnotation(TypeAnno.class) == null);
469 check(t[2].getAnnotation(TypeAnno2.class) == null);
470 }
471
472 private static void testParameterType() throws Exception {
473 // NO PARAMS
474 Method m = Params.class.getDeclaredMethod("noParams", (Class<?>[])null);
475 Parameter[] p = m.getParameters();
476 check(p.length == 0);
477
478 // ONLY ANNOTATED PARAM TYPES
479 Class[] argsArr = {String.class, String.class, String.class};
480 m = Params.class.getDeclaredMethod("onlyAnnotated", (Class<?>[])argsArr);
481 p = m.getParameters();
482 check(p.length == 3);
483 AnnotatedType t0 = p[0].getAnnotatedType();
484 AnnotatedType t1 = p[1].getAnnotatedType();
485 AnnotatedType t2 = p[2].getAnnotatedType();
486
487 check(t0.getAnnotations().length == 1);
488 check(t0.getAnnotation(TypeAnno.class) != null);
489 check(t0.getAnnotationsByType(TypeAnno.class)[0].value().equals("1"));
490
491 check(t1.getAnnotations().length == 1);
492 check(t1.getAnnotation(TypeAnno.class) != null);
493 check(t1.getAnnotationsByType(TypeAnno.class)[0].value().equals("2"));
494
495 check(t2.getAnnotations().length == 2);
496 check(t2.getAnnotations()[0].annotationType().equals(TypeAnno.class));
497 check(t2.getAnnotation(TypeAnno.class) != null);
498 check(t2.getAnnotation(TypeAnno2.class) != null);
499 check(t2.getAnnotationsByType(TypeAnno.class)[0].value().equals("3a"));
500 check(t2.getAnnotationsByType(TypeAnno2.class)[0].value().equals("3b"));
501
502 // MIXED ANNOTATED PARAM TYPES
503 m = Params.class.getDeclaredMethod("mixed", (Class<?>[])argsArr);
504 p = m.getParameters();
505 check(p.length == 3);
506
507 t0 = p[0].getAnnotatedType();
508 t1 = p[1].getAnnotatedType();
509 t2 = p[2].getAnnotatedType();
510
511 check(t0.getAnnotations().length == 1);
512 check(t0.getAnnotation(TypeAnno.class) != null);
513 check(t0.getAnnotationsByType(TypeAnno.class)[0].value().equals("1"));
514
515 check(t1.getAnnotations().length == 0);
516 check(t1.getAnnotation(TypeAnno.class) == null);
517 check(t1.getAnnotation(TypeAnno2.class) == null);
518
519 check(t2.getAnnotations().length == 2);
520 check(t2.getAnnotations()[0].annotationType().equals(TypeAnno.class));
521 check(t2.getAnnotation(TypeAnno.class) != null);
522 check(t2.getAnnotation(TypeAnno2.class) != null);
523 check(t2.getAnnotationsByType(TypeAnno.class)[0].value().equals("3a"));
524 check(t2.getAnnotationsByType(TypeAnno2.class)[0].value().equals("3b"));
525
526 // NO ANNOTATED PARAM TYPES
527 m = Params.class.getDeclaredMethod("unAnnotated", (Class<?>[])argsArr);
528 p = m.getParameters();
529 check(p.length == 3);
530
531 t0 = p[0].getAnnotatedType();
532 t1 = p[1].getAnnotatedType();
533 t2 = p[2].getAnnotatedType();
534
535 check(t0.getAnnotations().length == 0);
536 check(t0.getAnnotation(TypeAnno.class) == null);
537 check(t0.getAnnotation(TypeAnno2.class) == null);
538
539 check(t1.getAnnotations().length == 0);
540 check(t1.getAnnotation(TypeAnno.class) == null);
541 check(t1.getAnnotation(TypeAnno2.class) == null);
542
543 check(t2.getAnnotations().length == 0);
544 check(t2.getAnnotation(TypeAnno.class) == null);
545 check(t2.getAnnotation(TypeAnno2.class) == null);
546 }
547 }
548
549 class Params {
550 public void noParams() {}
551 public void onlyAnnotated(@TypeAnno("1") String s1, @TypeAnno("2") String s2, @TypeAnno("3a") @TypeAnno2("3b") String s3) {}
552 public void mixed(@TypeAnno("1") String s1, String s2, @TypeAnno("3a") @TypeAnno2("3b") String s3) {}
553 public void unAnnotated(String s1, String s2, String s3) {}
554 }
555
556 abstract class TestWildcardType {
557 public <T> List<? super T> foo() { return null;}
558 public Class<@TypeAnno("1") ? extends @TypeAnno("2") Annotation> f1;
559 public Class<@TypeAnno("3") ? super @TypeAnno("4") Annotation> f2;
560 public Class<@TypeAnno("5") ?> f3;
561 }
562
563 abstract class TestParameterizedType implements @TypeAnno("M") Map<@TypeAnno("S")String, @TypeAnno("I") @TypeAnno2("I2")Integer> {
564 public ParameterizedOuter<String>.ParameterizedInner<Integer> foo() {return null;}
565 public @TypeAnno("O") ParameterizedOuter<@TypeAnno("S1") @TypeAnno2("S2") String>.
566 @TypeAnno("I") ParameterizedInner<@TypeAnno("I1") @TypeAnno2("I2")Integer> foo2() {
567 return null;
568 }
569 }
570
571 class ParameterizedOuter <T> {
572 class ParameterizedInner <U> {}
573 }
574
575 abstract class TestClassArray extends @TypeAnno("extends") @TypeAnno2("extends2") Object
576 implements @TypeAnno("implements serializable") @TypeAnno2("implements2 serializable") Serializable,
577 Readable,
578 @TypeAnno("implements cloneable") @TypeAnno2("implements2 cloneable") Cloneable {
579 public @TypeAnno("return4") Object @TypeAnno("return1") [][] @TypeAnno("return3")[] foo() { return null; }
580 }
581
582 abstract class TestClassNested {
583 public @TypeAnno("Outer") Outer.@TypeAnno("Inner")Inner @TypeAnno("array")[] foo() { return null; }
584 }
585
586 class Outer {
587 class Inner {
588 }
589 }
590
591 abstract class TestClassException {
592 public Object foo() throws @TypeAnno("RE") @TypeAnno2("RE2") RuntimeException,
593 NullPointerException,
594 @TypeAnno("AIOOBE") ArrayIndexOutOfBoundsException {
595 return null;
596 }
597 }
598
599 abstract class TestClassTypeVarAndField <T extends @TypeAnno("Object1") Object
600 & @TypeAnno("Runnable1") @TypeAnno2("Runnable2") Runnable,
601 @TypeAnno("EE")EE extends @TypeAnno2("EEBound") Runnable, V > {
602 @TypeAnno("T1 field") @TypeAnno2("T2 field") T field1;
603 T field2;
604 @TypeAnno("Object field") Object field3;
605
606 public @TypeAnno("t1") @TypeAnno2("t2") T foo(){ return null; }
607 public <M extends @TypeAnno("M Runnable") Runnable> M foo2() {return null;}
608 public <@TypeAnno("K") K extends Cloneable, L> K foo3() {return null;}
609 public <L> L foo4() {return null;}
610 }
611
612 @Target(ElementType.TYPE_USE)
613 @Retention(RetentionPolicy.RUNTIME)
614 @interface TypeAnno {
615 String value();
616 }
617
618 @Target(ElementType.TYPE_USE)
619 @Retention(RetentionPolicy.RUNTIME)
620 @interface TypeAnno2 {
621 String value();
622 }
--- EOF ---