Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/jdk/jshell/JavadocTest.java
40931 views
1
/*
2
* Copyright (c) 2015, 2016, 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 8131019 8169561 8174245
27
* @summary Test Javadoc
28
* @library /tools/lib
29
* @modules jdk.compiler/com.sun.tools.javac.api
30
* jdk.compiler/com.sun.tools.javac.main
31
* jdk.jshell/jdk.jshell:open
32
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
33
* @build KullaTesting TestingInputStream Compiler
34
* @run testng JavadocTest
35
*/
36
37
import java.io.IOException;
38
import java.lang.reflect.Field;
39
import java.nio.file.Files;
40
import java.nio.file.Path;
41
import java.nio.file.Paths;
42
import java.util.Arrays;
43
import java.util.jar.JarEntry;
44
import java.util.jar.JarOutputStream;
45
46
import org.testng.annotations.Test;
47
48
@Test
49
public class JavadocTest extends KullaTesting {
50
51
private final Compiler compiler = new Compiler();
52
53
public void testJavadoc() {
54
prepareZip();
55
assertJavadoc("test.Clazz|", "test.Clazz\n" +
56
"Top level. ");
57
assertEval("test.Clazz clz = null;");
58
assertJavadoc("clz.test(|", "String test.Clazz.test(int p) throws IllegalStateException\n" +
59
" javadoc1A\n" +
60
"\n" +
61
" @param p param\n" +
62
" @throws IllegalStateException exc\n" +
63
" @return value\n");
64
//undefined handling:
65
assertJavadoc("clz.undef|");
66
}
67
68
public void testVariableInRepl() {
69
assertEval("Object o;");
70
assertSignature("o|", "o:java.lang.Object");
71
}
72
73
private void prepareZip() {
74
String clazz =
75
"package test;\n" +
76
"/**Top level." +
77
" */\n" +
78
"public class Clazz {\n" +
79
" /**\n" +
80
" * javadoc1A\n" +
81
" *\n" +
82
" * @param p param\n" +
83
" * @throws IllegalStateException exc\n" +
84
" * @return value\n" +
85
" */\n" +
86
" public String test(int p) throws IllegalStateException { return null;}\n" +
87
"}\n";
88
89
Path srcZip = Paths.get("src.zip");
90
91
try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(srcZip))) {
92
out.putNextEntry(new JarEntry("test/Clazz.java"));
93
out.write(clazz.getBytes());
94
} catch (IOException ex) {
95
throw new IllegalStateException(ex);
96
}
97
98
compiler.compile(clazz);
99
100
try {
101
Field availableSources = getAnalysis().getClass().getDeclaredField("availableSources");
102
availableSources.setAccessible(true);
103
availableSources.set(getAnalysis(), Arrays.asList(srcZip));
104
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) {
105
throw new IllegalStateException(ex);
106
}
107
addToClasspath(compiler.getClassDir());
108
}
109
110
public void testCollectionsMin() {
111
prepareJavaUtilZip();
112
assertJavadoc("java.util.Collections.min(|",
113
"T java.util.Collections.<T>min(java.util.Collection<? extends T> coll, java.util.Comparator<? super T> comp)\n" +
114
" min comparator\n",
115
"T java.util.Collections.<T extends Object & Comparable<? super T>>min(java.util.Collection<? extends T> coll)\n" +
116
" min comparable\n");
117
}
118
119
private void prepareJavaUtilZip() {
120
String clazz =
121
"package java.util;\n" +
122
"/**Top level." +
123
" */\n" +
124
"public class Collections {\n" +
125
" /**\n" +
126
" * min comparable\n" +
127
" */\n" +
128
" public static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> coll) {" +
129
" return null;\n" +
130
" }\n" +
131
" /**\n" +
132
" * min comparator\n" +
133
" */\n" +
134
" public static <T> T min(Collection<? extends T> coll, Comparator<? super T> comp) {\n" +
135
" return null;\n" +
136
" }\n" +
137
"}\n";
138
139
Path srcZip = Paths.get("src.zip");
140
141
try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(srcZip))) {
142
out.putNextEntry(new JarEntry("java/util/Collections.java"));
143
out.write(clazz.getBytes());
144
} catch (IOException ex) {
145
throw new IllegalStateException(ex);
146
}
147
148
try {
149
Field availableSources = getAnalysis().getClass().getDeclaredField("availableSources");
150
availableSources.setAccessible(true);
151
availableSources.set(getAnalysis(), Arrays.asList(srcZip));
152
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) {
153
throw new IllegalStateException(ex);
154
}
155
}
156
157
}
158
159