mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-14 09:53:18 +00:00
8152313: [javadoc] convert tool tests to doclet tests
Reviewed-by: ksrini
This commit is contained in:
parent
3839c8656e
commit
3e5abdaf32
@ -26,9 +26,6 @@
|
||||
###########################################################################
|
||||
#
|
||||
# javadoc
|
||||
jdk/javadoc/tool/enum/docComments/Main.java 8152313 generic-all convert to doclet test framework
|
||||
jdk/javadoc/tool/enum/enumType/Main.java 8152313 generic-all convert to doclet test framework
|
||||
jdk/javadoc/tool/varArgs/Main.java 8152313 generic-all convert to doclet test framework
|
||||
jdk/javadoc/doclet/testIOException/TestIOException.java 8164597 windows-all
|
||||
|
||||
###########################################################################
|
||||
|
||||
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javadoc.tester;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import javax.lang.model.SourceVersion;
|
||||
|
||||
import jdk.javadoc.doclet.Doclet;
|
||||
import jdk.javadoc.doclet.DocletEnvironment;
|
||||
import jdk.javadoc.doclet.Reporter;
|
||||
|
||||
/**
|
||||
* A minimal base class for test doclets.
|
||||
*
|
||||
* The {@link Doclet#run(DocletEnvironment) run} method must still be provided by subtypes.
|
||||
*/
|
||||
public abstract class TestDoclet implements Doclet {
|
||||
protected Locale locale;
|
||||
protected Reporter reporter;
|
||||
|
||||
@Override
|
||||
public void init(Locale locale, Reporter reporter) {
|
||||
this.locale = locale;
|
||||
this.reporter = reporter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<? extends Option> getSupportedOptions() {
|
||||
return Set.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceVersion getSupportedSourceVersion() {
|
||||
return SourceVersion.latestSupported();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4421066
|
||||
* @summary Verify the comments in an enum type.
|
||||
* @library ../../../lib
|
||||
* @modules jdk.javadoc/jdk.javadoc.internal.tool
|
||||
* @build javadoc.tester.*
|
||||
* @run main EnumCommentTest
|
||||
*/
|
||||
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.util.ElementFilter;
|
||||
import javax.lang.model.util.Elements;
|
||||
|
||||
import javadoc.tester.JavadocTester;
|
||||
import javadoc.tester.TestDoclet;
|
||||
import jdk.javadoc.doclet.DocletEnvironment;
|
||||
|
||||
public class EnumCommentTest extends JavadocTester {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
JavadocTester t = new EnumCommentTest();
|
||||
t.runTests();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnumComments() {
|
||||
javadoc("-sourcepath", testSrc,
|
||||
"-docletpath", System.getProperty("test.class.path"),
|
||||
"-doclet", "EnumCommentTest$ThisDoclet",
|
||||
"pkg1");
|
||||
checkExit(Exit.OK);
|
||||
}
|
||||
|
||||
public static class ThisDoclet extends TestDoclet {
|
||||
public boolean run(DocletEnvironment env) {
|
||||
Elements elements = env.getElementUtils();
|
||||
|
||||
System.err.println("incl " + env.getIncludedElements());
|
||||
TypeElement operation = env.getIncludedElements()
|
||||
.stream()
|
||||
.filter(e -> e.getKind() == ElementKind.ENUM)
|
||||
.map(e -> (TypeElement) e)
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new Error("can't find enum Operation"));
|
||||
|
||||
boolean ok = checkComment(elements.getDocComment(operation).trim(),
|
||||
"Arithmetic operations.");
|
||||
|
||||
for (VariableElement f : ElementFilter.fieldsIn(operation.getEnclosedElements())) {
|
||||
if (f.getSimpleName().contentEquals("plus")) {
|
||||
ok = checkComment(elements.getDocComment(f).trim(),
|
||||
"Addition")
|
||||
&& ok;
|
||||
for (ExecutableElement m : ElementFilter.methodsIn(operation.getEnclosedElements())) {
|
||||
if (m.getSimpleName().contentEquals("eval")) {
|
||||
ok = checkComment(elements.getDocComment(m).trim(),
|
||||
"Perform arithmetic operation represented by this constant.")
|
||||
&& ok;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!ok) {
|
||||
throw new Error("Comments don't match expectations.");
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkComment(String found, String expected) {
|
||||
System.out.println("expected: \"" + expected + "\"");
|
||||
System.out.println("found: \"" + found + "\"");
|
||||
return expected.equals(found);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4421066
|
||||
* @summary Verify the comments in an enum type.
|
||||
* @ignore 8152313 convert to doclet test framework
|
||||
* @library ../../lib
|
||||
* @modules jdk.javadoc
|
||||
* @compile ../../lib/Tester.java Main.java
|
||||
* @run main Main
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.sun.javadoc.*;
|
||||
import jdk.javadoc.doclet.DocletEnvironment;
|
||||
|
||||
public class Main extends Tester.Doclet {
|
||||
|
||||
private static final Tester tester =
|
||||
new Tester("Main", "-package", "pkg1");
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
tester.run();
|
||||
}
|
||||
|
||||
public static boolean run(DocletEnvironment root) {
|
||||
ClassDoc operation = root.classes()[0];
|
||||
boolean ok =
|
||||
checkComment(operation.commentText(), "Arithmetic operations.");
|
||||
|
||||
for (FieldDoc f : operation.fields()) {
|
||||
if (f.name().equals("plus")) {
|
||||
ok = checkComment(f.commentText(), "Addition") && ok;
|
||||
for (MethodDoc m : operation.methods()) {
|
||||
if (m.name().equals("eval")) {
|
||||
ok = checkComment(m.commentText(),
|
||||
"Perform arithmetic operation " +
|
||||
"represented by this constant.") &&
|
||||
ok;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!ok) {
|
||||
throw new Error("Comments don't match expectations.");
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean checkComment(String found, String expected) {
|
||||
System.out.println("expected: \"" + expected + "\"");
|
||||
System.out.println("found: \"" + found + "\"");
|
||||
return expected.equals(found);
|
||||
}
|
||||
}
|
||||
@ -30,7 +30,7 @@ package pkg1;
|
||||
/**
|
||||
* Arithmetic operations.
|
||||
*/
|
||||
public abstract enum Operation {
|
||||
public enum Operation {
|
||||
/** Addition */
|
||||
plus {
|
||||
/** Add 'em up. */
|
||||
|
||||
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4421066
|
||||
* @summary Verify the contents of an enum type.
|
||||
* @library ../../../lib
|
||||
* @modules jdk.javadoc/jdk.javadoc.internal.tool
|
||||
* @build javadoc.tester.*
|
||||
* @run main EnumContentsTest
|
||||
*/
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
|
||||
import jdk.javadoc.doclet.DocletEnvironment;
|
||||
|
||||
import javadoc.tester.JavadocTester;
|
||||
import javadoc.tester.TestDoclet;
|
||||
|
||||
public class EnumContentsTest extends JavadocTester {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
JavadocTester t = new EnumContentsTest();
|
||||
t.runTests();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnumContents() throws Exception {
|
||||
javadoc("-sourcepath", testSrc,
|
||||
"-docletpath", System.getProperty("test.class.path"),
|
||||
"-doclet", "EnumContentsTest$ThisDoclet",
|
||||
"pkg1");
|
||||
checkExit(Exit.OK);
|
||||
|
||||
String expect = Files.readAllLines(Path.of(testSrc).resolve("expected.out"))
|
||||
.stream()
|
||||
.collect(Collectors.joining("\n"));
|
||||
checkOutput(Output.STDOUT, true, expect);
|
||||
}
|
||||
|
||||
|
||||
public static class ThisDoclet extends TestDoclet {
|
||||
public boolean run(DocletEnvironment root) {
|
||||
try {
|
||||
for (Element e : root.getIncludedElements()) {
|
||||
if (e.getKind() == ElementKind.ENUM) {
|
||||
printClass((TypeElement) e);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// this method mimics the printClass method from the old
|
||||
// tester framework
|
||||
void printClass(TypeElement te) {
|
||||
PrintStream out = System.out;
|
||||
out.format("%s %s%n",
|
||||
te.getKind().toString().toLowerCase(),
|
||||
te.getQualifiedName());
|
||||
out.format(" name: %s / %s / %s%n",
|
||||
te.getSimpleName(), te.asType(), te.getQualifiedName());
|
||||
out.format(" superclass:%n %s%n",
|
||||
te.getSuperclass());
|
||||
out.format(" enum constants:%n");
|
||||
te.getEnclosedElements().stream()
|
||||
.filter(e -> e.getKind() == ElementKind.ENUM_CONSTANT)
|
||||
.forEach(e -> out.format(" %s%n", e.getSimpleName()));
|
||||
out.format(" methods:%n");
|
||||
te.getEnclosedElements().stream()
|
||||
.filter(e -> e.getKind() == ElementKind.METHOD)
|
||||
.map(e -> (ExecutableElement) e)
|
||||
.forEach(e -> out.format(" %s %s(%s)%n",
|
||||
e.getReturnType(),
|
||||
e.getSimpleName(),
|
||||
e.getParameters().stream()
|
||||
.map(this::paramToString)
|
||||
.collect(Collectors.joining(", "))
|
||||
));
|
||||
|
||||
}
|
||||
private String paramToString(Element e) {
|
||||
return ((DeclaredType) e.asType()).asElement().getSimpleName().toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4421066
|
||||
* @summary Verify the contents of an enum type.
|
||||
* @ignore 8152313 convert to doclet test framework
|
||||
* @library ../../lib
|
||||
* @modules jdk.javadoc
|
||||
* @compile ../../lib/Tester.java Main.java
|
||||
* @run main Main
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import com.sun.javadoc.*;
|
||||
|
||||
public class Main extends Tester.Doclet {
|
||||
|
||||
private static final Tester tester = new Tester("Main", "pkg1");
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
tester.run();
|
||||
tester.verify();
|
||||
}
|
||||
|
||||
public static boolean run(DocletEnvironment root) {
|
||||
try {
|
||||
for (ClassDoc cd : root.classes()) {
|
||||
tester.printClass(cd);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
enum pkg1.QuotablePerson
|
||||
name: QuotablePerson / QuotablePerson / pkg1.QuotablePerson
|
||||
name: QuotablePerson / pkg1.QuotablePerson / pkg1.QuotablePerson
|
||||
superclass:
|
||||
java.lang.Enum<pkg1.QuotablePerson>
|
||||
enum constants:
|
||||
@ -15,4 +15,4 @@ enum pkg1.QuotablePerson
|
||||
Eco
|
||||
methods:
|
||||
pkg1.QuotablePerson[] values()
|
||||
QuotablePerson valueOf(String)
|
||||
pkg1.QuotablePerson valueOf(String)
|
||||
|
||||
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4421066 5006659
|
||||
* @summary Verify the contents of a ClassDoc containing a varArgs method.
|
||||
* Verify that see/link tags can use "..." notation.
|
||||
* @ignore 8152313 convert to doclet test framework
|
||||
* @library ../lib
|
||||
* @modules jdk.javadoc
|
||||
* @compile ../lib/Tester.java Main.java
|
||||
* @run main Main
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.sun.javadoc.*;
|
||||
import jdk.javadoc.doclet.DocletEnvironment;
|
||||
|
||||
public class Main extends Tester.Doclet {
|
||||
|
||||
private static final Tester tester =
|
||||
new Tester("Main", "-Xwerror", "pkg1");
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
tester.run();
|
||||
tester.verify();
|
||||
}
|
||||
|
||||
public static boolean run(DocletEnvironment root) {
|
||||
try {
|
||||
for (ClassDoc cd : root.classes()) {
|
||||
tester.printClass(cd);
|
||||
|
||||
for (SeeTag tag : cd.seeTags()) {
|
||||
if (tag.referencedMember() != cd.methods()[0]) {
|
||||
throw new Error("5006659: @see tag meets varArgs");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
165
test/langtools/jdk/javadoc/tool/varArgs/VarArgsTest.java
Normal file
165
test/langtools/jdk/javadoc/tool/varArgs/VarArgsTest.java
Normal file
@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4421066 5006659
|
||||
* @summary Verify the contents of a ClassDoc containing a varArgs method.
|
||||
* Verify that see/link tags can use "..." notation.
|
||||
* @library ../../lib
|
||||
* @modules jdk.javadoc/jdk.javadoc.internal.tool
|
||||
* @build javadoc.tester.*
|
||||
* @run main VarArgsTest
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.type.ArrayType;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.lang.model.util.ElementFilter;
|
||||
|
||||
import com.sun.source.doctree.DocCommentTree;
|
||||
import com.sun.source.doctree.DocTree;
|
||||
import com.sun.source.doctree.SeeTree;
|
||||
import com.sun.source.util.DocTreePath;
|
||||
import com.sun.source.util.DocTrees;
|
||||
import com.sun.source.util.TreePath;
|
||||
import javadoc.tester.TestDoclet;
|
||||
import jdk.javadoc.doclet.DocletEnvironment;
|
||||
|
||||
import javadoc.tester.JavadocTester;
|
||||
|
||||
public class VarArgsTest extends JavadocTester {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
JavadocTester t = new VarArgsTest();
|
||||
t.runTests();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarArgs() throws Exception {
|
||||
javadoc("-sourcepath", testSrc,
|
||||
"-docletpath", System.getProperty("test.class.path"),
|
||||
"-doclet", "VarArgsTest$ThisDoclet",
|
||||
"pkg1");
|
||||
checkExit(Exit.OK);
|
||||
|
||||
String expect = Files.readAllLines(Path.of(testSrc).resolve("expected.out"))
|
||||
.stream()
|
||||
.collect(Collectors.joining("\n"));
|
||||
checkOutput(Output.STDOUT, true, expect);
|
||||
}
|
||||
|
||||
|
||||
public static class ThisDoclet extends TestDoclet {
|
||||
public boolean run(DocletEnvironment env) {
|
||||
DocTrees trees = env.getDocTrees();
|
||||
try {
|
||||
for (Element e : env.getIncludedElements()) {
|
||||
if (e.getKind() == ElementKind.INTERFACE) {
|
||||
printClass((TypeElement) e);
|
||||
|
||||
TreePath tp = trees.getPath(e);
|
||||
DocCommentTree dct = trees.getDocCommentTree(e);
|
||||
DocTreePath dtp = new DocTreePath(tp, dct);
|
||||
|
||||
ExecutableElement m0 = ElementFilter.methodsIn(e.getEnclosedElements()).get(0);
|
||||
for (DocTree t : dct.getBlockTags()) {
|
||||
if (t.getKind() == DocTree.Kind.SEE) {
|
||||
SeeTree st = (SeeTree) t;
|
||||
DocTreePath sp = new DocTreePath(dtp, st.getReference().get(0));
|
||||
Element se = trees.getElement(sp);
|
||||
System.err.println("Expect: " + m0);
|
||||
System.err.println("Found: " + se);
|
||||
if (se != m0) {
|
||||
throw new Error("unexpected value for @see reference");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// this method mimics the printClass method from the old
|
||||
// tester framework
|
||||
void printClass(TypeElement te) {
|
||||
PrintStream out = System.out;
|
||||
out.format("%s %s%n",
|
||||
te.getKind().toString().toLowerCase(),
|
||||
te.getQualifiedName());
|
||||
out.format(" name: %s / %s / %s%n",
|
||||
te.getSimpleName(), te.asType(), te.getQualifiedName());
|
||||
out.format(" methods:%n");
|
||||
te.getEnclosedElements().stream()
|
||||
.filter(e -> e.getKind() == ElementKind.METHOD)
|
||||
.map(e -> (ExecutableElement) e)
|
||||
.forEach(e -> out.format(" %s %s(%s)%n",
|
||||
e.getReturnType(),
|
||||
e.getSimpleName(),
|
||||
e.getParameters().stream()
|
||||
.map(this::paramToString)
|
||||
.collect(Collectors.joining(", "))
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
private String paramToString(Element e) {
|
||||
System.err.println("paramToString " + e);
|
||||
ExecutableElement m = (ExecutableElement) e.getEnclosingElement();
|
||||
return typeToString(m, e.asType());
|
||||
}
|
||||
|
||||
private String typeToString(ExecutableElement method, TypeMirror t) {
|
||||
System.err.println("typeToString " + method + " " + t + " " + t.getKind());
|
||||
switch (t.getKind()) {
|
||||
case INT:
|
||||
return t.getKind().toString().toLowerCase();
|
||||
|
||||
case DECLARED:
|
||||
return ((DeclaredType) t).asElement().getSimpleName().toString();
|
||||
|
||||
case ARRAY:
|
||||
String cs = typeToString(method, ((ArrayType) t).getComponentType());
|
||||
String suffix = method.isVarArgs() ? "..." : "[]";
|
||||
return cs + suffix;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException(t.getKind() + " " + t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
interface pkg1.A
|
||||
name: A / A / pkg1.A
|
||||
name: A / pkg1.A / pkg1.A
|
||||
methods:
|
||||
void m1(int, String...)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user