1
1
/*
2
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -215,82 +215,88 @@ void testConstantTest() throws Exception {
215
215
216
216
@ Test
217
217
void testAnnotations () throws Exception {
218
- doPrintElementTest ("package t;" +
219
- "import java.lang.annotation.*;" +
220
- "public @Visible @Invisible class T { public void extra() { } }" +
221
- "@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
222
- "@Retention(RetentionPolicy.CLASS) @interface Invisible { }" ,
223
- "package t;" +
224
- "import java.lang.annotation.*;" +
225
- "public @Visible @Invisible class T { }" +
226
- "@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
227
- "@Retention(RetentionPolicy.CLASS) @interface Invisible { }" ,
228
- "t.T" ,
229
- "package t;\n \n " +
230
- "@t.Invisible\n " +
231
- "@t.Visible\n " +
232
- "public class T {\n \n " +
233
- " public T();\n \n " +
234
- " public void extra();\n " +
235
- "}\n " ,
236
- "t.Visible" ,
237
- "package t;\n \n " +
238
- "@java.lang.annotation.Retention(RUNTIME)\n " +
239
- "@interface Visible {\n " +
240
- "}\n " );
241
- doPrintElementTest ("package t;" +
242
- "import java.lang.annotation.*;" +
243
- "import java.util.*;" +
244
- "public class T {" +
245
- " public void test(int h, @Invisible int i, @Visible List<String> j, int k) { }" +
246
- "}" +
247
- "@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
248
- "@Retention(RetentionPolicy.CLASS) @interface Invisible { }" ,
249
- "package t;" +
250
- "import java.lang.annotation.*;" +
251
- "import java.util.*;" +
252
- "public class T {" +
253
- " public void test(int h, @Invisible int i, @Visible List<String> j, int k) { }" +
254
- " public void extra() { }" +
255
- "}" +
256
- "@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
257
- "@Retention(RetentionPolicy.CLASS) @interface Invisible { }" ,
258
- "t.T" ,
259
- "package t;\n \n " +
260
- "public class T {\n \n " +
261
- " public T();\n \n " +
262
- " public void test(int arg0,\n " +
263
- " @t.Invisible int arg1,\n " +
264
- " @t.Visible java.util.List<java.lang.String> arg2,\n " +
265
- " int arg3);\n " +
266
- "}\n " ,
267
- "t.Visible" ,
268
- "package t;\n \n " +
269
- "@java.lang.annotation.Retention(RUNTIME)\n " +
270
- "@interface Visible {\n " +
271
- "}\n " );
272
- doPrintElementTest ("package t;" +
273
- "import java.lang.annotation.*;" +
274
- "public class T {" +
275
- " public void test(@Ann(v=\" url\" , dv=\" \\ \" \\ \" \" ) String str) { }" +
276
- "}" +
277
- "@Retention(RetentionPolicy.RUNTIME) @interface Ann {" +
278
- " public String v();" +
279
- " public String dv();" +
280
- "}" ,
281
- "package t;" +
282
- "public class T { }" ,
283
- "t.T" ,
284
- "package t;\n \n " +
285
- "public class T {\n \n " +
286
- " public T();\n \n " +
287
- " public void test(@t.Ann(dv=\" \\ \" \\ \" \" , v=\" url\" ) java.lang.String arg0);\n " +
288
- "}\n " ,
289
- "t.T" ,
290
- "package t;\n \n " +
291
- "public class T {\n \n " +
292
- " public T();\n " +
293
- "}\n " );
218
+ Set <String > extraAnnotations = Set .of ("Ljava/lang/annotation/Retention;" );
219
+ CreateSymbols .HARDCODED_ANNOTATIONS .addAll (extraAnnotations );
220
+ try {
221
+ doPrintElementTest ("package t;" +
222
+ "import java.lang.annotation.*;" +
223
+ "public @Visible @Invisible class T { public void extra() { } }" +
224
+ "@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
225
+ "@Retention(RetentionPolicy.CLASS) @interface Invisible { }" ,
226
+ "package t;" +
227
+ "import java.lang.annotation.*;" +
228
+ "public @Visible @Invisible class T { }" +
229
+ "@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
230
+ "@Retention(RetentionPolicy.CLASS) @interface Invisible { }" ,
231
+ "t.T" ,
232
+ "package t;\n \n " +
233
+ "@t.Invisible\n " +
234
+ "@t.Visible\n " +
235
+ "public class T {\n \n " +
236
+ " public T();\n \n " +
237
+ " public void extra();\n " +
238
+ "}\n " ,
239
+ "t.Visible" ,
240
+ "package t;\n \n " +
241
+ "@java.lang.annotation.Retention(RUNTIME)\n " +
242
+ "@interface Visible {\n " +
243
+ "}\n " );
244
+ doPrintElementTest ("package t;" +
245
+ "import java.lang.annotation.*;" +
246
+ "import java.util.*;" +
247
+ "public class T {" +
248
+ " public void test(int h, @Invisible int i, @Visible List<String> j, int k) { }" +
249
+ "}" +
250
+ "@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
251
+ "@Retention(RetentionPolicy.CLASS) @interface Invisible { }" ,
252
+ "package t;" +
253
+ "import java.lang.annotation.*;" +
254
+ "import java.util.*;" +
255
+ "public class T {" +
256
+ " public void test(int h, @Invisible int i, @Visible List<String> j, int k) { }" +
257
+ " public void extra() { }" +
258
+ "}" +
259
+ "@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
260
+ "@Retention(RetentionPolicy.CLASS) @interface Invisible { }" ,
261
+ "t.T" ,
262
+ "package t;\n \n " +
263
+ "public class T {\n \n " +
264
+ " public T();\n \n " +
265
+ " public void test(int arg0,\n " +
266
+ " @t.Invisible int arg1,\n " +
267
+ " @t.Visible java.util.List<java.lang.String> arg2,\n " +
268
+ " int arg3);\n " +
269
+ "}\n " ,
270
+ "t.Visible" ,
271
+ "package t;\n \n " +
272
+ "@java.lang.annotation.Retention(RUNTIME)\n " +
273
+ "@interface Visible {\n " +
274
+ "}\n " );
275
+ doPrintElementTest ("package t;" +
276
+ "import java.lang.annotation.*;" +
277
+ "public class T {" +
278
+ " public void test(@Ann(v=\" url\" , dv=\" \\ \" \\ \" \" ) String str) { }" +
279
+ "}" +
280
+ "@Retention(RetentionPolicy.RUNTIME) @interface Ann {" +
281
+ " public String v();" +
282
+ " public String dv();" +
283
+ "}" ,
284
+ "package t;" +
285
+ "public class T { }" ,
286
+ "t.T" ,
287
+ "package t;\n \n " +
288
+ "public class T {\n \n " +
289
+ " public T();\n \n " +
290
+ " public void test(@t.Ann(dv=\" \\ \" \\ \" \" , v=\" url\" ) java.lang.String arg0);\n " +
291
+ "}\n " ,
292
+ "t.T" ,
293
+ "package t;\n \n " +
294
+ "public class T {\n \n " +
295
+ " public T();\n " +
296
+ "}\n " );
297
+ } finally {
298
+ CreateSymbols .HARDCODED_ANNOTATIONS .removeAll (extraAnnotations );
299
+ }
294
300
}
295
301
296
302
@ Test
@@ -360,11 +366,70 @@ void testGenerification() throws Exception {
360
366
Expect .SUCCESS );
361
367
}
362
368
369
+ @ Test
370
+ void testClearMissingAnnotations () throws Exception {
371
+ doPrintElementTest (new String [] {
372
+ """
373
+ package t;
374
+ import t.impl.HC;
375
+ import t.impl.HR;
376
+ @HC @HR public class T {
377
+ @HC @HR public static final int i = 0;
378
+ @HC @HR public void t() {}
379
+ }
380
+ """ ,
381
+ """
382
+ package t.impl;
383
+ import java.lang.annotation.*;
384
+ @Retention(RetentionPolicy.CLASS)
385
+ public @interface HC {
386
+ }
387
+ """ ,
388
+ """
389
+ package t.impl;
390
+ import java.lang.annotation.*;
391
+ @Retention(RetentionPolicy.RUNTIME)
392
+ public @interface HR {
393
+ }
394
+ """
395
+ },
396
+ new String [] {
397
+ """
398
+ package t;
399
+ public class T {
400
+ public static final int i = 0;
401
+ }
402
+ """
403
+ },
404
+ "t.T" ,
405
+ """
406
+ package t;
407
+
408
+ public class T {
409
+ public static final int i = 0;
410
+
411
+ public T();
412
+
413
+ public void t();
414
+ }
415
+ """ ,
416
+ "t.T" ,
417
+ """
418
+ package t;
419
+
420
+ public class T {
421
+ public static final int i = 0;
422
+
423
+ public T();
424
+ }
425
+ """ );
426
+ }
427
+
363
428
int i = 0 ;
364
429
365
430
void doTest (String code7 , String code8 , String testCode , Expect result7 , Expect result8 ) throws Exception {
366
431
ToolBox tb = new ToolBox ();
367
- Path classes = prepareVersionedCTSym (code7 , code8 );
432
+ Path classes = prepareVersionedCTSym (new String [] { code7 }, new String [] { code8 } );
368
433
Path output = classes .getParent ();
369
434
Path scratch = output .resolve ("scratch" );
370
435
@@ -392,6 +457,10 @@ private static String computeClassPath(Path classes, String version) throws IOEx
392
457
}
393
458
394
459
void doPrintElementTest (String code7 , String code8 , String className7 , String printed7 , String className8 , String printed8 ) throws Exception {
460
+ doPrintElementTest (new String [] {code7 }, new String [] {code8 }, className7 , printed7 , className8 , printed8 );
461
+ }
462
+
463
+ void doPrintElementTest (String [] code7 , String [] code8 , String className7 , String printed7 , String className8 , String printed8 ) throws Exception {
395
464
ToolBox tb = new ToolBox ();
396
465
Path classes = prepareVersionedCTSym (code7 , code8 );
397
466
Path output = classes .getParent ();
@@ -419,7 +488,7 @@ void doPrintElementTest(String code7, String code8, String className7, String pr
419
488
}
420
489
421
490
void doTestEquivalence (String code7 , String code8 , String testClass ) throws Exception {
422
- Path classes = prepareVersionedCTSym (code7 , code8 );
491
+ Path classes = prepareVersionedCTSym (new String [] { code7 }, new String [] { code8 } );
423
492
Path classfile = classes .resolve ("78" ).resolve ("java.base" ).resolve (testClass .replace ('.' , '/' ) + ".class" );
424
493
425
494
if (!Files .isReadable (classfile )) {
@@ -576,7 +645,7 @@ void doTestIncluded(String code, String... includedClasses) throws Exception {
576
645
boolean oldIncludeAll = includeAll ;
577
646
try {
578
647
includeAll = false ;
579
- Path classes = prepareVersionedCTSym (code , "package other; public class Other {}" );
648
+ Path classes = prepareVersionedCTSym (new String [] { code }, new String [] { "package other; public class Other {}" } );
580
649
Path root = classes .resolve ("7" ).resolve ("java.base" );
581
650
try (Stream <Path > classFiles = Files .walk (root )) {
582
651
Set <String > names = classFiles .map (p -> root .relativize (p ))
@@ -595,7 +664,7 @@ void doTestIncluded(String code, String... includedClasses) throws Exception {
595
664
}
596
665
}
597
666
598
- Path prepareVersionedCTSym (String code7 , String code8 ) throws Exception {
667
+ Path prepareVersionedCTSym (String [] code7 , String [] code8 ) throws Exception {
599
668
String testClasses = System .getProperty ("test.classes" );
600
669
Path output = Paths .get (testClasses , "test-data" + i ++);
601
670
deleteRecursively (output );
@@ -694,6 +763,7 @@ List<String> collectClassFile(Path root) throws IOException {
694
763
return files .filter (p -> Files .isRegularFile (p ))
695
764
.filter (p -> p .getFileName ().toString ().endsWith (".class" ))
696
765
.map (p -> root .relativize (p ).toString ())
766
+ .filter (p -> !p .contains ("impl" ))
697
767
.collect (Collectors .toList ());
698
768
}
699
769
}
0 commit comments