1 /*
2 * Copyright (c) 2013, 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 8005085 8005877 8004829 8005681 8006734 8006775
27 * @ignore
28 * @summary Combinations of Target ElementTypes on (repeated)type annotations.
29 */
30
31 import com.sun.tools.classfile.*;
32 import java.io.File;
33
34 public class CombinationsTargetTest1 extends ClassfileTestHelper {
35 // Helps identify test case in event of failure.
36 int testcount = 0;
37 int src1 = 1, src2 = 2, src4 = 4,
38 src5 = 5, src6 = 6, src7 = 7;
39
40 String[] ETypes={"TYPE", "FIELD", "METHOD", "PARAMETER", "CONSTRUCTOR",
41 "LOCAL_VARIABLE", "ANNOTATION_TYPE", "PACKAGE"};
42
43 // local class tests will have an inner class.
44 Boolean hasInnerClass=false;
45 String innerClassname="";
46
47 public static void main(String[] args) throws Exception {
49 }
50
51 void run() throws Exception {
52 // Determines which repeat and order in source(ABMix).
53 Boolean As= false, BDs=true, ABMix=false;
54 int testrun=0;
55 // A repeats and/or B/D repeats, ABMix for order of As and Bs.
56 Boolean [][] bRepeat = new Boolean[][]{{false,false,false},//no repeats
57 {true,false,false}, //repeat @A
58 {false,true,false}, //repeat @B
59 {true,true,false}, //repeat both
60 {false,false,true} //repeat mix
61 };
62 for(Boolean[] bCombo : bRepeat) {
63 As=bCombo[0]; BDs=bCombo[1]; ABMix=bCombo[2];
64 for(String et : ETypes) {
65 switch(et) {
66 case "METHOD":
67 test( 8, 0, 2, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src1);
68 test(10, 0, 2, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src2);
69 test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src4);
70 test(10, 0, 2, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src6);
71 test( 0, 8, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, src1);
72 test( 0, 10, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, src2);
73 test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src4);
74 test( 0, 10, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, src6);
75 break;
76 case "CONSTRUCTOR":
77 case "FIELD":
78 test( 8, 0, 4, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src1);
79 test( 6, 0, 3, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src5);
80 test( 9, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src7);
81 test( 0, 8, 0, 4, As, BDs, ABMix, "RUNTIME", et, ++testrun, src1);
82 test( 0, 6, 0, 3, As, BDs, ABMix, "RUNTIME", et, ++testrun, src5);
83 test( 0, 9, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src7);
84 break;
85 default:/*TYPE,PARAMETER,LOCAL_VARIABLE,ANNOTATION_TYPE,PACKAGE*/
86 test( 8, 0, 2, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src1);
87 test( 6, 0, 3, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src5);
88 test( 0, 8, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, src1);
89 test( 0, 6, 0, 3, As, BDs, ABMix, "RUNTIME", et, ++testrun, src5);
90 }
91 }
92 }
93 }
96 Boolean BDrepeats, Boolean ABmix, String rtn, String et2,
97 Integer N, int source) throws Exception {
98 ++testcount;
99 expected_tvisibles = tvis;
100 expected_tinvisibles = tinv;
101 expected_visibles = vis;
102 expected_invisibles = inv;
103 File testFile = null;
104 String tname="Test" + N.toString();
105 hasInnerClass=false;
106 String testDef = "Test " + testcount + " parameters: tinv=" + tinv +
107 ", tvis=" + tvis + ", inv=" + inv + ", vis=" + vis +
108 ", Arepeats=" + Arepeats + ", BDrepeats=" + BDrepeats +
109 ", ABmix=" + ABmix + ", retention: " + rtn + ", anno2: " +
110 et2 + ", src=" + source;
111
112 println(testDef);
113 // Create test source and File.
114 String sourceString = sourceString(tname, rtn, et2, Arepeats,
115 BDrepeats, ABmix, source);
116 testFile = writeTestFile(tname+".java", sourceString);
117 // Compile test source and read classfile.
118 File classFile = null;
119 try {
120 classFile = compile(testFile);
121 } catch (Error err) {
122 System.err.println("Failed compile. Source:\n" + sourceString);
123 throw err;
124 }
125 //if sourcString() set hasInnerClass it also set innerClassname.
126 if(hasInnerClass) {
127 StringBuffer sb = new StringBuffer(classFile.getAbsolutePath());
128 classFile=new File(sb.insert(sb.lastIndexOf(".class"),innerClassname).toString());
129 }
130 ClassFile cf = ClassFile.read(classFile);
131
132 //Test class,fields and method counts.
133 test(cf);
134
135 for (Field f : cf.fields) {
184 "@Retention("+retentn+")\n" +
185 "@Target({TYPE_USE,_OTHER_})\n" +
186 "@Repeatable( BC.class )\n" +
187 "@interface B { }\n\n" +
188
189 "@Retention("+retentn+")\n" +
190 "@Target({TYPE_USE,_OTHER_})\n" +
191 "@interface BC { B[] value(); } \n\n" +
192
193 "@Retention("+retentn+")\n" +
194 "@Target({TYPE_PARAMETER,_OTHER_})\n" +
195 "@interface C { }\n\n" +
196
197 "@Retention("+retentn+")\n" +
198 "@Target({TYPE_USE,TYPE_PARAMETER,_OTHER_})\n" +
199 "@Repeatable(DC.class)\n" +
200 "@interface D { }\n\n" +
201
202 "@Retention("+retentn+")\n" +
203 "@Target({TYPE_USE,TYPE_PARAMETER,_OTHER_})\n" +
204 "@interface DC { D[] value(); }\n\n");
205
206 // Test case sources with sample generated source.
207 switch(src) {
208 case 1: // repeating type annotations at class level
209 /*
210 * @A @B class Test1 {
211 * @A @B Test1(){}
212 * @A @B Integer i1 = 0;
213 * String @A @B [] @A @B [] sa = null;
214 * // type usage in method body
215 * String test(Test1 this, String param, String ... vararg) {
216 * Object o = new String [3];
217 * return (String) null;
218 * }}
219 */
220 source = new String(
221 "// (repeating) type annotations at class level. \n" +
222 "_As_ _Bs_ class " + testname + " {\n" +
223 "_As_ _Bs_ " + testname +"(){} \n" +
224 "_As_ _Bs_ Integer i1 = 0; \n" +
225 "String _As_ _Bs_ [] _As_ _Bs_ [] sa = null; \n" +
226 "// type usage in method body \n" +
227 "String test("+testname+" this, " +
228 "String param, String ... vararg) { \n" +
229 " Object o = new String [3]; \n" +
230 " return (String) null; \n" +
231 "} \n" +
232 "} \n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
233 "\n\n";
234 break;
235 case 2: // (repeating) type annotations on method.
236 /*
237 * class Test12 {
238 * Test12(){}
239 * // type usage on method
240 * @A @B String test(@A @B Test12 this, @A @B String param, @A @B String @A @B ... vararg) {
241 * Object o = new String [3];
242 * return (String) null;
243 * }}
244 */
245 source = new String(
246 "// (repeating) type annotations on method. \n" +
247 "class " + testname + " {\n" +
248 testname +"(){} \n" +
249 "// type usage on method \n" +
250 "_As_ _Bs_ String test(_As_ _Bs_ "+testname+" this, " +
251 "_As_ _Bs_ String param, _As_ _Bs_ String _As_ _Bs_ ... vararg) { \n" +
252 " Object o = new String [3]; \n" +
253 " return (String) null; \n" +
254 "} \n" +
255 "} \n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
256 "\n\n";
257 break;
258 case 4: //(repeating) annotations on wildcard, type arguments in anonymous class.
259 /*
260 * class Test13<T extends Object> {
261 * public T data = null;
262 * T getData() { return data;}
263 * String mtest( Test13<String> t){ return t.getData(); }
264 * public void test() {
265 * mtest( new Test13<@A @B String>() {
266 * void m1(List<@A @B ? extends @A @B Object> lst) {}
267 * void m2() throws@A @B Exception { }
268 * });
269 * }
270 * }
271 */
272 source = new String( source +
273 "// (repeating) annotations on wildcard, type arguments in anonymous class. \n" +
274 "class " + testname + "<T extends Object> {\n" +
275 " public T data = null;\n" +
276 " T getData() { return data;}\n" +
277 " String mtest( " + testname + "<String> t){ return t.getData(); }\n" +
278 " public void test() {\n" +
279 " mtest( new " + testname + "<_As_ _Bs_ String>() {\n" +
280 " void m1(List<_As_ _Bs_ ? extends _As_ _Bs_ Object> lst) {}\n" +
281 " void m2() throws_As_ _Bs_ Exception { }\n" +
282 " });\n" +
283 " }\n" +
284 "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + "\n\n";
285 hasInnerClass=true;
286 innerClassname="$1";
287 break;
288 case 5: // (repeating)annotations on type parameters, bounds and type arguments on class decl.
289 /*
290 * @A @B @D
291 * class Test2<@A @B @C @D T extends @A @B Object> {
292 * Map<List<String>, Integer> map =
293 * new HashMap<List< String>, Integer>();
294 * Map<List<String>,Integer> map2 = new HashMap<>();
295 * String test(Test2<T> this) { return null;}
296 * <T> String genericMethod(T t) { return null; }
297 * }
298 */
299 source = new String( source +
300 "// (repeating)annotations on type parameters, bounds and type arguments on class decl. \n" +
301 "_As_ _Bs_ _Ds_\n" + //8004829: A and B on type parameter below.
302 "class " + testname + "<_As_ _Bs_ @C _Ds_ T extends _As_ _Bs_ Object> {\n" +
303 " Map<List<String>, Integer> map =\n" +
304 " new HashMap<List< String>, Integer>();\n" +
305 " Map<List<String>,Integer> map2 = new HashMap<>();\n" +
306 " String test(" + testname + "<T> this) { return null;}\n" +
307 " <T> String genericMethod(T t) { return null; }\n" +
308 "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
309 "\n\n";
310 break;
311 case 6: // (repeating) annotations on type parameters, bounds and type arguments on method.
312 /*
313 * class Test14<T extends Object> {
314 * Map<List<String>, Integer> map =
315 * new HashMap<List<String>, Integer>();
316 * Map<List<String>, Integer> map2 = new HashMap<>();
317 * String test(@A @B Test14<@D T> this) { return null;}
318 * <@C @D T> @A @B String genericMethod(@A @B @D T t) { return null; }
319 * }
320 */
321 source = new String( source +
322 "// (repeating) annotations on type parameters, bounds and type arguments on method. \n" +
323 "class " + testname + "<T extends Object> {\n" +
324 " Map<List<String>, Integer> map =\n" +
325 " new HashMap<List<String>, Integer>();\n" +
326 " Map<List<String>, Integer> map2 = new HashMap<>();\n" +
327 " String test(_As_ _Bs_ " + testname + "<_Ds_ T> this) { return null;}\n" +
328 " <@C _Ds_ T> _As_ _Bs_ String genericMethod(_As_ _Bs_ _Ds_ T t) { return null; }\n" +
329 "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
330 "\n\n";
331 break;
332 case 7: // repeating annotations on type parameters, bounds and type arguments in method.
333 /*
334 * class Test7{
335 * <E extends Comparable> Map<List<E>, E > foo(E e) {
336 * class maptest <@A @B @D E> {
337 * Map<List<@A @B @D E>,@A @B @D E> getMap() {
338 * return new HashMap<List<E>,E>();
339 * }
340 * }
341 * return new maptest<E>().getMap();
342 * }
343 * Map<List<String>,String> shm = foo(new String("hello"));
344 * }
345 */
346 source = new String( source +
347 "// (repeating)annotations on type parameters of class, method return value in method. \n" +
348 "class "+ testname + "{\n" +
349 " <E extends Comparable> Map<List<E>, E > foo(E e) {\n" +
350 " class maptest <_As_ _Bs_ _Ds_ E> {\n" + // inner class $1maptest
351 " Map<List<_As_ _Bs_ _Ds_ E>,_As_ _Bs_ _Ds_ E> getMap() { \n" +
352 " return new HashMap<List<E>,E>();\n" +
353 " }\n" +
354 " }\n" +
355 " return new maptest<E>().getMap();\n" +
356 " }\n" +
357 " Map<List<String>,String> shm = foo(new String(\"hello\"));\n" +
358 "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
359 "\n\n";
360 hasInnerClass=true;
361 innerClassname="$1maptest";
362 break;
363 }
364 return imports + source;
365 }
366 }
|
1 /*
2 * Copyright (c) 2013 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 8005085 8005877 8004829 8005681 8006734 8006775
27 * @summary Combinations of Target ElementTypes on (repeated)type annotations.
28 */
29
30 import com.sun.tools.classfile.*;
31 import java.io.File;
32
33 public class CombinationsTargetTest1 extends ClassfileTestHelper {
34 // Helps identify test case in event of failure.
35 int testcount = 0;
36 int src1 = 1, src2 = 2, src4 = 4,
37 src5 = 5, src6 = 6, src7 = 7;
38
39 String[] ETypes={"TYPE", "FIELD", "METHOD", "PARAMETER", "CONSTRUCTOR",
40 "LOCAL_VARIABLE", "ANNOTATION_TYPE", "PACKAGE"};
41
42 // local class tests will have an inner class.
43 Boolean hasInnerClass=false;
44 String innerClassname="";
45
46 public static void main(String[] args) throws Exception {
48 }
49
50 void run() throws Exception {
51 // Determines which repeat and order in source(ABMix).
52 Boolean As= false, BDs=true, ABMix=false;
53 int testrun=0;
54 // A repeats and/or B/D repeats, ABMix for order of As and Bs.
55 Boolean [][] bRepeat = new Boolean[][]{{false,false,false},//no repeats
56 {true,false,false}, //repeat @A
57 {false,true,false}, //repeat @B
58 {true,true,false}, //repeat both
59 {false,false,true} //repeat mix
60 };
61 for(Boolean[] bCombo : bRepeat) {
62 As=bCombo[0]; BDs=bCombo[1]; ABMix=bCombo[2];
63 for(String et : ETypes) {
64 switch(et) {
65 case "METHOD":
66 test( 8, 0, 2, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src1);
67 test(10, 0, 2, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src2);
68 test( 6, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src4);
69 test(10, 0, 2, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src6);
70 test( 0, 8, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, src1);
71 test( 0, 10, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, src2);
72 test( 0, 6, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src4);
73 test( 0, 10, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, src6);
74 break;
75 case "CONSTRUCTOR":
76 case "FIELD":
77 test( 8, 0, 4, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src1);
78 test( 6, 0, 3, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src5);
79 test( 9, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src7);
80 test( 0, 8, 0, 4, As, BDs, ABMix, "RUNTIME", et, ++testrun, src1);
81 test( 0, 6, 0, 3, As, BDs, ABMix, "RUNTIME", et, ++testrun, src5);
82 test( 0, 9, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src7);
83 break;
84 default:/*TYPE,PARAMETER,LOCAL_VARIABLE,ANNOTATION_TYPE,PACKAGE*/
85 test( 8, 0, 2, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src1);
86 test( 6, 0, 3, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src5);
87 test( 0, 8, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, src1);
88 test( 0, 6, 0, 3, As, BDs, ABMix, "RUNTIME", et, ++testrun, src5);
89 }
90 }
91 }
92 }
95 Boolean BDrepeats, Boolean ABmix, String rtn, String et2,
96 Integer N, int source) throws Exception {
97 ++testcount;
98 expected_tvisibles = tvis;
99 expected_tinvisibles = tinv;
100 expected_visibles = vis;
101 expected_invisibles = inv;
102 File testFile = null;
103 String tname="Test" + N.toString();
104 hasInnerClass=false;
105 String testDef = "Test " + testcount + " parameters: tinv=" + tinv +
106 ", tvis=" + tvis + ", inv=" + inv + ", vis=" + vis +
107 ", Arepeats=" + Arepeats + ", BDrepeats=" + BDrepeats +
108 ", ABmix=" + ABmix + ", retention: " + rtn + ", anno2: " +
109 et2 + ", src=" + source;
110
111 println(testDef);
112 // Create test source and File.
113 String sourceString = sourceString(tname, rtn, et2, Arepeats,
114 BDrepeats, ABmix, source);
115
116 testFile = writeTestFile(tname+".java", sourceString);
117 // Compile test source and read classfile.
118 File classFile = null;
119 try {
120 classFile = compile(testFile);
121 } catch (Error err) {
122 System.err.println("Failed compile. Source:\n" + sourceString);
123 throw err;
124 }
125 //if sourcString() set hasInnerClass it also set innerClassname.
126 if(hasInnerClass) {
127 StringBuffer sb = new StringBuffer(classFile.getAbsolutePath());
128 classFile=new File(sb.insert(sb.lastIndexOf(".class"),innerClassname).toString());
129 }
130 ClassFile cf = ClassFile.read(classFile);
131
132 //Test class,fields and method counts.
133 test(cf);
134
135 for (Field f : cf.fields) {
184 "@Retention("+retentn+")\n" +
185 "@Target({TYPE_USE,_OTHER_})\n" +
186 "@Repeatable( BC.class )\n" +
187 "@interface B { }\n\n" +
188
189 "@Retention("+retentn+")\n" +
190 "@Target({TYPE_USE,_OTHER_})\n" +
191 "@interface BC { B[] value(); } \n\n" +
192
193 "@Retention("+retentn+")\n" +
194 "@Target({TYPE_PARAMETER,_OTHER_})\n" +
195 "@interface C { }\n\n" +
196
197 "@Retention("+retentn+")\n" +
198 "@Target({TYPE_USE,TYPE_PARAMETER,_OTHER_})\n" +
199 "@Repeatable(DC.class)\n" +
200 "@interface D { }\n\n" +
201
202 "@Retention("+retentn+")\n" +
203 "@Target({TYPE_USE,TYPE_PARAMETER,_OTHER_})\n" +
204 "@interface DC { D[] value(); }\n");
205
206 // Test case sources with sample generated source.
207 switch(src) {
208 case 1: // repeating type annotations at class level
209 /*
210 * @A @B class Test1 {
211 * @A @B Test1(){}
212 * @A @B Integer i1 = 0;
213 * String @A @B [] @A @B [] sa = null;
214 * // type usage in method body
215 * String test(Test1 this, String param, String ... vararg) {
216 * Object o = new String [3];
217 * return (String) null;
218 * }}
219 */
220 source = new String(
221 "//case1: (repeating) type annotations at class level. \n" +
222 "_As_ _Bs_ class " + testname + " {\n" +
223 "_As_ _Bs_ " + testname +"(){} \n" +
224 "_As_ _Bs_ Integer i1 = 0; \n" +
225 "String _As_ _Bs_ [] _As_ _Bs_ [] sa = null; \n" +
226 "// type usage in method body \n" +
227 "String test("+testname+" this, " +
228 "String param, String ... vararg) { \n" +
229 " Object o = new String [3]; \n" +
230 " return (String) null; \n" +
231 "}\n" +
232 "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
233 "\n";
234 break;
235 case 2: // (repeating) type annotations on method.
236 /*
237 * class Test12 {
238 * Test12(){}
239 * // type usage on method
240 * @A @B String test(@A @B Test12 this, @A @B String param, @A @B String @A @B ... vararg) {
241 * Object o = new String [3];
242 * return (String) null;
243 * }}
244 */
245 source = new String(
246 "//case2: (repeating) type annotations on method. \n" +
247 "class " + testname + " {\n" +
248 testname +"(){} \n" +
249 "// type usage on method \n" +
250 "_As_ _Bs_ String test(_As_ _Bs_ "+testname+" this, " +
251 "_As_ _Bs_ String param, _As_ _Bs_ String _As_ _Bs_ ... vararg) { \n" +
252 " Object o = new String [3]; \n" +
253 " return (String) null; \n" +
254 "}\n" +
255 "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
256 "\n";
257 break;
258 case 4: //(repeating) annotations on wildcard, type arguments in anonymous class.
259 /*
260 * class Test13<T extends Object> {
261 * public T data = null;
262 * T getData() { return data;}
263 * String mtest( Test13<String> t){ return t.getData(); }
264 * public void test() {
265 * mtest( new Test13<String>() {
266 * void m1(List<@A @B ? extends @A @B Object> lst) {}
267 * void m2() throws@A @B Exception { }
268 * });
269 * }
270 * }
271 */
272 source = new String( source +
273 "//case4:(repeating) annotations on wildcard, type arguments in anonymous class. \n" +
274 "class " + testname + "<T extends Object> {\n" +
275 " public T data = null;\n" +
276 " T getData() { return data;}\n" +
277 " String mtest( " + testname + "<String> t){ return t.getData(); }\n" +
278 " public void test() {\n" +
279 " mtest( new " + testname + "<String>() {\n" +
280 " void m1(List<_As_ _Bs_ ? extends _As_ _Bs_ Object> lst) {}\n" +
281 " void m2() throws_As_ _Bs_ Exception { }\n" +
282 " });\n" +
283 " }\n" +
284 "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
285 "\n";
286 hasInnerClass=true;
287 innerClassname="$1";
288 break;
289 case 5: // (repeating)annotations on type parameters, bounds and type arguments on class decl.
290 /*
291 * @A @B @D
292 * class Test2<@A @B @C @D T extends @A @B Object> {
293 * Map<List<String>, Integer> map =
294 * new HashMap<List< String>, Integer>();
295 * Map<List<String>,Integer> map2 = new HashMap<>();
296 * String test(Test2<T> this) { return null;}
297 * <T> String genericMethod(T t) { return null; }
298 * }
299 */
300 source = new String( source +
301 "//case5: (repeating)annotations on type parameters, bounds and type arguments on class decl. \n" +
302 "_As_ _Bs_ _Ds_\n" + //8004829: A and B on type parameter below.
303 "class " + testname + "<_As_ _Bs_ @C _Ds_ T extends _As_ _Bs_ Object> {\n" +
304 " Map<List<String>, Integer> map =\n" +
305 " new HashMap<List< String>, Integer>();\n" +
306 " Map<List<String>,Integer> map2 = new HashMap<>();\n" +
307 " String test(" + testname + "<T> this) { return null;}\n" +
308 " <T> String genericMethod(T t) { return null; }\n" +
309 "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
310 "\n";
311 break;
312 case 6: // (repeating) annotations on type parameters, bounds and type arguments on method.
313 /*
314 * class Test14<T extends Object> {
315 * Map<List<String>, Integer> map =
316 * new HashMap<List<String>, Integer>();
317 * Map<List<String>, Integer> map2 = new HashMap<>();
318 * String test(@A @B Test14<@D T> this) { return null;}
319 * <@C @D T> @A @B String genericMethod(@A @B @D T t) { return null; }
320 * }
321 */
322 source = new String( source +
323 "//case6: (repeating) annotations on type parameters, bounds and type arguments on method. \n" +
324 "class " + testname + "<T extends Object> {\n" +
325 " Map<List<String>, Integer> map =\n" +
326 " new HashMap<List<String>, Integer>();\n" +
327 " Map<List<String>, Integer> map2 = new HashMap<>();\n" +
328 " String test(_As_ _Bs_ " + testname + "<_Ds_ T> this) { return null;}\n" +
329 " <@C _Ds_ T> _As_ _Bs_ String genericMethod(_As_ _Bs_ _Ds_ T t) { return null; }\n" +
330 "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
331 "\n";
332 break;
333 case 7: // repeating annotations on type parameters, bounds and type arguments in method.
334 /*
335 * class Test7{
336 * <E extends Comparable> Map<List<E>, E > foo(E e) {
337 * class maptest <@A @B @D E> {
338 * Map<List<@A @B @D E>,@A @B @D E> getMap() {
339 * return new HashMap<List<E>,E>();
340 * }
341 * }
342 * return new maptest<E>().getMap();
343 * }
344 * Map<List<String>,String> shm = foo(new String("hello"));
345 * }
346 */
347 source = new String( source +
348 "//case7: (repeating)annotations on type parameters of class, method return value in method. \n" +
349 "class "+ testname + "{\n" +
350 " <E extends Comparable> Map<List<E>, E > foo(E e) {\n" +
351 " class maptest <_As_ _Bs_ _Ds_ E> {\n" + // inner class $1maptest
352 " Map<List<_As_ _Bs_ _Ds_ E>,_As_ _Bs_ _Ds_ E> getMap() { \n" +
353 " return new HashMap<List<E>,E>();\n" +
354 " }\n" +
355 " }\n" +
356 " return new maptest<E>().getMap();\n" +
357 " }\n" +
358 " Map<List<String>,String> shm = foo(new String(\"hello\"));\n" +
359 "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
360 "\n";
361 hasInnerClass=true;
362 innerClassname="$1maptest";
363 break;
364 }
365 return imports + source;
366 }
367 }
|