1 /* |
|
2 * Copyright (c) 2004, 2008, 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 /* |
|
26 * @test |
|
27 * @bug 4853450 5014539 |
|
28 * @summary Tests AnnotationMirror and AnnotationValue methods. |
|
29 * @library ../../lib |
|
30 * @compile -source 1.5 AnnoMirror.java |
|
31 * @run main/othervm AnnoMirror |
|
32 */ |
|
33 |
|
34 |
|
35 import java.util.*; |
|
36 import com.sun.mirror.declaration.*; |
|
37 import com.sun.mirror.type.*; |
|
38 |
|
39 |
|
40 public class AnnoMirror extends Tester { |
|
41 |
|
42 public static void main(String[] args) { |
|
43 (new AnnoMirror()).run(); |
|
44 } |
|
45 |
|
46 |
|
47 @Test(result={"AT1"}) |
|
48 @AT1 |
|
49 AnnotationType getAnnotationType() { |
|
50 AnnotationMirror anno = getAnno("getAnnotationType", "AT1"); |
|
51 return anno.getAnnotationType(); |
|
52 } |
|
53 |
|
54 @Test(result={}) |
|
55 @AT1 |
|
56 Set getElementValuesNone() { |
|
57 AnnotationMirror anno = getAnno("getElementValuesNone", "AT1"); |
|
58 return anno.getElementValues().entrySet(); |
|
59 } |
|
60 |
|
61 |
|
62 // The seemingly out-of-place parens in the following "result" |
|
63 // entry are needed due to the shortcut of having the test return |
|
64 // the entry set directly. |
|
65 @Test(result={"i()=2", |
|
66 "b()=true", |
|
67 "k()=java.lang.Boolean.class", |
|
68 "a()=@AT1"}) |
|
69 @AT2(i = 1+1, |
|
70 b = true, |
|
71 k = Boolean.class, |
|
72 a = @AT1) |
|
73 Set getElementValues() { |
|
74 AnnotationMirror anno = getAnno("getElementValues", "AT2"); |
|
75 return anno.getElementValues().entrySet(); |
|
76 } |
|
77 |
|
78 @Test(result={"@AT1(\"zax\")", |
|
79 "@AT2(i=2, b=true, k=java.lang.Boolean.class, a=@AT1)", |
|
80 "@AT3(arr={1})", |
|
81 "@AT4({2, 3, 4})"}) |
|
82 Collection<AnnotationMirror> toStringTests() { |
|
83 for (MethodDeclaration m : thisClassDecl.getMethods()) { |
|
84 if (m.getSimpleName().equals("toStringTestsHelper")) { |
|
85 return m.getAnnotationMirrors(); |
|
86 } |
|
87 } |
|
88 throw new AssertionError(); |
|
89 } |
|
90 |
|
91 @AT1("zax") |
|
92 @AT2(i = 1+1, |
|
93 b = true, |
|
94 k = Boolean.class, |
|
95 a = @AT1) |
|
96 @AT3(arr={1}) |
|
97 @AT4({2,3,4}) |
|
98 private void toStringTestsHelper() { |
|
99 } |
|
100 } |
|
101 |
|
102 |
|
103 /* |
|
104 * Annotations used for testing. |
|
105 */ |
|
106 |
|
107 @interface AT1 { |
|
108 String value() default ""; |
|
109 } |
|
110 |
|
111 @interface AT2 { |
|
112 int i(); |
|
113 boolean b(); |
|
114 Class k(); |
|
115 AT1 a(); |
|
116 } |
|
117 |
|
118 @interface AT3 { |
|
119 int[] arr(); |
|
120 } |
|
121 |
|
122 @interface AT4 { |
|
123 int[] value(); |
|
124 } |
|