ClassTypeParam.java revision 2942:08092deced3f
1/*
2 * Copyright (c) 2009, 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
24import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
25
26/*
27 * @test
28 * @bug 8042451
29 * @summary Test population of reference info for class type parameters
30 * @modules jdk.jdeps/com.sun.tools.classfile
31 * @compile -g Driver.java ReferenceInfoUtil.java ClassTypeParam.java
32 * @run main Driver ClassTypeParam
33 */
34public class ClassTypeParam {
35
36    @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER, paramIndex = 0)
37    @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0)
38    @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER, paramIndex = 1)
39    @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0)
40    @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1)
41    public String regularClass1() {
42        return "class %TEST_CLASS_NAME%<@TA K extends @TB Date, @TC V extends @TD Object & @TE Cloneable> { }";
43    }
44
45    @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER, paramIndex = 0)
46    @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0)
47    @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER, paramIndex = 1)
48    @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1)
49    public String regularClass2() {
50        return "class %TEST_CLASS_NAME%<@TA K extends @TB Date, @TC V extends @TE Cloneable> { }";
51    }
52
53    @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1)
54    @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1})
55    @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1)
56    @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0})
57    @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0})
58    public String regularClassParameterized() {
59        return "class %TEST_CLASS_NAME%<K extends @TA Map<String, @TB String>, V extends @TC List<@TD List<@TE Object>>> { }";
60    }
61
62    @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1)
63    @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1})
64    @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1)
65    @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0})
66    @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0})
67    @TADescription(annotation = "TF", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0)
68    @TADescription(annotation = "TG", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0)
69    public String regularClassParameterized2() {
70        return "class %TEST_CLASS_NAME%<K extends @TG Object & @TA Map<String, @TB String>, V extends @TF Object & @TC List<@TD List<@TE Object>>> { }";
71    }
72
73    @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER, paramIndex = 0)
74    @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0)
75    @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER, paramIndex = 1)
76    @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0)
77    @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1)
78    public String abstractClass() {
79        return "abstract class %TEST_CLASS_NAME%<@TA K extends @TB Date, @TC V extends @TD Object & @TE Cloneable> { }";
80    }
81
82    @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1)
83    @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1})
84    @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1)
85    @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0})
86    @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0})
87    @TADescription(annotation = "TF", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0)
88    public String abstractClassParameterized() {
89        return "abstract class %TEST_CLASS_NAME%<K extends @TA Map<String, @TB String>, V extends @TF Object & @TC List<@TD List<@TE Object>>> { }";
90    }
91
92    @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER, paramIndex = 0)
93    @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0)
94    @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER, paramIndex = 1)
95    @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0)
96    @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1)
97    public String regularInterface() {
98        return "interface %TEST_CLASS_NAME%<@TA K extends @TB Date, @TC V extends @TD Object & @TE Cloneable> { }";
99    }
100
101    @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1)
102    @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1})
103    @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1)
104    @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0})
105    @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0})
106    public String regularInterfaceParameterized() {
107        return "interface %TEST_CLASS_NAME%<K extends @TA Map<String, @TB String>, V extends @TC List<@TD List<@TE Object>>> { }";
108    }
109
110    @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1)
111    @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1})
112    @TADescription(annotation = "TC", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1)
113    @TADescription(annotation = "TD", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0})
114    @TADescription(annotation = "TE", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0})
115    @TADescription(annotation = "TF", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0)
116    @TADescription(annotation = "TG", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0)
117    public String regularInterfaceParameterized2() {
118        return "interface %TEST_CLASS_NAME%<K extends @TG Object & @TA Map<String, @TB String>, V extends @TF Object & @TC List<@TD List<@TE Object>>> { }";
119    }
120
121    @TADescription(annotation = "TA", type = METHOD_RETURN)
122    public String useInReturn1() {
123        return "class %TEST_CLASS_NAME%<T> { @TA T m() { throw new RuntimeException(); } }";
124    }
125
126    @TADescription(annotation = "TA", type = METHOD_RETURN, genericLocation = {3, 0})
127    public String useInReturn2() {
128        return "class %TEST_CLASS_NAME%<T> { Class<@TA T> m() { throw new RuntimeException(); } }";
129    }
130
131    @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER,
132            paramIndex = 0, genericLocation = {3, 0})
133    public String useInParam1() {
134        return "class %TEST_CLASS_NAME%<T> { void m(Class<@TA T> p) { throw new RuntimeException(); } }";
135    }
136
137    @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER,
138            paramIndex = 0, genericLocation = {3, 0})
139    public String useInParam2() {
140        return "class %TEST_CLASS_NAME% { void m(Class<@TA Object> p) { throw new RuntimeException(); } }";
141    }
142
143    @TADescription(annotation = "RTAs", type = CLASS_TYPE_PARAMETER, paramIndex = 0)
144    @TADescription(annotation = "RTBs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0)
145    @TADescription(annotation = "RTCs", type = CLASS_TYPE_PARAMETER, paramIndex = 1)
146    @TADescription(annotation = "RTDs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0)
147    @TADescription(annotation = "RTEs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1)
148    public String regularClassRepeatableAnnotation1() {
149        return "class %TEST_CLASS_NAME%<@RTA @RTA K extends @RTB @RTB Date, @RTC @RTC V extends @RTD @RTD Object & @RTE @RTE Cloneable> { }";
150    }
151
152    @TADescription(annotation = "RTAs", type = CLASS_TYPE_PARAMETER, paramIndex = 0)
153    @TADescription(annotation = "RTBs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0)
154    @TADescription(annotation = "RTCs", type = CLASS_TYPE_PARAMETER, paramIndex = 1)
155    @TADescription(annotation = "RTEs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1)
156    public String regularClassRepeatableAnnotation2() {
157        return "class %TEST_CLASS_NAME%<@RTA @RTA K extends @RTB @RTB Date, @RTC @RTC V extends @RTE @RTE Cloneable> { }";
158    }
159
160    @TADescription(annotation = "RTAs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1)
161    @TADescription(annotation = "RTBs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1})
162    @TADescription(annotation = "RTCs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1)
163    @TADescription(annotation = "RTDs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0})
164    @TADescription(annotation = "RTEs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0})
165    public String regularClassParameterizedRepeatableAnnotation() {
166        return "class %TEST_CLASS_NAME%<K extends @RTA @RTA Map<String, @RTB @RTB String>," +
167                " V extends @RTC @RTC List<@RTD @RTD List<@RTE @RTE Object>>> { }";
168    }
169
170    @TADescription(annotation = "RTAs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1)
171    @TADescription(annotation = "RTBs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1})
172    @TADescription(annotation = "RTCs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1)
173    @TADescription(annotation = "RTDs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0})
174    @TADescription(annotation = "RTEs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0})
175    @TADescription(annotation = "RTFs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0)
176    @TADescription(annotation = "RTGs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0)
177    public String regularClassParameterizedRepeatableAnnotation2() {
178        return "class %TEST_CLASS_NAME%<K extends @RTG @RTG Object & @RTA @RTA Map<String, @RTB @RTB String>," +
179                " V extends @RTF @RTF Object & @RTC @RTC List<@RTD @RTD List<@RTE @RTE Object>>> { }";
180    }
181
182    @TADescription(annotation = "RTAs", type = CLASS_TYPE_PARAMETER, paramIndex = 0)
183    @TADescription(annotation = "RTBs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0)
184    @TADescription(annotation = "RTCs", type = CLASS_TYPE_PARAMETER, paramIndex = 1)
185    @TADescription(annotation = "RTDs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0)
186    @TADescription(annotation = "RTEs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1)
187    public String abstractClassRepeatableAnnotation() {
188        return "abstract class %TEST_CLASS_NAME%<@RTA @RTA K extends @RTB @RTB Date," +
189                " @RTC @RTC V extends @RTD @RTD Object & @RTE @RTE Cloneable> { }";
190    }
191
192    @TADescription(annotation = "RTAs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1)
193    @TADescription(annotation = "RTBs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1})
194    @TADescription(annotation = "RTCs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1)
195    @TADescription(annotation = "RTDs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0})
196    @TADescription(annotation = "RTEs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0})
197    @TADescription(annotation = "RTFs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0)
198    public String abstractClassParameterizedRepeatableAnnotation() {
199        return "abstract class %TEST_CLASS_NAME%<K extends @RTA @RTA Map<String, @RTB @RTB String>," +
200                " V extends @RTF @RTF Object & @RTC @RTC List<@RTD @RTD List<@RTE @RTE Object>>> { }";
201    }
202
203    @TADescription(annotation = "RTAs", type = CLASS_TYPE_PARAMETER, paramIndex = 0)
204    @TADescription(annotation = "RTBs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0)
205    @TADescription(annotation = "RTCs", type = CLASS_TYPE_PARAMETER, paramIndex = 1)
206    @TADescription(annotation = "RTDs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0)
207    @TADescription(annotation = "RTEs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1)
208    public String regularInterfaceRepeatableAnnotation() {
209        return "interface %TEST_CLASS_NAME%<@RTA @RTA K extends @RTB @RTB Date," +
210                " @RTC @RTC V extends @RTD @RTD Object & @RTE @RTE Cloneable> { }";
211    }
212
213    @TADescription(annotation = "RTAs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1)
214    @TADescription(annotation = "RTBs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1})
215    @TADescription(annotation = "RTCs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1)
216    @TADescription(annotation = "RTDs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0})
217    @TADescription(annotation = "RTEs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0})
218    public String regularInterfaceParameterizedRepeatableAnnotation() {
219        return "interface %TEST_CLASS_NAME%<K extends @RTA @RTA Map<String, @RTB @RTB String>," +
220                " V extends @RTC @RTC List<@RTD @RTD List<@RTE @RTE Object>>> { }";
221    }
222
223    @TADescription(annotation = "RTAs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1)
224    @TADescription(annotation = "RTBs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 1, genericLocation = {3, 1})
225    @TADescription(annotation = "RTCs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1)
226    @TADescription(annotation = "RTDs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0})
227    @TADescription(annotation = "RTEs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 1, genericLocation = {3, 0, 3, 0})
228    @TADescription(annotation = "RTFs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 1, boundIndex = 0)
229    @TADescription(annotation = "RTGs", type = CLASS_TYPE_PARAMETER_BOUND, paramIndex = 0, boundIndex = 0)
230    public String regularInterfaceParameterizedRepeatableAnnotation2() {
231        return "interface %TEST_CLASS_NAME%<K extends @RTG @RTG Object & @RTA @RTA Map<String, @RTB @RTB String>," +
232                " V extends @RTF @RTF Object & @RTC @RTC List<@RTD @RTD List<@RTE @RTE Object>>> { }";
233    }
234
235    @TADescription(annotation = "RTAs", type = METHOD_RETURN)
236    public String useInReturnRepeatableAnnotation1() {
237        return "class %TEST_CLASS_NAME%<T> { @RTA @RTA T m() { throw new RuntimeException(); } }";
238    }
239
240    @TADescription(annotation = "RTAs", type = METHOD_RETURN, genericLocation = {3, 0})
241    public String useInReturnRepeatableAnnotation2() {
242        return "class %TEST_CLASS_NAME%<T> { Class<@RTA @RTA T> m() { throw new RuntimeException(); } }";
243    }
244
245    @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER,
246            paramIndex = 0, genericLocation = {3, 0})
247    public String useInParamRepeatableAnnotation1() {
248        return "class %TEST_CLASS_NAME%<T> { void m(Class<@RTA @RTA T> p) { throw new RuntimeException(); } }";
249    }
250
251    @TADescription(annotation = "RTAs", type = METHOD_FORMAL_PARAMETER,
252            paramIndex = 0, genericLocation = {3, 0})
253    public String useInParamRepeatableAnnotation2() {
254        return "class %TEST_CLASS_NAME% { void m(Class<@RTA @RTA Object> p) { throw new RuntimeException(); } }";
255    }
256
257}
258