1 /* |
|
2 * Copyright (c) 2014, 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 SyntheticParameters |
|
26 * @bug 8065132 |
|
27 * @summary Test generation of annotations on inner class parameters. |
|
28 * @library /lib/annotations/ |
|
29 * @run main SyntheticParameters |
|
30 */ |
|
31 |
|
32 import annotations.classfile.ClassfileInspector; |
|
33 |
|
34 import java.io.*; |
|
35 import java.lang.annotation.*; |
|
36 |
|
37 import com.sun.tools.classfile.*; |
|
38 |
|
39 public class SyntheticParameters extends ClassfileInspector { |
|
40 |
|
41 private static final String Inner_class = "SyntheticParameters$Inner.class"; |
|
42 private static final String Foo_class = "SyntheticParameters$Foo.class"; |
|
43 private static final Expected Inner_expected = |
|
44 new Expected("SyntheticParameters$Inner", |
|
45 null, |
|
46 null, |
|
47 new ExpectedParameterAnnotation[] { |
|
48 (ExpectedParameterAnnotation) |
|
49 // Assert there is no annotation on the |
|
50 // this$0 parameter. |
|
51 new ExpectedParameterAnnotation( |
|
52 "<init>", |
|
53 0, |
|
54 "A", |
|
55 true, |
|
56 0), |
|
57 (ExpectedParameterAnnotation) |
|
58 // Assert there is an annotation on the |
|
59 // first parameter. |
|
60 new ExpectedParameterAnnotation( |
|
61 "<init>", |
|
62 1, |
|
63 "A", |
|
64 true, |
|
65 1), |
|
66 (ExpectedParameterAnnotation) |
|
67 new ExpectedParameterAnnotation( |
|
68 "foo", |
|
69 0, |
|
70 "A", |
|
71 true, |
|
72 1), |
|
73 (ExpectedParameterAnnotation) |
|
74 new ExpectedParameterAnnotation( |
|
75 "foo", |
|
76 1, |
|
77 "A", |
|
78 true, |
|
79 0), |
|
80 (ExpectedParameterAnnotation) |
|
81 // Assert there is no annotation on the |
|
82 // this$0 parameter. |
|
83 new ExpectedParameterAnnotation( |
|
84 "<init>", |
|
85 0, |
|
86 "B", |
|
87 false, |
|
88 0), |
|
89 (ExpectedParameterAnnotation) |
|
90 // Assert there is an annotation on the |
|
91 // first parameter. |
|
92 new ExpectedParameterAnnotation( |
|
93 "<init>", |
|
94 1, |
|
95 "B", |
|
96 false, |
|
97 1), |
|
98 (ExpectedParameterAnnotation) |
|
99 new ExpectedParameterAnnotation( |
|
100 "foo", |
|
101 0, |
|
102 "B", |
|
103 false, |
|
104 1), |
|
105 (ExpectedParameterAnnotation) |
|
106 new ExpectedParameterAnnotation( |
|
107 "foo", |
|
108 1, |
|
109 "B", |
|
110 false, |
|
111 0) |
|
112 }, |
|
113 null); |
|
114 private static final Expected Foo_expected = |
|
115 new Expected("SyntheticParameters$Foo", |
|
116 null, |
|
117 null, |
|
118 new ExpectedParameterAnnotation[] { |
|
119 (ExpectedParameterAnnotation) |
|
120 // Assert there is no annotation on the |
|
121 // $enum$name parameter. |
|
122 new ExpectedParameterAnnotation( |
|
123 "<init>", |
|
124 0, |
|
125 "A", |
|
126 true, |
|
127 0), |
|
128 (ExpectedParameterAnnotation) |
|
129 // Assert there is no annotation on the |
|
130 // $enum$ordinal parameter. |
|
131 new ExpectedParameterAnnotation( |
|
132 "<init>", |
|
133 1, |
|
134 "A", |
|
135 true, |
|
136 0), |
|
137 (ExpectedParameterAnnotation) |
|
138 // Assert there is an annotation on the |
|
139 // first parameter. |
|
140 new ExpectedParameterAnnotation( |
|
141 "<init>", |
|
142 2, |
|
143 "A", |
|
144 true, |
|
145 1), |
|
146 (ExpectedParameterAnnotation) |
|
147 // Assert there is no annotation on the |
|
148 // $enum$name parameter. |
|
149 new ExpectedParameterAnnotation( |
|
150 "<init>", |
|
151 0, |
|
152 "B", |
|
153 false, |
|
154 0), |
|
155 (ExpectedParameterAnnotation) |
|
156 // Assert there is no annotation on the |
|
157 // $enum$ordinal parameter. |
|
158 new ExpectedParameterAnnotation( |
|
159 "<init>", |
|
160 1, |
|
161 "B", |
|
162 false, |
|
163 0), |
|
164 (ExpectedParameterAnnotation) |
|
165 // Assert there is an annotation on the |
|
166 // first parameter. |
|
167 new ExpectedParameterAnnotation( |
|
168 "<init>", |
|
169 2, |
|
170 "B", |
|
171 false, |
|
172 1) |
|
173 }, |
|
174 null); |
|
175 |
|
176 public static void main(String... args) throws Exception { |
|
177 new SyntheticParameters().run( |
|
178 new ClassFile[] { getClassFile(Inner_class, Inner.class), |
|
179 getClassFile(Foo_class, Foo.class) }, |
|
180 new Expected[] { Inner_expected, Foo_expected }); |
|
181 } |
|
182 |
|
183 public class Inner { |
|
184 public Inner(@A @B int a) {} |
|
185 public void foo(@A @B int a, int b) {} |
|
186 } |
|
187 |
|
188 public static enum Foo { |
|
189 ONE(null); |
|
190 Foo(@A @B Object a) {} |
|
191 } |
|
192 } |
|
193 |
|
194 @Retention(RetentionPolicy.RUNTIME) |
|
195 @interface A {} |
|
196 |
|
197 @Retention(RetentionPolicy.CLASS) |
|
198 @interface B {} |
|