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 8072480 8277106 8331027
27 * @summary Unit test for CreateSymbols
28 * @modules java.compiler
29 * jdk.compiler/com.sun.tools.javac.api
30 * jdk.compiler/com.sun.tools.javac.jvm
31 * jdk.compiler/com.sun.tools.javac.main
32 * jdk.compiler/com.sun.tools.javac.util
33 * @clean *
34 * @run main/othervm CreateSymbolsTest
35 */
36
37 import java.io.File;
38 import java.io.InputStream;
39 import java.io.Writer;
40 import java.lang.annotation.Retention;
41 import java.lang.annotation.RetentionPolicy;
42 import java.lang.classfile.ClassFile;
43 import java.lang.classfile.ClassModel;
44 import java.lang.classfile.attribute.ModuleAttribute;
45 import java.lang.classfile.attribute.ModulePackagesAttribute;
46 import java.lang.constant.PackageDesc;
47 import java.lang.reflect.Method;
48 import java.util.Arrays;
49 import java.util.ArrayList;
50 import java.util.HashMap;
51 import java.util.List;
52 import java.util.Map;
53 import java.io.IOException;
54 import java.io.OutputStream;
55 import java.nio.charset.StandardCharsets;
56 import java.nio.file.DirectoryStream;
57 import java.nio.file.FileVisitResult;
58 import java.nio.file.FileVisitor;
59 import java.nio.file.Files;
60 import java.nio.file.Path;
61 import java.nio.file.Paths;
62 import java.nio.file.attribute.BasicFileAttributes;
63 import java.util.Enumeration;
64 import java.util.HashSet;
65 import java.util.Set;
66 import java.util.jar.JarEntry;
67 import java.util.jar.JarFile;
68 import java.util.stream.Collectors;
69 import java.util.stream.Stream;
70 import toolbox.JavacTask;
71 import toolbox.Task;
72 import toolbox.Task.Expect;
73 import toolbox.ToolBox;
74 import build.tools.symbolgenerator.CreateSymbols;
75 import build.tools.symbolgenerator.CreateSymbols.ClassDescription;
76 import build.tools.symbolgenerator.CreateSymbols.ClassList;
77 import build.tools.symbolgenerator.CreateSymbols.ExcludeIncludeList;
78 import build.tools.symbolgenerator.CreateSymbols.VersionDescription;
79 import java.io.UncheckedIOException;
80 import java.lang.classfile.attribute.ModuleMainClassAttribute;
81 import java.lang.constant.ClassDesc;
82 import java.util.Objects;
83 import java.util.function.Consumer;
84
85 public class CreateSymbolsTestImpl {
86
87 static final String CREATE_SYMBOLS_NAME = "symbolgenerator.CreateSymbols";
88
89 public static void main(String... args) throws Exception {
90 new CreateSymbolsTestImpl().doTest();
91 }
92
93 void doTest() throws Exception {
94 boolean testRun = false;
95 for (Method m : CreateSymbolsTestImpl.class.getDeclaredMethods()) {
96 if (m.isAnnotationPresent(Test.class)) {
97 m.invoke(this);
98 testRun = true;
99 }
100 }
101 if (!testRun) {
102 throw new IllegalStateException("No tests found.");
103 }
104 }
105
106 @Test
107 void testMethodRemoved() throws Exception {
108 doTest("package t; public class T { public void m() { } }",
109 "package t; public class T { }",
110 "package t; public class Test { { T t = null; t.m(); } }",
111 Expect.SUCCESS,
112 Expect.FAIL);
113 doTest("package t; public class T { public void b() { } public void m() { } public void a() { } }",
114 "package t; public class T { public void b() { } public void a() { } }",
115 "package t; public class Test { { T t = null; t.b(); t.a(); } }",
116 Expect.SUCCESS,
117 Expect.SUCCESS);
118 //with additional attribute (need to properly skip the member):
119 doTest("package t; public class T { public void m() throws IllegalStateException { } public void a() { } }",
120 "package t; public class T { public void a() { } }",
121 "package t; public class Test { { T t = null; t.a(); } }",
122 Expect.SUCCESS,
123 Expect.SUCCESS);
124 }
125
842 .getOutput(Task.OutputKind.DIRECT)
843 .replaceAll("\\R", "\n");
844
845 if (!out.equals(expectedFailure)) {
846 throw new AssertionError("out=" + out + "; expected=" + expectedFailure);
847 }
848 }
849 }
850
851 @Test
852 void testExtendsInternalData1() throws Exception {
853 doTestData("""
854 module name m
855 header exports api extraModulePackages nonapi requires name\\u0020;java.base\\u0020;flags\\u0020;8000\\u0020;version\\u0020;0 flags 8000
856
857 class name api/Ann
858 header extends java/lang/Object implements java/lang/annotation/Annotation flags 2601
859
860 class name api/Api
861 header extends nonapi/Impl$Nested$Exp flags 21
862 innerclass innerClass nonapi/Impl$Nested outerClass nonapi/Impl innerClassName Nested flags 9
863 innerclass innerClass nonapi/Impl$Nested$Exp outerClass nonapi/Impl$Nested innerClassName Exp flags 9
864 method name <init> descriptor ()V flags 1
865
866 class name nonapi/Impl
867 header extends java/lang/Object nestMembers nonapi/Impl$Nested,nonapi/Impl$Nested$Exp flags 21
868 innerclass innerClass nonapi/Impl$Nested outerClass nonapi/Impl innerClassName Nested flags 9
869 innerclass innerClass nonapi/Impl$Nested$Exp outerClass nonapi/Impl$Nested innerClassName Exp flags 9
870 field name C descriptor Ljava/lang/String; constantValue flags 19
871 method name <init> descriptor ()V flags 1
872 method name test descriptor ()V flags 1
873
874 class name nonapi/Impl$Nested
875 header extends java/lang/Object nestHost nonapi/Impl flags 21 classAnnotations @Lapi/Ann;
876 innerclass innerClass nonapi/Impl$Nested outerClass nonapi/Impl innerClassName Nested flags 9
877 innerclass innerClass nonapi/Impl$Nested$Exp outerClass nonapi/Impl$Nested innerClassName Exp flags 9
878 method name <init> descriptor ()V flags 1
879
880 class name nonapi/Impl$Nested$Exp
881 header extends nonapi/Impl$Nested implements java/lang/Runnable nestHost nonapi/Impl flags 21
882 innerclass innerClass nonapi/Impl$Nested outerClass nonapi/Impl innerClassName Nested flags 9
883 innerclass innerClass nonapi/Impl$Nested$Exp outerClass nonapi/Impl$Nested innerClassName Exp flags 9
884 method name <init> descriptor ()V flags 1
885 method name run descriptor ()V flags 1
886 method name get descriptor ()Lnonapi/Impl$OtherNested; flags 1
887
888 """,
889 """
890 module m {
891 exports api;
892 exports nonapi to java.base;
893 }
894 """,
895 """
896 package api;
897 import nonapi.Impl;
898 public class Api extends Impl.Nested.Exp {
899 }
900 """,
901 """
902 package api;
903 public @interface Ann {
1335
1336 void deleteRecursively(Path dir) throws IOException {
1337 Files.walkFileTree(dir, new FileVisitor<Path>() {
1338 @Override
1339 public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
1340 return FileVisitResult.CONTINUE;
1341 }
1342 @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
1343 Files.delete(file);
1344 return FileVisitResult.CONTINUE;
1345 }
1346 @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
1347 return FileVisitResult.CONTINUE;
1348 }
1349 @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
1350 Files.delete(dir);
1351 return FileVisitResult.CONTINUE;
1352 }
1353 });
1354 }
1355
1356 @Retention(RetentionPolicy.RUNTIME)
1357 @interface Test {
1358 }
1359 }
|
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 8072480 8277106 8331027
27 * @summary Unit test for CreateSymbols
28 * @modules java.compiler
29 * jdk.compiler/com.sun.tools.javac.api
30 * jdk.compiler/com.sun.tools.javac.jvm
31 * jdk.compiler/com.sun.tools.javac.main
32 * jdk.compiler/com.sun.tools.javac.util
33 * @clean *
34 * @run junit/othervm CreateSymbolsTest
35 */
36
37 import java.io.File;
38 import java.io.InputStream;
39 import java.io.Writer;
40 import java.lang.annotation.Retention;
41 import java.lang.annotation.RetentionPolicy;
42 import java.lang.classfile.ClassFile;
43 import java.lang.classfile.ClassModel;
44 import java.lang.classfile.attribute.ModuleAttribute;
45 import java.lang.classfile.attribute.ModulePackagesAttribute;
46 import java.lang.constant.PackageDesc;
47 import java.lang.reflect.Method;
48 import java.util.Arrays;
49 import java.util.ArrayList;
50 import java.util.HashMap;
51 import java.util.List;
52 import java.util.Map;
53 import java.io.IOException;
54 import java.io.OutputStream;
55 import java.nio.charset.StandardCharsets;
56 import java.nio.file.DirectoryStream;
57 import java.nio.file.FileVisitResult;
58 import java.nio.file.FileVisitor;
59 import java.nio.file.Files;
60 import java.nio.file.Path;
61 import java.nio.file.Paths;
62 import java.nio.file.attribute.BasicFileAttributes;
63 import java.util.Enumeration;
64 import java.util.HashSet;
65 import java.util.Set;
66 import java.util.jar.JarEntry;
67 import java.util.jar.JarFile;
68 import java.util.stream.Collectors;
69 import java.util.stream.Stream;
70
71 import org.junit.jupiter.api.Test;
72 import toolbox.JavacTask;
73 import toolbox.Task;
74 import toolbox.Task.Expect;
75 import toolbox.ToolBox;
76 import build.tools.symbolgenerator.CreateSymbols;
77 import build.tools.symbolgenerator.CreateSymbols.ClassDescription;
78 import build.tools.symbolgenerator.CreateSymbols.ClassList;
79 import build.tools.symbolgenerator.CreateSymbols.ExcludeIncludeList;
80 import build.tools.symbolgenerator.CreateSymbols.VersionDescription;
81 import java.io.UncheckedIOException;
82 import java.lang.classfile.attribute.ModuleMainClassAttribute;
83 import java.lang.constant.ClassDesc;
84 import java.util.Objects;
85 import java.util.function.Consumer;
86
87 public class CreateSymbolsTestImpl {
88
89 static final String CREATE_SYMBOLS_NAME = "symbolgenerator.CreateSymbols";
90
91 @Test
92 void testMethodRemoved() throws Exception {
93 doTest("package t; public class T { public void m() { } }",
94 "package t; public class T { }",
95 "package t; public class Test { { T t = null; t.m(); } }",
96 Expect.SUCCESS,
97 Expect.FAIL);
98 doTest("package t; public class T { public void b() { } public void m() { } public void a() { } }",
99 "package t; public class T { public void b() { } public void a() { } }",
100 "package t; public class Test { { T t = null; t.b(); t.a(); } }",
101 Expect.SUCCESS,
102 Expect.SUCCESS);
103 //with additional attribute (need to properly skip the member):
104 doTest("package t; public class T { public void m() throws IllegalStateException { } public void a() { } }",
105 "package t; public class T { public void a() { } }",
106 "package t; public class Test { { T t = null; t.a(); } }",
107 Expect.SUCCESS,
108 Expect.SUCCESS);
109 }
110
827 .getOutput(Task.OutputKind.DIRECT)
828 .replaceAll("\\R", "\n");
829
830 if (!out.equals(expectedFailure)) {
831 throw new AssertionError("out=" + out + "; expected=" + expectedFailure);
832 }
833 }
834 }
835
836 @Test
837 void testExtendsInternalData1() throws Exception {
838 doTestData("""
839 module name m
840 header exports api extraModulePackages nonapi requires name\\u0020;java.base\\u0020;flags\\u0020;8000\\u0020;version\\u0020;0 flags 8000
841
842 class name api/Ann
843 header extends java/lang/Object implements java/lang/annotation/Annotation flags 2601
844
845 class name api/Api
846 header extends nonapi/Impl$Nested$Exp flags 21
847 innerclass innerClass nonapi/Impl$Nested outerClass nonapi/Impl innerClassName Nested flags 29
848 innerclass innerClass nonapi/Impl$Nested$Exp outerClass nonapi/Impl$Nested innerClassName Exp flags 29
849 method name <init> descriptor ()V flags 1
850
851 class name nonapi/Impl
852 header extends java/lang/Object nestMembers nonapi/Impl$Nested,nonapi/Impl$Nested$Exp flags 21
853 innerclass innerClass nonapi/Impl$Nested outerClass nonapi/Impl innerClassName Nested flags 29
854 innerclass innerClass nonapi/Impl$Nested$Exp outerClass nonapi/Impl$Nested innerClassName Exp flags 29
855 field name C descriptor Ljava/lang/String; constantValue flags 19
856 method name <init> descriptor ()V flags 1
857 method name test descriptor ()V flags 1
858
859 class name nonapi/Impl$Nested
860 header extends java/lang/Object nestHost nonapi/Impl flags 21 classAnnotations @Lapi/Ann;
861 innerclass innerClass nonapi/Impl$Nested outerClass nonapi/Impl innerClassName Nested flags 29
862 innerclass innerClass nonapi/Impl$Nested$Exp outerClass nonapi/Impl$Nested innerClassName Exp flags 29
863 method name <init> descriptor ()V flags 1
864
865 class name nonapi/Impl$Nested$Exp
866 header extends nonapi/Impl$Nested implements java/lang/Runnable nestHost nonapi/Impl flags 21
867 innerclass innerClass nonapi/Impl$Nested outerClass nonapi/Impl innerClassName Nested flags 29
868 innerclass innerClass nonapi/Impl$Nested$Exp outerClass nonapi/Impl$Nested innerClassName Exp flags 29
869 method name <init> descriptor ()V flags 1
870 method name run descriptor ()V flags 1
871 method name get descriptor ()Lnonapi/Impl$OtherNested; flags 1
872
873 """,
874 """
875 module m {
876 exports api;
877 exports nonapi to java.base;
878 }
879 """,
880 """
881 package api;
882 import nonapi.Impl;
883 public class Api extends Impl.Nested.Exp {
884 }
885 """,
886 """
887 package api;
888 public @interface Ann {
1320
1321 void deleteRecursively(Path dir) throws IOException {
1322 Files.walkFileTree(dir, new FileVisitor<Path>() {
1323 @Override
1324 public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
1325 return FileVisitResult.CONTINUE;
1326 }
1327 @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
1328 Files.delete(file);
1329 return FileVisitResult.CONTINUE;
1330 }
1331 @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
1332 return FileVisitResult.CONTINUE;
1333 }
1334 @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
1335 Files.delete(dir);
1336 return FileVisitResult.CONTINUE;
1337 }
1338 });
1339 }
1340 }
|