author | jlahoda |
Wed, 27 Nov 2019 09:00:01 +0100 | |
changeset 59285 | 7799a51dbe30 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
15385 | 1 |
/* |
59285
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. |
15385 | 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 |
|
17578 | 26 |
* @bug 8005085 8005877 8004829 8005681 8006734 8006775 8006507 |
15385 | 27 |
* @summary Combinations of Target ElementTypes on (repeated)type annotations. |
30846 | 28 |
* @modules jdk.jdeps/com.sun.tools.classfile |
15385 | 29 |
*/ |
30 |
||
31 |
import com.sun.tools.classfile.*; |
|
32 |
import java.io.File; |
|
59285
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
33 |
import java.util.List; |
15385 | 34 |
|
35 |
public class CombinationsTargetTest2 extends ClassfileTestHelper { |
|
17578 | 36 |
|
59285
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
37 |
private static final String JDK_VERSION = |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
38 |
Integer.toString(Runtime.getRuntime().version().feature()); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
39 |
|
17578 | 40 |
// Test count helps identify test case in event of failure. |
15385 | 41 |
int testcount = 0; |
17578 | 42 |
|
19651 | 43 |
// Base test case template descriptions;true==annotations in code attribute. |
17578 | 44 |
enum srce { |
45 |
src1("(repeating) type annotations on on field in method body",true), |
|
46 |
src2("(repeating) type annotations on type parameters, bounds and type arguments", true), |
|
47 |
src3("(repeating) type annotations on type parameters of class, method return value in method", true), |
|
48 |
src4("(repeating) type annotations on field in anonymous class", false), |
|
19651 | 49 |
src5("(repeating) type annotations on field in anonymous class", false), |
50 |
src6("(repeating) type annotations on void method declaration", false), |
|
51 |
src7("(repeating) type annotations in use of instanceof", true), |
|
59285
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
52 |
src7p("(repeating) type annotations in use of instanceof with type test pattern", true), |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
53 |
src8("(repeating) type annotations in use of instanceof in method", true), |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
54 |
src8p("(repeating) type annotations in use of instanceof with type test pattern in method", true); |
17578 | 55 |
|
56 |
String description; |
|
57 |
Boolean local; |
|
58 |
||
59 |
srce(String desc, Boolean b) { |
|
60 |
this.description = this + ": " +desc; |
|
61 |
this.local = b; |
|
62 |
} |
|
63 |
} |
|
64 |
||
15385 | 65 |
|
66 |
String[] ETypes={"TYPE", "FIELD", "METHOD", "PARAMETER", "CONSTRUCTOR", |
|
67 |
"LOCAL_VARIABLE", "ANNOTATION_TYPE", "PACKAGE"}; |
|
68 |
||
69 |
// local class tests will have an inner class. |
|
70 |
Boolean hasInnerClass=false; |
|
71 |
String innerClassname=""; |
|
72 |
||
73 |
public static void main(String[] args) throws Exception { |
|
74 |
new CombinationsTargetTest2().run(); |
|
75 |
} |
|
76 |
||
77 |
void run() throws Exception { |
|
78 |
// Determines which repeat and order in source(ABMix). |
|
79 |
Boolean As= false, BDs=true, ABMix=false; |
|
80 |
int testrun=0; |
|
81 |
Boolean [][] bRepeat = new Boolean[][]{{false,false,false},//no repeats |
|
82 |
{true,false,false}, //repeat @A |
|
83 |
{false,true,false}, //repeat @B |
|
84 |
{true,true,false}, //repeat both |
|
85 |
{false,false,true} //repeat mix |
|
86 |
}; |
|
17578 | 87 |
|
15385 | 88 |
for(Boolean[] bCombo : bRepeat) { |
89 |
As=bCombo[0]; BDs=bCombo[1]; ABMix=bCombo[2]; |
|
90 |
for(String et : ETypes) { |
|
91 |
switch(et) { |
|
92 |
case "METHOD": |
|
17578 | 93 |
test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src1); |
94 |
test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1); |
|
95 |
test( 2, 0, 2, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src5); |
|
96 |
test( 0, 2, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src5); |
|
19651 | 97 |
test( 0, 0, 2, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src6); |
98 |
test( 0, 0, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src6); |
|
99 |
test( 2, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src7); |
|
100 |
test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src7); |
|
59285
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
101 |
test( 2, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src7p); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
102 |
test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src7p); |
19651 | 103 |
test( 4, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src8); |
104 |
test( 0, 4, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src8); |
|
59285
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
105 |
test( 4, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src8p); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
106 |
test( 0, 4, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src8p); |
15385 | 107 |
break; |
108 |
case "FIELD": |
|
17578 | 109 |
test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src1); |
110 |
test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src2); |
|
111 |
test( 6, 0, 0, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src3); |
|
112 |
test( 2, 0, 2, 0, As, BDs, ABMix, "CLASS", et, ++testrun, srce.src4); |
|
113 |
test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1); |
|
114 |
test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src2); |
|
115 |
test( 0, 6, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src3); |
|
116 |
test( 0, 2, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src4); |
|
15385 | 117 |
break; |
118 |
default:/*TYPE,PARAMETER,LOCAL_VARIABLE,ANNOTATION_TYPE,PACKAGE*/ |
|
17578 | 119 |
test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src4); |
120 |
test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src5); |
|
15385 | 121 |
break; |
122 |
} |
|
123 |
} |
|
124 |
} |
|
125 |
} |
|
126 |
||
127 |
public void test(int tinv, int tvis, int inv, int vis, Boolean Arepeats, |
|
128 |
Boolean BDrepeats, Boolean ABmix, String rtn, String et2, |
|
17578 | 129 |
Integer N, srce source) throws Exception { |
15385 | 130 |
++testcount; |
131 |
expected_tvisibles = tvis; |
|
132 |
expected_tinvisibles = tinv; |
|
133 |
expected_visibles = vis; |
|
134 |
expected_invisibles = inv; |
|
59285
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
135 |
extraOptions = List.of(); |
15385 | 136 |
File testFile = null; |
137 |
String tname="Test" + N.toString(); |
|
138 |
hasInnerClass=false; |
|
139 |
String testDef = "Test " + testcount + " parameters: tinv=" + tinv + |
|
140 |
", tvis=" + tvis + ", inv=" + inv + ", vis=" + vis + |
|
141 |
", Arepeats=" + Arepeats + ", BDrepeats=" + BDrepeats + |
|
142 |
", ABmix=" + ABmix + ", retention: " + rtn + ", anno2: " + |
|
17578 | 143 |
et2 + ", src=" + source + "\n " + source.description; |
15385 | 144 |
|
145 |
println(testDef); |
|
146 |
// Create test source and File. |
|
147 |
String sourceString = sourceString(tname, rtn, et2, Arepeats, |
|
148 |
BDrepeats, ABmix, source); |
|
149 |
testFile = writeTestFile(tname+".java", sourceString); |
|
150 |
// Compile test source and read classfile. |
|
151 |
File classFile = null; |
|
152 |
try { |
|
153 |
classFile = compile(testFile); |
|
154 |
} catch (Error err) { |
|
155 |
System.err.println("Failed compile. Source:\n" + sourceString); |
|
156 |
throw err; |
|
157 |
} |
|
158 |
//if sourcString() set hasInnerClass it also set innerClassname. |
|
159 |
if(hasInnerClass) { |
|
160 |
StringBuffer sb = new StringBuffer(classFile.getAbsolutePath()); |
|
161 |
classFile=new File(sb.insert(sb.lastIndexOf(".class"),innerClassname).toString()); |
|
17578 | 162 |
println("classfile: " + classFile.getAbsolutePath()); |
15385 | 163 |
} |
164 |
ClassFile cf = ClassFile.read(classFile); |
|
165 |
||
166 |
//Test class,fields and method counts. |
|
167 |
test(cf); |
|
168 |
||
169 |
for (Field f : cf.fields) { |
|
17578 | 170 |
if(source.local) |
171 |
test(cf, f, true); |
|
172 |
else |
|
173 |
test(cf,f); |
|
15385 | 174 |
} |
175 |
for (Method m: cf.methods) { |
|
17578 | 176 |
if(source.local) |
177 |
test(cf, m, true); |
|
178 |
else |
|
179 |
test(cf, m); |
|
15385 | 180 |
} |
181 |
countAnnotations(); |
|
182 |
if (errors > 0) { |
|
183 |
System.err.println( testDef ); |
|
184 |
System.err.println( "Source:\n" + sourceString ); |
|
185 |
throw new Exception( errors + " errors found" ); |
|
186 |
} |
|
187 |
println("Pass"); |
|
188 |
} |
|
189 |
||
190 |
// Source for test cases |
|
191 |
String sourceString(String testname, String retentn, String annot2, |
|
192 |
Boolean Arepeats, Boolean BDrepeats, Boolean ABmix, |
|
17578 | 193 |
srce src) { |
15385 | 194 |
|
195 |
String As = "@A", Bs = "@B", Ds = "@D"; |
|
196 |
if(Arepeats) As = "@A @A"; |
|
197 |
if(BDrepeats) { |
|
198 |
Bs = "@B @B"; |
|
199 |
Ds = "@D @D"; |
|
200 |
} |
|
201 |
if(ABmix) { As = "@A @B"; Bs = "@A @B"; Ds = "@D @D"; } |
|
202 |
||
203 |
// Source to check for TYPE_USE and TYPE_PARAMETER annotations. |
|
204 |
// Source base (annotations) is same for all test cases. |
|
205 |
String source = new String(); |
|
206 |
String imports = new String("import java.lang.annotation.*; \n" + |
|
207 |
"import static java.lang.annotation.RetentionPolicy.*; \n" + |
|
208 |
"import static java.lang.annotation.ElementType.*; \n" + |
|
209 |
"import java.util.List; \n" + |
|
210 |
"import java.util.HashMap; \n" + |
|
211 |
"import java.util.Map; \n\n"); |
|
212 |
||
213 |
String sourceBase = new String("@Retention("+retentn+")\n" + |
|
214 |
"@Target({TYPE_USE,_OTHER_})\n" + |
|
15554
eea02af8112f
8007313: Remove use of {ContainerFor/ContainedBy} from langtools
darcy
parents:
15385
diff
changeset
|
215 |
"@Repeatable( AC.class )\n" + |
15385 | 216 |
"@interface A { }\n\n" + |
217 |
||
218 |
"@Retention("+retentn+")\n" + |
|
219 |
"@Target({TYPE_USE,_OTHER_})\n" + |
|
220 |
"@interface AC { A[] value(); }\n\n" + |
|
221 |
||
222 |
"@Retention("+retentn+")\n" + |
|
223 |
"@Target({TYPE_USE,_OTHER_})\n" + |
|
15554
eea02af8112f
8007313: Remove use of {ContainerFor/ContainedBy} from langtools
darcy
parents:
15385
diff
changeset
|
224 |
"@Repeatable( BC.class )\n" + |
15385 | 225 |
"@interface B { }\n\n" + |
226 |
||
227 |
"@Retention("+retentn+")\n" + |
|
228 |
"@Target({TYPE_USE,_OTHER_})\n" + |
|
229 |
"@interface BC { B[] value(); } \n\n" + |
|
230 |
||
231 |
"@Retention("+retentn+")\n" + |
|
232 |
"@Target({TYPE_USE,TYPE_PARAMETER,_OTHER_})\n" + |
|
15554
eea02af8112f
8007313: Remove use of {ContainerFor/ContainedBy} from langtools
darcy
parents:
15385
diff
changeset
|
233 |
"@Repeatable(DC.class)\n" + |
15385 | 234 |
"@interface D { }\n\n" + |
235 |
||
236 |
"@Retention("+retentn+")\n" + |
|
237 |
"@Target({TYPE_USE,TYPE_PARAMETER,_OTHER_})\n" + |
|
238 |
"@interface DC { D[] value(); }\n\n"); |
|
239 |
||
240 |
// Test case sources with sample generated source |
|
241 |
switch(src) { |
|
17578 | 242 |
case src1: // (repeating) type annotations on field in method body |
15385 | 243 |
/* |
244 |
* class Test1 { |
|
245 |
* Test1(){} |
|
246 |
* // type usage in method body |
|
247 |
* String test(Test1 this, String param, String ... vararg) { |
|
248 |
* @A @B |
|
249 |
* Object o = new @A @B String @A @B [3]; |
|
250 |
* return (@A @B String) null; |
|
251 |
* }} |
|
252 |
*/ |
|
253 |
source = new String( |
|
17578 | 254 |
"// " + src.description + "\n" + |
255 |
"class " + testname + " {\n" + |
|
256 |
"" + testname +"(){} \n" + |
|
257 |
"// type usage in method body \n" + |
|
258 |
"String test("+testname+" this, " + |
|
259 |
"String param, String ... vararg) { \n" + |
|
260 |
" _As_ _Bs_\n Object o = new _As_ _Bs_ String _As_ _Bs_ [3]; \n" + |
|
261 |
" return (_As_ _Bs_ String) null; \n" + |
|
262 |
"} \n" + |
|
263 |
"} \n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + |
|
264 |
"\n\n"; |
|
265 |
break; |
|
266 |
case src2: // (repeating) annotations on type parameters, bounds and type arguments in new statement. |
|
15385 | 267 |
/* |
268 |
* class Test2<T extends Object> { |
|
269 |
* Map<List<String>, Integer> map = |
|
270 |
* new HashMap<@A @B List<@A @B String>, @A @B Integer>(); |
|
271 |
* Map<List<String>, Integer> map2 = new @A @B HashMap<>(); |
|
272 |
* String test(Test2<T> this) { return null;} |
|
273 |
* <T> String genericMethod(T t) { return null; } |
|
274 |
* } |
|
275 |
*/ |
|
276 |
source = new String( source + |
|
17578 | 277 |
"// " + src.description + "\n" + |
278 |
"class " + testname + "<T extends Object> {\n" + |
|
279 |
" Map<List<String>, Integer> map =\n" + |
|
280 |
" new HashMap<_As_ _Bs_ List<_As_ _Bs_ String>, _As_ _Bs_ Integer>();\n" + |
|
281 |
" Map<List<String>, Integer> map2 = new _As_ _Bs_ HashMap<>();\n" + |
|
282 |
" String test(" + testname + "<T> this) { return null;}\n" + |
|
283 |
" <T> String genericMethod(T t) { return null; }\n" + |
|
284 |
"}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + |
|
285 |
"\n\n"; |
|
286 |
break; |
|
287 |
case src3: // (repeating)annotations on type parameters of class, method return value in method. |
|
15385 | 288 |
/* |
289 |
* class Test3{ |
|
290 |
* <E extends Comparable> Map<List<E>, E > foo(E e) { |
|
291 |
* class maptest <E> { |
|
292 |
* Map<List<E>,E> getMap() { |
|
293 |
* Map<List<E>,E> Em = new HashMap<List<@A @B @D E>,@A @B @D E>(); |
|
294 |
* return Em; |
|
295 |
* } |
|
296 |
* } |
|
297 |
* return new maptest<E>().getMap(); |
|
298 |
* } |
|
299 |
* Map<List<String>,String> shm = foo(new String("hello")); |
|
300 |
* } |
|
301 |
*/ |
|
302 |
source = new String( source + |
|
17578 | 303 |
"// " + src.description + "\n" + |
304 |
"class "+ testname + "{\n" + |
|
305 |
" <E extends Comparable> Map<List<E>, E > foo(E e) {\n" + |
|
306 |
" class maptest <E> {\n" + // inner class $1maptest |
|
307 |
" Map<List<E>,E> getMap() { \n" + |
|
308 |
" Map<List<E>,E> Em = new HashMap<List<_As_ _Bs_ _Ds_ E>,_As_ _Bs_ _Ds_ E>();\n" + |
|
309 |
" return Em;\n" + |
|
310 |
" }\n" + |
|
311 |
" }\n" + |
|
312 |
" return new maptest<E>().getMap();\n" + |
|
313 |
" }\n" + |
|
314 |
" Map<List<String>,String> shm = foo(new String(\"hello\"));\n" + |
|
315 |
"}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) + |
|
316 |
"\n\n"; |
|
317 |
hasInnerClass=true; |
|
318 |
innerClassname="$1maptest"; |
|
319 |
break; |
|
320 |
case src4: // (repeating)annotations on field in anonymous class |
|
321 |
/* |
|
322 |
* class Test95{ |
|
323 |
* void mtest( Test95 t){ } |
|
324 |
* public void test() { |
|
325 |
* mtest( new Test95() { |
|
326 |
* @A @A @B @B String data2 = "test"; |
|
327 |
* }); |
|
328 |
* } |
|
329 |
* } |
|
330 |
*/ |
|
331 |
source = new String( source + |
|
332 |
"// " + src.description + "\n" + |
|
333 |
"class "+ testname + "{\n" + |
|
334 |
" void mtest( "+ testname + " t){ }\n" + |
|
335 |
" public void test() {\n" + |
|
336 |
" mtest( new "+ testname + "() {\n" + |
|
337 |
" _As_ _Bs_ String data2 = \"test\";\n" + |
|
338 |
" });\n" + |
|
339 |
" }\n" + |
|
340 |
"}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + |
|
341 |
"\n\n"; |
|
342 |
hasInnerClass=true; |
|
343 |
innerClassname="$1"; |
|
344 |
break; |
|
345 |
case src5: // (repeating)annotations on method in anonymous class |
|
346 |
/* |
|
347 |
* class Test120{ |
|
348 |
* void mtest( Test120 t){ } |
|
349 |
* public void test() { |
|
350 |
* mtest( new Test120() { |
|
351 |
* @A @B @A @B String m2(){return null;}; |
|
352 |
* }); |
|
353 |
* } |
|
354 |
*/ |
|
355 |
source = new String( source + |
|
356 |
"// " + src.description + "\n" + |
|
357 |
"class "+ testname + "{\n" + |
|
358 |
" void mtest( "+ testname + " t){ }\n" + |
|
359 |
" public void test() {\n" + |
|
360 |
" mtest( new "+ testname + "() {\n" + |
|
361 |
" _As_ _Bs_ String m2(){return null;};\n" + |
|
362 |
" });\n" + |
|
363 |
" }\n" + |
|
364 |
"}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + |
|
365 |
"\n\n"; |
|
366 |
hasInnerClass=true; |
|
367 |
innerClassname="$1"; |
|
368 |
break; |
|
19651 | 369 |
case src6: // (repeating)annotations on void method declaration |
370 |
/* |
|
371 |
* class Test95{ |
|
372 |
* @A @A @B @B public void test() { }; |
|
373 |
* } |
|
374 |
*/ |
|
375 |
source = new String( source + |
|
376 |
"// " + src.description + "\n" + |
|
377 |
"class "+ testname + "{\n" + |
|
378 |
" _As_ _Bs_ public void test() { }\n" + |
|
379 |
"}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + |
|
380 |
"\n\n"; |
|
381 |
hasInnerClass=false; |
|
382 |
break; |
|
383 |
case src7: // (repeating) type annotations in use of instanceof |
|
384 |
/* |
|
385 |
* class Test10{ |
|
386 |
* String data = "test"; |
|
387 |
* boolean dataIsString = ( data instanceof @A @B @A @B String); |
|
388 |
* } |
|
389 |
*/ |
|
390 |
source = new String( source + |
|
391 |
"// " + src.description + "\n" + |
|
392 |
"class "+ testname + "{\n" + |
|
393 |
" String data = \"test\";\n" + |
|
394 |
" boolean dataIsString = ( data instanceof _As_ _Bs_ String);\n" + |
|
395 |
"}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + |
|
396 |
"\n\n"; |
|
397 |
hasInnerClass=false; |
|
398 |
break; |
|
59285
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
399 |
case src7p: // (repeating) type annotations in use of instanceof with type test pattern |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
400 |
/* |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
401 |
* class Test10{ |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
402 |
* String data = "test"; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
403 |
* boolean dataIsString = ( data instanceof @A @B @A @B String str); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
404 |
* } |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
405 |
*/ |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
406 |
source = new String( source + |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
407 |
"// " + src.description + "\n" + |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
408 |
"class "+ testname + "{\n" + |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
409 |
" String data = \"test\";\n" + |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
410 |
" boolean dataIsString = ( data instanceof _As_ _Bs_ String str && str.isEmpty());\n" + |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
411 |
"}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
412 |
"\n\n"; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
413 |
extraOptions = List.of("--enable-preview", |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
414 |
"-source", JDK_VERSION); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
415 |
hasInnerClass=false; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
416 |
break; |
19651 | 417 |
case src8: // (repeating) type annotations in use of instanceof |
418 |
/* |
|
419 |
* class Test20{ |
|
420 |
* String data = "test"; |
|
421 |
* Boolean isString() { |
|
422 |
* if( data instanceof @A @B @A @B String ) |
|
423 |
* return true; |
|
424 |
* else |
|
425 |
* return( data instanceof @A @B @A @B String ); |
|
426 |
* } |
|
427 |
* } |
|
428 |
*/ |
|
429 |
source = new String( source + |
|
430 |
"// " + src.description + "\n" + |
|
431 |
"class "+ testname + "{\n" + |
|
432 |
" String data = \"test\";\n" + |
|
433 |
" Boolean isString() { \n" + |
|
434 |
" if( data instanceof _As_ _Bs_ String )\n" + |
|
435 |
" return true;\n" + |
|
436 |
" else\n" + |
|
437 |
" return( data instanceof _As_ _Bs_ String );\n" + |
|
438 |
" }\n" + |
|
439 |
"}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + |
|
440 |
"\n\n"; |
|
441 |
hasInnerClass=false; |
|
442 |
break; |
|
59285
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
443 |
case src8p: // (repeating) type annotations in use of instanceof with type test pattern |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
444 |
/* |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
445 |
* class Test20{ |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
446 |
* String data = "test"; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
447 |
* Boolean isString() { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
448 |
* if( data instanceof @A @B @A @B String ) |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
449 |
* return true; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
450 |
* else |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
451 |
* return( data instanceof @A @B @A @B String ); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
452 |
* } |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
453 |
* } |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
454 |
*/ |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
455 |
source = new String( source + |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
456 |
"// " + src.description + "\n" + |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
457 |
"class "+ testname + "{\n" + |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
458 |
" String data = \"test\";\n" + |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
459 |
" Boolean isString() { \n" + |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
460 |
" if( data instanceof _As_ _Bs_ String str)\n" + |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
461 |
" return true;\n" + |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
462 |
" else\n" + |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
463 |
" return( data instanceof _As_ _Bs_ String str && str.isEmpty());\n" + |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
464 |
" }\n" + |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
465 |
"}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
466 |
"\n\n"; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
467 |
extraOptions = List.of("--enable-preview", |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
468 |
"-source", JDK_VERSION); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
469 |
hasInnerClass=false; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
47216
diff
changeset
|
470 |
break; |
19651 | 471 |
|
15385 | 472 |
} |
473 |
return imports + source; |
|
474 |
} |
|
475 |
} |