author | aph |
Mon, 04 Nov 2019 13:13:34 -0500 | |
changeset 58917 | 33f9271b3167 |
parent 48237 | ee130cca69e6 |
permissions | -rw-r--r-- |
41865 | 1 |
/* |
48028
9e022f580a9d
8190552: Augment the Compiler API tree with APIs to represent HTML content
ksrini
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
41865 | 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 |
|
48237
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
26 |
* @bug 8131019 8189778 8190552 |
41865 | 27 |
* @summary Test JavadocHelper |
28 |
* @library /tools/lib |
|
29 |
* @modules jdk.compiler/com.sun.tools.javac.api |
|
30 |
* jdk.compiler/com.sun.tools.javac.main |
|
31 |
* jdk.compiler/jdk.internal.shellsupport.doc |
|
32 |
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask |
|
48237
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
33 |
* @run testng/timeout=900/othervm JavadocHelperTest |
41865 | 34 |
*/ |
35 |
||
36 |
import java.io.IOException; |
|
37 |
import java.net.URI; |
|
38 |
import java.net.URISyntaxException; |
|
48237
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
39 |
import java.nio.file.DirectoryStream; |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
40 |
import java.nio.file.FileSystem; |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
41 |
import java.nio.file.FileSystems; |
41865 | 42 |
import java.nio.file.Files; |
43 |
import java.nio.file.Path; |
|
44 |
import java.nio.file.Paths; |
|
48237
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
45 |
import java.util.ArrayList; |
41865 | 46 |
import java.util.Arrays; |
48237
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
47 |
import java.util.Collections; |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
48 |
import java.util.List; |
41865 | 49 |
import java.util.function.Function; |
50 |
import java.util.jar.JarEntry; |
|
51 |
import java.util.jar.JarOutputStream; |
|
52 |
||
53 |
import javax.lang.model.element.Element; |
|
48237
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
54 |
import javax.lang.model.element.ModuleElement; |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
55 |
import javax.lang.model.element.ModuleElement.ExportsDirective; |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
56 |
import javax.lang.model.element.TypeElement; |
41865 | 57 |
import javax.lang.model.util.ElementFilter; |
58 |
import javax.tools.Diagnostic.Kind; |
|
59 |
import javax.tools.DiagnosticListener; |
|
60 |
import javax.tools.JavaCompiler; |
|
61 |
import javax.tools.JavaFileObject; |
|
62 |
import javax.tools.SimpleJavaFileObject; |
|
63 |
import javax.tools.StandardJavaFileManager; |
|
64 |
import javax.tools.StandardLocation; |
|
65 |
import javax.tools.ToolProvider; |
|
66 |
||
67 |
import com.sun.source.util.JavacTask; |
|
68 |
import jdk.internal.shellsupport.doc.JavadocHelper; |
|
69 |
import org.testng.annotations.Test; |
|
70 |
import static org.testng.Assert.assertEquals; |
|
71 |
import static org.testng.Assert.assertTrue; |
|
72 |
||
73 |
@Test |
|
74 |
public class JavadocHelperTest { |
|
75 |
||
76 |
public void testJavadoc() throws Exception { |
|
77 |
doTestJavadoc("", |
|
78 |
t -> t.getElements().getTypeElement("test.Super"), |
|
79 |
"Top level. "); |
|
80 |
doTestJavadoc("", |
|
81 |
t -> getFirstMethod(t, "test.Super"), |
|
48237
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
82 |
" javadoc1\n" + |
41865 | 83 |
"\n" + |
48237
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
84 |
" @param p1 param1\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
85 |
" @param p2 param2\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
86 |
" @param p3 param3\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
87 |
" @throws IllegalStateException exc1\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
88 |
" @throws IllegalArgumentException exc2\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
89 |
" @throws IllegalAccessException exc3\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
90 |
" @return value\n"); |
41865 | 91 |
} |
92 |
||
93 |
private Element getFirstMethod(JavacTask task, String typeName) { |
|
94 |
return ElementFilter.methodsIn(task.getElements().getTypeElement(typeName).getEnclosedElements()).get(0); |
|
95 |
} |
|
96 |
||
97 |
private Function<JavacTask, Element> getSubTest = t -> getFirstMethod(t, "test.Sub"); |
|
98 |
||
99 |
public void testInheritNoJavadoc() throws Exception { |
|
100 |
doTestJavadoc("", |
|
101 |
getSubTest, |
|
48237
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
102 |
" javadoc1\n" + |
41865 | 103 |
"\n" + |
48237
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
104 |
" @param p1 param1\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
105 |
" @param p2 param2\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
106 |
" @param p3 param3\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
107 |
" @throws IllegalStateException exc1\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
108 |
" @throws IllegalArgumentException exc2\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
109 |
" @throws IllegalAccessException exc3\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
110 |
" @return value\n"); |
41865 | 111 |
} |
112 |
||
113 |
public void testInheritFull() throws Exception { |
|
114 |
doTestJavadoc(" /**\n" + |
|
115 |
" * Prefix {@inheritDoc} suffix.\n" + |
|
116 |
" *\n" + |
|
117 |
" * @param p1 prefix {@inheritDoc} suffix\n" + |
|
118 |
" * @param p2 prefix {@inheritDoc} suffix\n" + |
|
119 |
" * @param p3 prefix {@inheritDoc} suffix\n" + |
|
120 |
" * @throws IllegalStateException prefix {@inheritDoc} suffix\n" + |
|
121 |
" * @throws IllegalArgumentException prefix {@inheritDoc} suffix\n" + |
|
122 |
" * @throws IllegalAccessException prefix {@inheritDoc} suffix\n" + |
|
123 |
" * @return prefix {@inheritDoc} suffix\n" + |
|
124 |
" */\n", |
|
125 |
getSubTest, |
|
126 |
" Prefix javadoc1 suffix.\n" + |
|
127 |
"\n" + |
|
128 |
" @param p1 prefix param1 suffix\n" + |
|
129 |
" @param p2 prefix param2 suffix\n" + |
|
130 |
" @param p3 prefix param3 suffix\n" + |
|
131 |
" @throws IllegalStateException prefix exc1 suffix\n" + |
|
132 |
" @throws IllegalArgumentException prefix exc2 suffix\n" + |
|
133 |
" @throws IllegalAccessException prefix exc3 suffix\n" + |
|
134 |
" @return prefix value suffix\n"); |
|
135 |
} |
|
136 |
||
137 |
public void testInheritMissingParam() throws Exception { |
|
138 |
doTestJavadoc(" /**\n" + |
|
139 |
" * Prefix {@inheritDoc} suffix.\n" + |
|
140 |
" *\n" + |
|
141 |
" * @param p1 prefix {@inheritDoc} suffix\n" + |
|
142 |
" * @param p3 prefix {@inheritDoc} suffix\n" + |
|
143 |
" * @throws IllegalStateException prefix {@inheritDoc} suffix\n" + |
|
144 |
" * @throws IllegalArgumentException prefix {@inheritDoc} suffix\n" + |
|
145 |
" * @throws IllegalAccessException prefix {@inheritDoc} suffix\n" + |
|
146 |
" * @return prefix {@inheritDoc} suffix\n" + |
|
147 |
" */\n", |
|
148 |
getSubTest, |
|
149 |
" Prefix javadoc1 suffix.\n" + |
|
150 |
"\n" + |
|
151 |
" @param p1 prefix param1 suffix\n" + |
|
48237
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
152 |
"@param p2 param2\n" + |
41865 | 153 |
" @param p3 prefix param3 suffix\n" + |
154 |
" @throws IllegalStateException prefix exc1 suffix\n" + |
|
155 |
" @throws IllegalArgumentException prefix exc2 suffix\n" + |
|
156 |
" @throws IllegalAccessException prefix exc3 suffix\n" + |
|
157 |
" @return prefix value suffix\n"); |
|
158 |
} |
|
159 |
||
160 |
public void testInheritMissingFirstParam() throws Exception { |
|
161 |
doTestJavadoc(" /**\n" + |
|
162 |
" * Prefix {@inheritDoc} suffix.\n" + |
|
163 |
" *\n" + |
|
164 |
" * @param p2 prefix {@inheritDoc} suffix\n" + |
|
165 |
" * @param p3 prefix {@inheritDoc} suffix\n" + |
|
166 |
" * @throws IllegalStateException prefix {@inheritDoc} suffix\n" + |
|
167 |
" * @throws IllegalArgumentException prefix {@inheritDoc} suffix\n" + |
|
168 |
" * @throws IllegalAccessException prefix {@inheritDoc} suffix\n" + |
|
169 |
" * @return prefix {@inheritDoc} suffix\n" + |
|
170 |
" */\n", |
|
171 |
getSubTest, |
|
172 |
" Prefix javadoc1 suffix.\n" + |
|
173 |
"\n" + |
|
48237
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
174 |
"@param p1 param1\n" + |
41865 | 175 |
" @param p2 prefix param2 suffix\n" + |
176 |
" @param p3 prefix param3 suffix\n" + |
|
177 |
" @throws IllegalStateException prefix exc1 suffix\n" + |
|
178 |
" @throws IllegalArgumentException prefix exc2 suffix\n" + |
|
179 |
" @throws IllegalAccessException prefix exc3 suffix\n" + |
|
180 |
" @return prefix value suffix\n"); |
|
181 |
} |
|
182 |
||
183 |
public void testInheritMissingThrows() throws Exception { |
|
184 |
doTestJavadoc(" /**\n" + |
|
185 |
" * Prefix {@inheritDoc} suffix.\n" + |
|
186 |
" *\n" + |
|
187 |
" * @param p1 prefix {@inheritDoc} suffix\n" + |
|
188 |
" * @param p2 prefix {@inheritDoc} suffix\n" + |
|
189 |
" * @param p3 prefix {@inheritDoc} suffix\n" + |
|
190 |
" * @throws IllegalStateException prefix {@inheritDoc} suffix\n" + |
|
191 |
" * @throws IllegalAccessException prefix {@inheritDoc} suffix\n" + |
|
192 |
" * @return prefix {@inheritDoc} suffix\n" + |
|
193 |
" */\n", |
|
194 |
getSubTest, |
|
195 |
" Prefix javadoc1 suffix.\n" + |
|
196 |
"\n" + |
|
197 |
" @param p1 prefix param1 suffix\n" + |
|
198 |
" @param p2 prefix param2 suffix\n" + |
|
199 |
" @param p3 prefix param3 suffix\n" + |
|
200 |
" @throws IllegalStateException prefix exc1 suffix\n" + |
|
48237
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
201 |
"@throws java.lang.IllegalArgumentException exc2\n" + |
41865 | 202 |
" @throws IllegalAccessException prefix exc3 suffix\n" + |
203 |
" @return prefix value suffix\n"); |
|
204 |
} |
|
205 |
||
206 |
public void testInheritMissingReturn() throws Exception { |
|
207 |
doTestJavadoc(" /**\n" + |
|
208 |
" * Prefix {@inheritDoc} suffix.\n" + |
|
209 |
" *\n" + |
|
210 |
" * @param p1 prefix {@inheritDoc} suffix\n" + |
|
211 |
" * @param p2 prefix {@inheritDoc} suffix\n" + |
|
212 |
" * @param p3 prefix {@inheritDoc} suffix\n" + |
|
213 |
" * @throws IllegalStateException prefix {@inheritDoc} suffix\n" + |
|
214 |
" * @throws IllegalArgumentException prefix {@inheritDoc} suffix\n" + |
|
215 |
" * @throws IllegalAccessException prefix {@inheritDoc} suffix\n" + |
|
216 |
" */\n", |
|
217 |
getSubTest, |
|
218 |
" Prefix javadoc1 suffix.\n" + |
|
219 |
"\n" + |
|
220 |
" @param p1 prefix param1 suffix\n" + |
|
221 |
" @param p2 prefix param2 suffix\n" + |
|
222 |
" @param p3 prefix param3 suffix\n" + |
|
223 |
" @throws IllegalStateException prefix exc1 suffix\n" + |
|
224 |
" @throws IllegalArgumentException prefix exc2 suffix\n" + |
|
225 |
" @throws IllegalAccessException prefix exc3 suffix\n" + |
|
48237
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
226 |
"@return value\n"); |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
227 |
} |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
228 |
|
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
229 |
public void testInheritAllButOne() throws Exception { |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
230 |
doTestJavadoc(" /**\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
231 |
" * @throws IllegalArgumentException {@inheritDoc}\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
232 |
" */\n", |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
233 |
getSubTest, |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
234 |
"javadoc1\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
235 |
"@param p1 param1\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
236 |
"@param p2 param2\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
237 |
"@param p3 param3\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
238 |
"@throws java.lang.IllegalStateException exc1\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
239 |
" @throws IllegalArgumentException exc2\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
240 |
"@throws java.lang.IllegalAccessException exc3\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
241 |
"@return value\n"); |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
242 |
} |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
243 |
|
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
244 |
public void testInheritEmpty() throws Exception { |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
245 |
doTestJavadoc(" /**\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
246 |
" */\n", |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
247 |
" /**@param p1\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
248 |
" * @param p2\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
249 |
" * @param p3\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
250 |
" * @throws IllegalStateException\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
251 |
" * @throws IllegalArgumentException\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
252 |
" * @throws IllegalAccessException\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
253 |
" * @return\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
254 |
" */\n", |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
255 |
getSubTest, |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
256 |
"\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
257 |
"@param p1 \n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
258 |
"@param p2 \n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
259 |
"@param p3 \n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
260 |
"@throws java.lang.IllegalStateException \n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
261 |
"@throws java.lang.IllegalArgumentException \n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
262 |
"@throws java.lang.IllegalAccessException \n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
263 |
"@return \n"); |
41865 | 264 |
} |
265 |
||
48237
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
266 |
public void testEmptyValue() throws Exception { |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
267 |
doTestJavadoc(" /**\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
268 |
" */\n", |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
269 |
" /**@param p1 {@value}\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
270 |
" * @param p2\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
271 |
" * @param p3\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
272 |
" * @throws IllegalStateException\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
273 |
" * @throws IllegalArgumentException\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
274 |
" * @throws IllegalAccessException\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
275 |
" * @return\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
276 |
" */\n", |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
277 |
getSubTest, |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
278 |
"\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
279 |
"@param p1 {@value}\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
280 |
"@param p2 \n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
281 |
"@param p3 \n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
282 |
"@throws java.lang.IllegalStateException \n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
283 |
"@throws java.lang.IllegalArgumentException \n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
284 |
"@throws java.lang.IllegalAccessException \n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
285 |
"@return \n"); |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
286 |
} |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
287 |
|
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
288 |
public void testShortComment() throws Exception { |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
289 |
doTestJavadoc(" /**Test.*/\n", |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
290 |
getSubTest, |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
291 |
"Test." + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
292 |
"@param p1 param1\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
293 |
"@param p2 param2\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
294 |
"@param p3 param3\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
295 |
"@throws java.lang.IllegalStateException exc1\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
296 |
"@throws java.lang.IllegalArgumentException exc2\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
297 |
"@throws java.lang.IllegalAccessException exc3\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
298 |
"@return value\n"); |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
299 |
} |
41865 | 300 |
|
301 |
private void doTestJavadoc(String origJavadoc, Function<JavacTask, Element> getElement, String expectedJavadoc) throws Exception { |
|
48237
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
302 |
doTestJavadoc(origJavadoc, |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
303 |
" /**\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
304 |
" * javadoc1\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
305 |
" *\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
306 |
" * @param p1 param1\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
307 |
" * @param p2 param2\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
308 |
" * @param p3 param3\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
309 |
" * @throws IllegalStateException exc1\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
310 |
" * @throws IllegalArgumentException exc2\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
311 |
" * @throws IllegalAccessException exc3\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
312 |
" * @return value\n" + |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
313 |
" */\n", |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
314 |
getElement, expectedJavadoc); |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
315 |
} |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
316 |
|
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
317 |
private void doTestJavadoc(String origJavadoc, |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
318 |
String superJavadoc, |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
319 |
Function<JavacTask, Element> getElement, |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
320 |
String expectedJavadoc) throws Exception { |
41865 | 321 |
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
322 |
String subClass = |
|
323 |
"package test;\n" + |
|
324 |
"public class Sub extends Super {\n" + |
|
325 |
origJavadoc + |
|
326 |
" public String test(int p1, int p2, int p3) throws IllegalStateException, IllegalArgumentException, IllegalAccessException { return null;} \n" + |
|
327 |
"}\n"; |
|
328 |
String superClass = |
|
329 |
"package test;\n" + |
|
330 |
"/**Top level." + |
|
331 |
" */\n" + |
|
332 |
"public class Super {\n" + |
|
48237
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
333 |
superJavadoc + |
41865 | 334 |
" public String test(int p1, int p2, int p3) throws IllegalStateException, IllegalArgumentException, IllegalAccessException { return null;} \n" + |
335 |
"}\n"; |
|
336 |
||
337 |
Path srcZip = Paths.get("src.zip"); |
|
338 |
||
339 |
try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(srcZip))) { |
|
340 |
out.putNextEntry(new JarEntry("test/Sub.java")); |
|
341 |
out.write(subClass.getBytes()); |
|
342 |
out.putNextEntry(new JarEntry("test/Super.java")); |
|
343 |
out.write(superClass.getBytes()); |
|
344 |
} catch (IOException ex) { |
|
345 |
throw new IllegalStateException(ex); |
|
346 |
} |
|
347 |
||
348 |
DiagnosticListener<? super JavaFileObject> noErrors = d -> { |
|
349 |
if (d.getKind() == Kind.ERROR) { |
|
350 |
throw new AssertionError(d.getMessage(null)); |
|
351 |
} |
|
352 |
}; |
|
353 |
||
354 |
assertTrue(compiler.getTask(null, null, noErrors, Arrays.asList("-d", "."), null, Arrays.asList(new JFOImpl("Super", superClass), new JFOImpl("Sub", subClass))).call()); |
|
355 |
||
356 |
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) { |
|
357 |
fm.setLocationFromPaths(StandardLocation.CLASS_PATH, Arrays.asList(Paths.get(".").toAbsolutePath())); |
|
358 |
JavacTask task = (JavacTask) compiler.getTask(null, fm, noErrors, null, null, null); |
|
359 |
||
360 |
Element el = getElement.apply(task); |
|
361 |
||
362 |
try (JavadocHelper helper = JavadocHelper.create(task, Arrays.asList(srcZip))) { |
|
363 |
String javadoc = helper.getResolvedDocComment(el); |
|
364 |
||
365 |
assertEquals(javadoc, expectedJavadoc); |
|
366 |
} |
|
367 |
} |
|
368 |
} |
|
369 |
||
370 |
private static final class JFOImpl extends SimpleJavaFileObject { |
|
371 |
||
372 |
private final String code; |
|
373 |
||
374 |
public JFOImpl(String name, String code) throws URISyntaxException { |
|
375 |
super(new URI("mem:///" + name + ".java"), Kind.SOURCE); |
|
376 |
this.code = code; |
|
377 |
} |
|
378 |
||
379 |
@Override |
|
380 |
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { |
|
381 |
return code; |
|
382 |
} |
|
383 |
||
384 |
} |
|
48237
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
385 |
|
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
386 |
public void testAllDocs() throws IOException { |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
387 |
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
388 |
DiagnosticListener<? super JavaFileObject> noErrors = d -> { |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
389 |
if (d.getKind() == Kind.ERROR) { |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
390 |
throw new AssertionError(d.getMessage(null)); |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
391 |
} |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
392 |
}; |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
393 |
|
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
394 |
List<Path> sources = new ArrayList<>(); |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
395 |
Path home = Paths.get(System.getProperty("java.home")); |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
396 |
Path srcZip = home.resolve("lib").resolve("src.zip"); |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
397 |
if (Files.isReadable(srcZip)) { |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
398 |
URI uri = URI.create("jar:" + srcZip.toUri()); |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
399 |
try (FileSystem zipFO = FileSystems.newFileSystem(uri, Collections.emptyMap())) { |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
400 |
Path root = zipFO.getRootDirectories().iterator().next(); |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
401 |
|
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
402 |
//modular format: |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
403 |
try (DirectoryStream<Path> ds = Files.newDirectoryStream(root)) { |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
404 |
for (Path p : ds) { |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
405 |
if (Files.isDirectory(p)) { |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
406 |
sources.add(p); |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
407 |
} |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
408 |
} |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
409 |
} |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
410 |
try (StandardJavaFileManager fm = |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
411 |
compiler.getStandardFileManager(null, null, null)) { |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
412 |
JavacTask task = |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
413 |
(JavacTask) compiler.getTask(null, fm, noErrors, null, null, null); |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
414 |
task.getElements().getTypeElement("java.lang.Object"); |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
415 |
for (ModuleElement me : task.getElements().getAllModuleElements()) { |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
416 |
List<ExportsDirective> exports = |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
417 |
ElementFilter.exportsIn(me.getDirectives()); |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
418 |
for (ExportsDirective ed : exports) { |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
419 |
try (JavadocHelper helper = JavadocHelper.create(task, sources)) { |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
420 |
List<? extends Element> content = |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
421 |
ed.getPackage().getEnclosedElements(); |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
422 |
for (TypeElement clazz : ElementFilter.typesIn(content)) { |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
423 |
for (Element el : clazz.getEnclosedElements()) { |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
424 |
helper.getResolvedDocComment(el); |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
425 |
} |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
426 |
} |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
427 |
} |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
428 |
} |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
429 |
} |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
430 |
} |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
431 |
} |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
432 |
} |
ee130cca69e6
8189778: Jshell crash on tab for StringBuilder.append(
jlahoda
parents:
48028
diff
changeset
|
433 |
} |
41865 | 434 |
} |