Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/tools/sjavac/PubApisTest.java
41144 views
1
/*
2
* Copyright (c) 2020, 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 8241312 8246774
27
* @summary test for com.sun.tools.sjavac.comp.PubAPIs and com.sun.tools.sjavac.comp.PubapiVisitor
28
* @library /tools/lib
29
* @modules jdk.compiler/com.sun.tools.javac.util
30
* jdk.compiler/com.sun.tools.sjavac.comp
31
* jdk.compiler/com.sun.tools.sjavac.pubapi
32
*/
33
import com.sun.source.util.JavacTask;
34
import com.sun.tools.javac.util.Context;
35
import java.io.IOException;
36
import com.sun.tools.sjavac.comp.PubAPIs;
37
import com.sun.tools.sjavac.pubapi.PubApi;
38
import java.net.URI;
39
import static java.util.Arrays.asList;
40
import static java.util.Collections.emptySet;
41
import java.util.List;
42
import javax.tools.JavaFileObject;
43
import javax.tools.SimpleJavaFileObject;
44
import javax.tools.ToolProvider;
45
46
public class PubApisTest {
47
48
public static void main(String[] args) throws Throwable {
49
javax.tools.JavaCompiler c = ToolProvider.getSystemJavaCompiler();
50
JavacTask t = (JavacTask) c.getTask(null, null, null, null, null,
51
List.of(new SimpleJavaFileObject(URI.create("TestClass.java"), JavaFileObject.Kind.SOURCE) {
52
@Override
53
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
54
return String.join("\n",
55
"import java.util.*;",
56
"public final class TestClass {",
57
" private String s1 = \"str 1\";",
58
" public String s2 = \"str 2\";",
59
" protected final String s3 = \"str 3\";",
60
" static String s4 = \"str 4\";",
61
" protected TestClass(int i) {}",
62
" protected void m1() {}",
63
" public static Map<Integer, List<String>> m2() {",
64
" return null;",
65
" }",
66
" final void m3(Set<Map<Integer, Map<String, String>>> s) {}",
67
" static class DummyInner1 implements Runnable {",
68
" protected int field;",
69
" public void run() {}",
70
" }",
71
" final class DummyInner2 { }",
72
" public record Record3(int f1, String f2) {}",
73
"}");
74
}
75
}));
76
PubAPIs apis = PubAPIs.instance(new Context());
77
t.analyze().forEach(apis::visitPubapi);
78
PubApi actualApi = (PubApi) apis.getPubapis(emptySet(), false).get(":");
79
PubApi expectedApi = new PubApi();
80
asList( "TYPE final public TestClass",
81
" VAR public java.lang.String s2",
82
" VAR final protected java.lang.String s3 = \"\\u0073\\u0074\\u0072\\u0020\\u0033\"",
83
" VAR static java.lang.String s4",
84
" METHOD protected void m1()",
85
" METHOD public static java.util.Map m2()",
86
" METHOD final void m3(java.util.Set)",
87
" METHOD protected void <init>(int)",
88
" TYPE static TestClass$DummyInner1",
89
" VAR protected int field",
90
" METHOD public void run()",
91
" METHOD void <init>()",
92
" TYPE final TestClass$DummyInner2",
93
" METHOD void <init>()",
94
" TYPE final public static TestClass$Record3",
95
" METHOD final public boolean equals(java.lang.Object)",
96
" METHOD final public int hashCode()",
97
" METHOD public int f1()",
98
" METHOD public java.lang.String f2()",
99
" METHOD final public java.lang.String toString()",
100
" METHOD public void <init>(int,java.lang.String)"
101
).forEach(expectedApi::appendItem);
102
if (!expectedApi.equals(actualApi)) {
103
List<String> diffs = expectedApi.diff(actualApi);
104
System.out.println(diffs.size() + " differences found.");
105
diffs.forEach(System.out::println);
106
throw new AssertionError("Actual API differs from expected API.");
107
}
108
}
109
}
110
111