21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 /* |
24 /* |
25 * @test |
25 * @test |
26 * @bug 8005085 8005877 8004829 8005681 8006734 8006775 |
26 * @bug 8005085 8005877 8004829 8005681 8006734 8006775 8006507 |
27 * @ignore 8013409: test failures for type annotations |
|
28 * @summary Combinations of Target ElementTypes on (repeated)type annotations. |
27 * @summary Combinations of Target ElementTypes on (repeated)type annotations. |
29 */ |
28 */ |
30 |
29 |
31 import com.sun.tools.classfile.*; |
30 import com.sun.tools.classfile.*; |
32 import java.io.File; |
31 import java.io.File; |
33 |
32 |
34 public class CombinationsTargetTest2 extends ClassfileTestHelper { |
33 public class CombinationsTargetTest2 extends ClassfileTestHelper { |
35 // Helps identify test case in event of failure. |
34 |
|
35 // Test count helps identify test case in event of failure. |
36 int testcount = 0; |
36 int testcount = 0; |
37 int src3 = 3, src8 = 8, src9 = 9; |
37 |
|
38 // Base test case template descriptions |
|
39 enum srce { |
|
40 src1("(repeating) type annotations on on field in method body",true), |
|
41 src2("(repeating) type annotations on type parameters, bounds and type arguments", true), |
|
42 src3("(repeating) type annotations on type parameters of class, method return value in method", true), |
|
43 src4("(repeating) type annotations on field in anonymous class", false), |
|
44 src5("(repeating) type annotations on field in anonymous class", false); |
|
45 |
|
46 String description; |
|
47 Boolean local; |
|
48 |
|
49 srce(String desc, Boolean b) { |
|
50 this.description = this + ": " +desc; |
|
51 this.local = b; |
|
52 } |
|
53 } |
|
54 |
38 |
55 |
39 String[] ETypes={"TYPE", "FIELD", "METHOD", "PARAMETER", "CONSTRUCTOR", |
56 String[] ETypes={"TYPE", "FIELD", "METHOD", "PARAMETER", "CONSTRUCTOR", |
40 "LOCAL_VARIABLE", "ANNOTATION_TYPE", "PACKAGE"}; |
57 "LOCAL_VARIABLE", "ANNOTATION_TYPE", "PACKAGE"}; |
41 |
58 |
42 // local class tests will have an inner class. |
59 // local class tests will have an inner class. |
49 |
66 |
50 void run() throws Exception { |
67 void run() throws Exception { |
51 // Determines which repeat and order in source(ABMix). |
68 // Determines which repeat and order in source(ABMix). |
52 Boolean As= false, BDs=true, ABMix=false; |
69 Boolean As= false, BDs=true, ABMix=false; |
53 int testrun=0; |
70 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 |
71 Boolean [][] bRepeat = new Boolean[][]{{false,false,false},//no repeats |
56 {true,false,false}, //repeat @A |
72 {true,false,false}, //repeat @A |
57 {false,true,false}, //repeat @B |
73 {false,true,false}, //repeat @B |
58 {true,true,false}, //repeat both |
74 {true,true,false}, //repeat both |
59 {false,false,true} //repeat mix |
75 {false,false,true} //repeat mix |
60 }; |
76 }; |
|
77 |
61 for(Boolean[] bCombo : bRepeat) { |
78 for(Boolean[] bCombo : bRepeat) { |
62 As=bCombo[0]; BDs=bCombo[1]; ABMix=bCombo[2]; |
79 As=bCombo[0]; BDs=bCombo[1]; ABMix=bCombo[2]; |
63 for(String et : ETypes) { |
80 for(String et : ETypes) { |
64 switch(et) { |
81 switch(et) { |
65 case "METHOD": |
82 case "METHOD": |
66 test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src3); |
83 test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src1); |
67 test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src3); |
84 test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1); |
|
85 test( 2, 0, 2, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src5); |
|
86 test( 0, 2, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src5); |
68 break; |
87 break; |
69 case "CONSTRUCTOR": |
|
70 case "FIELD": |
88 case "FIELD": |
71 test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src3); |
89 test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src1); |
72 test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src8); |
90 test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src2); |
73 test( 6, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, src9); |
91 test( 6, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src3); |
74 test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src3); |
92 test( 2, 0, 2, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src4); |
75 test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src8); |
93 test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1); |
76 test( 0, 6, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src9); |
94 test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src2); |
|
95 test( 0, 6, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src3); |
|
96 test( 0, 2, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src4); |
77 break; |
97 break; |
78 default:/*TYPE,PARAMETER,LOCAL_VARIABLE,ANNOTATION_TYPE,PACKAGE*/ |
98 default:/*TYPE,PARAMETER,LOCAL_VARIABLE,ANNOTATION_TYPE,PACKAGE*/ |
|
99 test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src4); |
|
100 test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src5); |
79 break; |
101 break; |
80 } |
102 } |
81 } |
103 } |
82 } |
104 } |
83 } |
105 } |
84 |
106 |
85 public void test(int tinv, int tvis, int inv, int vis, Boolean Arepeats, |
107 public void test(int tinv, int tvis, int inv, int vis, Boolean Arepeats, |
86 Boolean BDrepeats, Boolean ABmix, String rtn, String et2, |
108 Boolean BDrepeats, Boolean ABmix, String rtn, String et2, |
87 Integer N, int source) throws Exception { |
109 Integer N, srce source) throws Exception { |
88 ++testcount; |
110 ++testcount; |
89 expected_tvisibles = tvis; |
111 expected_tvisibles = tvis; |
90 expected_tinvisibles = tinv; |
112 expected_tinvisibles = tinv; |
91 expected_visibles = vis; |
113 expected_visibles = vis; |
92 expected_invisibles = inv; |
114 expected_invisibles = inv; |
95 hasInnerClass=false; |
117 hasInnerClass=false; |
96 String testDef = "Test " + testcount + " parameters: tinv=" + tinv + |
118 String testDef = "Test " + testcount + " parameters: tinv=" + tinv + |
97 ", tvis=" + tvis + ", inv=" + inv + ", vis=" + vis + |
119 ", tvis=" + tvis + ", inv=" + inv + ", vis=" + vis + |
98 ", Arepeats=" + Arepeats + ", BDrepeats=" + BDrepeats + |
120 ", Arepeats=" + Arepeats + ", BDrepeats=" + BDrepeats + |
99 ", ABmix=" + ABmix + ", retention: " + rtn + ", anno2: " + |
121 ", ABmix=" + ABmix + ", retention: " + rtn + ", anno2: " + |
100 et2 + ", src=" + source; |
122 et2 + ", src=" + source + "\n " + source.description; |
101 |
123 |
102 // Uncomment this block to run the tests but skip failing scenarios. |
124 if( |
103 // // 8005681 - skip cases with repeated annotations on new, array, cast. |
125 // 8005681 - src1,2,3 - skip cases with repeated annotations on new, array, cast. |
104 // if((source==3 || source==8 || source==9) && (ABmix || (Arepeats && BDrepeats))) { |
126 (( source.equals(srce.src1) || source.equals(srce.src2) || |
105 // System.out.println(testDef+"\n8005681-skip repeated annotations on new,array,cast"); |
127 source.equals(srce.src3)) && (ABmix || (Arepeats && BDrepeats))) |
106 // return; |
128 // 8008928 - src4,5 - this change cause crash with t-a on anon class) |
107 // } |
129 || (source.equals(srce.src4) || source.equals(srce.src5)) |
|
130 ) { |
|
131 System.out.println(testDef + |
|
132 "\n 8005681-skip repeated annotations on new,array,cast"); |
|
133 return; |
|
134 } |
108 |
135 |
109 println(testDef); |
136 println(testDef); |
110 // Create test source and File. |
137 // Create test source and File. |
111 String sourceString = sourceString(tname, rtn, et2, Arepeats, |
138 String sourceString = sourceString(tname, rtn, et2, Arepeats, |
112 BDrepeats, ABmix, source); |
139 BDrepeats, ABmix, source); |
208 * Object o = new @A @B String @A @B [3]; |
242 * Object o = new @A @B String @A @B [3]; |
209 * return (@A @B String) null; |
243 * return (@A @B String) null; |
210 * }} |
244 * }} |
211 */ |
245 */ |
212 source = new String( |
246 source = new String( |
213 "class " + testname + " {\n" + |
247 "// " + src.description + "\n" + |
214 "" + testname +"(){} \n" + |
248 "class " + testname + " {\n" + |
215 "// type usage in method body \n" + |
249 "" + testname +"(){} \n" + |
216 "String test("+testname+" this, " + |
250 "// type usage in method body \n" + |
217 "String param, String ... vararg) { \n" + |
251 "String test("+testname+" this, " + |
218 " _As_ _Bs_\n Object o = new _As_ _Bs_ String _As_ _Bs_ [3]; \n" + |
252 "String param, String ... vararg) { \n" + |
219 " return (_As_ _Bs_ String) null; \n" + |
253 " _As_ _Bs_\n Object o = new _As_ _Bs_ String _As_ _Bs_ [3]; \n" + |
220 "} \n" + |
254 " return (_As_ _Bs_ String) null; \n" + |
221 "} \n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + |
255 "} \n" + |
222 "\n\n"; |
256 "} \n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + |
223 break; |
257 "\n\n"; |
224 case 8: // (repeating) annotations on type parameters, bounds and type arguments in new statement. |
258 break; |
|
259 case src2: // (repeating) annotations on type parameters, bounds and type arguments in new statement. |
225 /* |
260 /* |
226 * class Test2<T extends Object> { |
261 * class Test2<T extends Object> { |
227 * Map<List<String>, Integer> map = |
262 * Map<List<String>, Integer> map = |
228 * new HashMap<@A @B List<@A @B String>, @A @B Integer>(); |
263 * new HashMap<@A @B List<@A @B String>, @A @B Integer>(); |
229 * Map<List<String>, Integer> map2 = new @A @B HashMap<>(); |
264 * Map<List<String>, Integer> map2 = new @A @B HashMap<>(); |
230 * String test(Test2<T> this) { return null;} |
265 * String test(Test2<T> this) { return null;} |
231 * <T> String genericMethod(T t) { return null; } |
266 * <T> String genericMethod(T t) { return null; } |
232 * } |
267 * } |
233 */ |
268 */ |
234 source = new String( source + |
269 source = new String( source + |
235 "// (repeating) annotations on type parameters, bounds and type arguments. \n" + |
270 "// " + src.description + "\n" + |
236 "class " + testname + "<T extends Object> {\n" + |
271 "class " + testname + "<T extends Object> {\n" + |
237 " Map<List<String>, Integer> map =\n" + |
272 " Map<List<String>, Integer> map =\n" + |
238 " new HashMap<_As_ _Bs_ List<_As_ _Bs_ String>, _As_ _Bs_ Integer>();\n" + |
273 " new HashMap<_As_ _Bs_ List<_As_ _Bs_ String>, _As_ _Bs_ Integer>();\n" + |
239 " Map<List<String>, Integer> map2 = new _As_ _Bs_ HashMap<>();\n" + |
274 " Map<List<String>, Integer> map2 = new _As_ _Bs_ HashMap<>();\n" + |
240 " String test(" + testname + "<T> this) { return null;}\n" + |
275 " String test(" + testname + "<T> this) { return null;}\n" + |
241 " <T> String genericMethod(T t) { return null; }\n" + |
276 " <T> String genericMethod(T t) { return null; }\n" + |
242 "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + |
277 "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + |
243 "\n\n"; |
278 "\n\n"; |
244 break; |
279 break; |
245 case 9: // (repeating)annotations on type parameters of class, method return value in method. |
280 case src3: // (repeating)annotations on type parameters of class, method return value in method. |
246 /* |
281 /* |
247 * class Test3{ |
282 * class Test3{ |
248 * <E extends Comparable> Map<List<E>, E > foo(E e) { |
283 * <E extends Comparable> Map<List<E>, E > foo(E e) { |
249 * class maptest <E> { |
284 * class maptest <E> { |
250 * Map<List<E>,E> getMap() { |
285 * Map<List<E>,E> getMap() { |
256 * } |
291 * } |
257 * Map<List<String>,String> shm = foo(new String("hello")); |
292 * Map<List<String>,String> shm = foo(new String("hello")); |
258 * } |
293 * } |
259 */ |
294 */ |
260 source = new String( source + |
295 source = new String( source + |
261 "// (repeating)annotations on type parameters of class, method return value in method. \n" + |
296 "// " + src.description + "\n" + |
262 "class "+ testname + "{\n" + |
297 "class "+ testname + "{\n" + |
263 " <E extends Comparable> Map<List<E>, E > foo(E e) {\n" + |
298 " <E extends Comparable> Map<List<E>, E > foo(E e) {\n" + |
264 " class maptest <E> {\n" + // inner class $1maptest |
299 " class maptest <E> {\n" + // inner class $1maptest |
265 " Map<List<E>,E> getMap() { \n" + |
300 " Map<List<E>,E> getMap() { \n" + |
266 " Map<List<E>,E> Em = new HashMap<List<_As_ _Bs_ _Ds_ E>,_As_ _Bs_ _Ds_ E>();\n" + |
301 " Map<List<E>,E> Em = new HashMap<List<_As_ _Bs_ _Ds_ E>,_As_ _Bs_ _Ds_ E>();\n" + |
267 " return Em;\n" + |
302 " return Em;\n" + |
268 " }\n" + |
303 " }\n" + |
269 " }\n" + |
304 " }\n" + |
270 " return new maptest<E>().getMap();\n" + |
305 " return new maptest<E>().getMap();\n" + |
271 " }\n" + |
306 " }\n" + |
272 " Map<List<String>,String> shm = foo(new String(\"hello\"));\n" + |
307 " Map<List<String>,String> shm = foo(new String(\"hello\"));\n" + |
273 "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) + |
308 "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) + |
274 "\n\n"; |
309 "\n\n"; |
275 hasInnerClass=true; |
310 hasInnerClass=true; |
276 innerClassname="$1maptest"; |
311 innerClassname="$1maptest"; |
277 break; |
312 break; |
278 |
313 case src4: // (repeating)annotations on field in anonymous class |
|
314 /* |
|
315 * class Test95{ |
|
316 * void mtest( Test95 t){ } |
|
317 * public void test() { |
|
318 * mtest( new Test95() { |
|
319 * @A @A @B @B String data2 = "test"; |
|
320 * }); |
|
321 * } |
|
322 * } |
|
323 */ |
|
324 source = new String( source + |
|
325 "// " + src.description + "\n" + |
|
326 "class "+ testname + "{\n" + |
|
327 " void mtest( "+ testname + " t){ }\n" + |
|
328 " public void test() {\n" + |
|
329 " mtest( new "+ testname + "() {\n" + |
|
330 " _As_ _Bs_ String data2 = \"test\";\n" + |
|
331 " });\n" + |
|
332 " }\n" + |
|
333 "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + |
|
334 "\n\n"; |
|
335 hasInnerClass=true; |
|
336 innerClassname="$1"; |
|
337 break; |
|
338 case src5: // (repeating)annotations on method in anonymous class |
|
339 /* |
|
340 * class Test120{ |
|
341 * void mtest( Test120 t){ } |
|
342 * public void test() { |
|
343 * mtest( new Test120() { |
|
344 * @A @B @A @B String m2(){return null;}; |
|
345 * }); |
|
346 * } |
|
347 */ |
|
348 source = new String( source + |
|
349 "// " + src.description + "\n" + |
|
350 "class "+ testname + "{\n" + |
|
351 " void mtest( "+ testname + " t){ }\n" + |
|
352 " public void test() {\n" + |
|
353 " mtest( new "+ testname + "() {\n" + |
|
354 " _As_ _Bs_ String m2(){return null;};\n" + |
|
355 " });\n" + |
|
356 " }\n" + |
|
357 "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + |
|
358 "\n\n"; |
|
359 hasInnerClass=true; |
|
360 innerClassname="$1"; |
|
361 break; |
279 } |
362 } |
280 return imports + source; |
363 return imports + source; |
281 } |
364 } |
282 } |
365 } |