Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/jdk/javadoc/tool/enum/docComments/EnumCommentTest.java
40983 views
1
/*
2
* Copyright (c) 2003, 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 4421066
27
* @summary Verify the comments in an enum type.
28
* @library ../../../lib
29
* @modules jdk.javadoc/jdk.javadoc.internal.tool
30
* @build javadoc.tester.*
31
* @run main EnumCommentTest
32
*/
33
34
import javax.lang.model.element.ElementKind;
35
import javax.lang.model.element.ExecutableElement;
36
import javax.lang.model.element.TypeElement;
37
import javax.lang.model.element.VariableElement;
38
import javax.lang.model.util.ElementFilter;
39
import javax.lang.model.util.Elements;
40
41
import javadoc.tester.JavadocTester;
42
import javadoc.tester.TestDoclet;
43
import jdk.javadoc.doclet.DocletEnvironment;
44
45
public class EnumCommentTest extends JavadocTester {
46
47
public static void main(String[] args) throws Exception {
48
JavadocTester t = new EnumCommentTest();
49
t.runTests();
50
}
51
52
@Test
53
public void testEnumComments() {
54
javadoc("-sourcepath", testSrc,
55
"-docletpath", System.getProperty("test.class.path"),
56
"-doclet", "EnumCommentTest$ThisDoclet",
57
"pkg1");
58
checkExit(Exit.OK);
59
}
60
61
public static class ThisDoclet extends TestDoclet {
62
public boolean run(DocletEnvironment env) {
63
Elements elements = env.getElementUtils();
64
65
System.err.println("incl " + env.getIncludedElements());
66
TypeElement operation = env.getIncludedElements()
67
.stream()
68
.filter(e -> e.getKind() == ElementKind.ENUM)
69
.map(e -> (TypeElement) e)
70
.findFirst()
71
.orElseThrow(() -> new Error("can't find enum Operation"));
72
73
boolean ok = checkComment(elements.getDocComment(operation).trim(),
74
"Arithmetic operations.");
75
76
for (VariableElement f : ElementFilter.fieldsIn(operation.getEnclosedElements())) {
77
if (f.getSimpleName().contentEquals("plus")) {
78
ok = checkComment(elements.getDocComment(f).trim(),
79
"Addition")
80
&& ok;
81
for (ExecutableElement m : ElementFilter.methodsIn(operation.getEnclosedElements())) {
82
if (m.getSimpleName().contentEquals("eval")) {
83
ok = checkComment(elements.getDocComment(m).trim(),
84
"Perform arithmetic operation represented by this constant.")
85
&& ok;
86
break;
87
}
88
}
89
break;
90
}
91
}
92
if (!ok) {
93
throw new Error("Comments don't match expectations.");
94
} else {
95
return true;
96
}
97
}
98
99
private boolean checkComment(String found, String expected) {
100
System.out.println("expected: \"" + expected + "\"");
101
System.out.println("found: \"" + found + "\"");
102
return expected.equals(found);
103
}
104
}
105
}
106
107