Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/tools/doclint/EmptyHtmlTest.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
/*
26
* @test
27
* @bug 8246712
28
* @summary doclint incorrectly reports some HTML elements as empty
29
* @modules jdk.javadoc/jdk.javadoc.internal.doclint
30
* @library /tools/lib
31
* @build toolbox.TestRunner toolbox.ToolBox
32
* @run main EmptyHtmlTest
33
*/
34
35
import java.io.PrintWriter;
36
import java.io.StringWriter;
37
import java.lang.reflect.Method;
38
import java.nio.file.Files;
39
import java.nio.file.Path;
40
import java.util.List;
41
42
import com.sun.source.doctree.DocTreeVisitor;
43
import com.sun.source.doctree.InlineTagTree;
44
import jdk.javadoc.internal.doclint.DocLint;
45
import toolbox.TestRunner;
46
import toolbox.ToolBox;
47
48
public class EmptyHtmlTest extends TestRunner {
49
50
public static void main(String... args) throws Exception {
51
EmptyHtmlTest t = new EmptyHtmlTest();
52
t.runTests(m -> new Object[] { Path.of(m.getName()) });
53
}
54
55
public EmptyHtmlTest() {
56
super(System.err);
57
}
58
59
ToolBox tb = new ToolBox();
60
61
/**
62
* This test is intended to be future-proof, and hence detect any
63
* problems in any inline tags added in the future.
64
* Since there is not yet any mapping between DocTree.Kind and
65
* the corresponding subtype DocTree (see javac Tree.Kind, Tree)
66
* the list of all current inline tag classes is determined by
67
* scanning DocTreeVisitor.
68
*
69
* @param base working directory for the test case
70
* @throws Exception if an error occurs
71
*/
72
@Test
73
public void testInlines(Path base) throws Exception {
74
Class<DocTreeVisitor> c = DocTreeVisitor.class;
75
for (Method m : c.getDeclaredMethods()) {
76
if (m.getName().startsWith("visit") && m.getParameterCount() == 2) {
77
Class<?>[] paramTypes = m.getParameterTypes();
78
Class<?> firstParamType = paramTypes[0];
79
if (InlineTagTree.class.isAssignableFrom(firstParamType)) {
80
testInline(base, firstParamType);
81
}
82
}
83
}
84
}
85
86
void testInline(Path base, Class<?> type) throws Exception {
87
// the following can eventually be converted to instanceof pattern switch
88
Path d = Files.createDirectories(base.resolve(type.getSimpleName()));
89
switch (type.getSimpleName()) {
90
case "DocRootTree" ->
91
test(d, type, "{@docRoot}");
92
93
case "IndexTree" ->
94
test(d, type, "{@index Object}");
95
96
case "InheritDocTree" ->
97
test(d, type, "{@inheritDoc}");
98
99
case "LinkTree" ->
100
test(d, type, "{@link Object}");
101
102
case "LiteralTree" ->
103
test(d, type, "{@literal abc}");
104
105
case "ReturnTree" ->
106
test(d, type, "{@return abc}");
107
108
case "SummaryTree" ->
109
test(d, type, "{@summary First sentence.}");
110
111
case "SystemPropertyTree" ->
112
test(d, type, "{@systemProperty file.separator}");
113
114
case "UnknownInlineTagTree" ->
115
test(d, type, "{@unknown}");
116
117
case "ValueTree" ->
118
test(d, type, "{@value Math.PI}");
119
120
default ->
121
error("no test case provided for " + type);
122
}
123
}
124
125
void test(Path base, Class<?> type, String tag) throws Exception {
126
System.err.println("test " + type.getSimpleName() + " " + tag);
127
Path src = base.resolve("src");
128
String text = """
129
/**
130
* This is a comment.
131
* <b>INSERT</b>
132
*/
133
public class C { }
134
""".replace("INSERT", tag);
135
tb.writeJavaFiles(src, text);
136
137
List<String> cmdArgs = List.of(
138
"-Xmsgs:html",
139
"-XcustomTags:unknown",
140
src.resolve("C.java").toString()
141
);
142
143
StringWriter sw = new StringWriter();
144
try (PrintWriter pw = new PrintWriter(sw)) {
145
new DocLint().run(pw, cmdArgs.toArray(new String[0]));
146
}
147
String log = sw.toString();
148
if (!log.isEmpty()) {
149
System.err.println("output:");
150
log.lines().forEach(System.err::println);
151
error("Unexpected output from doclint");
152
}
153
}
154
}
155
156