mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-11 05:59:52 +00:00
8287379: Using @inheritDoc in an inapplicable context shouldn't crash javadoc
Reviewed-by: jjg
This commit is contained in:
parent
fed3af8ae0
commit
62fbc3f883
@ -1485,7 +1485,7 @@ public class HtmlDocletWriter {
|
||||
};
|
||||
CommentHelper ch = utils.getCommentHelper(element);
|
||||
// Array of all possible inline tags for this javadoc run
|
||||
configuration.tagletManager.checkTags(element, trees, true);
|
||||
configuration.tagletManager.checkTags(element, trees);
|
||||
commentRemoved = false;
|
||||
|
||||
for (ListIterator<? extends DocTree> iterator = trees.listIterator(); iterator.hasNext();) {
|
||||
|
||||
@ -28,9 +28,8 @@ package jdk.javadoc.internal.doclets.toolkit.taglets;
|
||||
import java.util.EnumSet;
|
||||
|
||||
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.TypeKind;
|
||||
|
||||
import com.sun.source.doctree.DocTree;
|
||||
import jdk.javadoc.doclet.Taglet.Location;
|
||||
@ -42,9 +41,7 @@ import jdk.javadoc.internal.doclets.toolkit.util.DocFinder;
|
||||
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
|
||||
|
||||
/**
|
||||
* An inline taglet representing the {@code {@inheritDoc}} tag.
|
||||
* It is used to copy documentation from superclass (but not superinterface)
|
||||
* declarations and from overridden and implemented methods.
|
||||
* A taglet that represents the {@code {@inheritDoc}} tag.
|
||||
*/
|
||||
public class InheritDocTaglet extends BaseTaglet {
|
||||
|
||||
@ -52,7 +49,7 @@ public class InheritDocTaglet extends BaseTaglet {
|
||||
* Construct a new InheritDocTaglet.
|
||||
*/
|
||||
public InheritDocTaglet() {
|
||||
super(DocTree.Kind.INHERIT_DOC, true, EnumSet.of(Location.TYPE, Location.METHOD));
|
||||
super(DocTree.Kind.INHERIT_DOC, true, EnumSet.of(Location.METHOD));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,14 +93,6 @@ public class InheritDocTaglet extends BaseTaglet {
|
||||
inheritedDoc.inlineTags, isFirstSentence);
|
||||
}
|
||||
} else {
|
||||
// This is to assert that we don't reach here for a class declaration.
|
||||
// Indeed, every class except for java.lang.Object has a superclass.
|
||||
// If we ever reach here, we would need a different warning; because
|
||||
// the below warning is about method declarations, not class declarations.
|
||||
// Unless @inheritDoc is used inside java.lang.Object itself,
|
||||
// which would clearly be an error, we shouldn't reach here.
|
||||
assert !(e instanceof TypeElement typeElement)
|
||||
|| typeElement.getSuperclass().getKind() == TypeKind.NONE;
|
||||
String signature = utils.getSimpleName(e) +
|
||||
((utils.isExecutableElement(e))
|
||||
? utils.flatSignature((ExecutableElement) e, writer.getCurrentPageElement())
|
||||
@ -115,6 +104,9 @@ public class InheritDocTaglet extends BaseTaglet {
|
||||
|
||||
@Override
|
||||
public Content getInlineTagOutput(Element e, DocTree inheritDoc, TagletWriter tagletWriter) {
|
||||
if (e.getKind() != ElementKind.METHOD) {
|
||||
return tagletWriter.getOutputInstance();
|
||||
}
|
||||
return retrieveInheritedDocumentation(tagletWriter, e, inheritDoc, tagletWriter.isFirstSentence);
|
||||
}
|
||||
}
|
||||
|
||||
@ -350,16 +350,12 @@ public class TagletManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a series of {@code DocTree}s, check for spelling mistakes.
|
||||
* Given a series of {@code DocTree}s, check for misuse and spelling mistakes.
|
||||
*
|
||||
* @param element the tags holder
|
||||
* @param trees the trees containing the comments
|
||||
* @param inlineTrees true if the trees are inline and false otherwise
|
||||
*/
|
||||
public void checkTags(Element element, Iterable<? extends DocTree> trees, boolean inlineTrees) {
|
||||
if (trees == null) {
|
||||
return;
|
||||
}
|
||||
public void checkTags(Element element, Iterable<? extends DocTree> trees) {
|
||||
CommentHelper ch = utils.getCommentHelper(element);
|
||||
for (DocTree tag : trees) {
|
||||
String name = tag.getKind().tagName;
|
||||
@ -386,73 +382,62 @@ public class TagletManager {
|
||||
return;
|
||||
}
|
||||
|
||||
if (inlineTrees && !taglet.isInlineTag()) {
|
||||
printTagMisuseWarn(ch, taglet, tag, "inline");
|
||||
}
|
||||
|
||||
// nothing more to do
|
||||
if (element == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!inlineTrees) {
|
||||
new SimpleElementVisitor14<Void, Void>() {
|
||||
@Override
|
||||
public Void visitModule(ModuleElement e, Void p) {
|
||||
if (!taglet.inModule()) {
|
||||
printTagMisuseWarn(utils.getCommentHelper(e), taglet, tag, "module");
|
||||
}
|
||||
return null;
|
||||
new SimpleElementVisitor14<Void, Void>() {
|
||||
@Override
|
||||
public Void visitModule(ModuleElement e, Void p) {
|
||||
if (!taglet.inModule()) {
|
||||
printTagMisuseWarn(utils.getCommentHelper(e), taglet, tag, "module");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitPackage(PackageElement e, Void p) {
|
||||
if (!taglet.inPackage()) {
|
||||
printTagMisuseWarn(utils.getCommentHelper(e), taglet, tag, "package");
|
||||
}
|
||||
return null;
|
||||
@Override
|
||||
public Void visitPackage(PackageElement e, Void p) {
|
||||
if (!taglet.inPackage()) {
|
||||
printTagMisuseWarn(utils.getCommentHelper(e), taglet, tag, "package");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitType(TypeElement e, Void p) {
|
||||
if (!taglet.inType()) {
|
||||
printTagMisuseWarn(utils.getCommentHelper(e), taglet, tag, "class");
|
||||
}
|
||||
return null;
|
||||
@Override
|
||||
public Void visitType(TypeElement e, Void p) {
|
||||
if (!taglet.inType()) {
|
||||
printTagMisuseWarn(utils.getCommentHelper(e), taglet, tag, "class");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitExecutable(ExecutableElement e, Void p) {
|
||||
if (utils.isConstructor(e) && !taglet.inConstructor()) {
|
||||
printTagMisuseWarn(utils.getCommentHelper(e), taglet, tag, "constructor");
|
||||
} else if (!taglet.inMethod()) {
|
||||
printTagMisuseWarn(utils.getCommentHelper(e), taglet, tag, "method");
|
||||
}
|
||||
return null;
|
||||
@Override
|
||||
public Void visitExecutable(ExecutableElement e, Void p) {
|
||||
if (utils.isConstructor(e) && !taglet.inConstructor()) {
|
||||
printTagMisuseWarn(utils.getCommentHelper(e), taglet, tag, "constructor");
|
||||
} else if (!taglet.inMethod()) {
|
||||
printTagMisuseWarn(utils.getCommentHelper(e), taglet, tag, "method");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitVariable(VariableElement e, Void p) {
|
||||
if (utils.isField(e) && !taglet.inField()) {
|
||||
printTagMisuseWarn(utils.getCommentHelper(e), taglet, tag, "field");
|
||||
}
|
||||
return null;
|
||||
@Override
|
||||
public Void visitVariable(VariableElement e, Void p) {
|
||||
if (utils.isField(e) && !taglet.inField()) {
|
||||
printTagMisuseWarn(utils.getCommentHelper(e), taglet, tag, "field");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitUnknown(Element e, Void p) {
|
||||
if (utils.isOverviewElement(e) && !taglet.inOverview()) {
|
||||
printTagMisuseWarn(utils.getCommentHelper(e), taglet, tag, "overview");
|
||||
}
|
||||
return null;
|
||||
@Override
|
||||
public Void visitUnknown(Element e, Void p) {
|
||||
if (utils.isOverviewElement(e) && !taglet.inOverview()) {
|
||||
printTagMisuseWarn(utils.getCommentHelper(e), taglet, tag, "overview");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void defaultAction(Element e, Void p) {
|
||||
return null;
|
||||
}
|
||||
}.visit(element);
|
||||
}
|
||||
@Override
|
||||
protected Void defaultAction(Element e, Void p) {
|
||||
return null;
|
||||
}
|
||||
}.visit(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -489,22 +474,13 @@ public class TagletManager {
|
||||
if (taglet.inMethod()) {
|
||||
locationsSet.add("method");
|
||||
}
|
||||
if (taglet.isInlineTag()) {
|
||||
locationsSet.add("inline text");
|
||||
}
|
||||
if (locationsSet.isEmpty()) {
|
||||
//This known tag is excluded.
|
||||
return;
|
||||
}
|
||||
StringBuilder combined_locations = new StringBuilder();
|
||||
for (String location: locationsSet) {
|
||||
if (combined_locations.length() > 0) {
|
||||
combined_locations.append(", ");
|
||||
}
|
||||
combined_locations.append(location);
|
||||
}
|
||||
var combined_locations = String.join(", ", locationsSet);
|
||||
messages.warning(ch.getDocTreePath(tag), "doclet.tag_misuse",
|
||||
"@" + taglet.getName(), holderType, combined_locations.toString());
|
||||
"@" + taglet.getName(), holderType, combined_locations);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -275,8 +275,8 @@ public abstract class TagletWriter {
|
||||
|
||||
Content output = getOutputInstance();
|
||||
Utils utils = configuration().utils;
|
||||
tagletManager.checkTags(element, utils.getBlockTags(element), false);
|
||||
tagletManager.checkTags(element, utils.getFullBody(element), true);
|
||||
tagletManager.checkTags(element, utils.getBlockTags(element));
|
||||
tagletManager.checkTags(element, utils.getFullBody(element));
|
||||
for (Taglet taglet : taglets) {
|
||||
if (utils.isTypeElement(element) && taglet instanceof ParamTaglet) {
|
||||
// The type parameters and state components are documented in a special
|
||||
|
||||
@ -30,7 +30,6 @@ import java.util.*;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
|
||||
import com.sun.source.doctree.DocTree;
|
||||
import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
|
||||
@ -258,17 +257,6 @@ public class DocFinder {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
} else if (utils.isTypeElement(input.element)) {
|
||||
TypeMirror t = ((TypeElement) input.element).getSuperclass();
|
||||
Element superclass = utils.asTypeElement(t);
|
||||
if (superclass != null) {
|
||||
inheritedSearchInput.element = superclass;
|
||||
output = search(configuration, inheritedSearchInput);
|
||||
output.isValidInheritDocTag = true;
|
||||
if (!output.inlineTags.isEmpty()) {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
@ -193,7 +193,7 @@ public class Checker extends DocTreePathScanner<Void, Void> {
|
||||
reportMissing("dc.missing.comment");
|
||||
}
|
||||
return null;
|
||||
} else if (tree.getFirstSentence().isEmpty() && !isOverridingMethod) {
|
||||
} else if (tree.getFirstSentence().isEmpty() && !isOverridingMethod && !pseudoElement(p)) {
|
||||
if (tree.getBlockTags().isEmpty()) {
|
||||
reportMissing("dc.empty.comment");
|
||||
return null;
|
||||
@ -224,7 +224,7 @@ public class Checker extends DocTreePathScanner<Void, Void> {
|
||||
|
||||
// this is for html files
|
||||
// ... if it is a legacy package.html, the doc comment comes after the <h1> page title
|
||||
// ... otherwise, (e.g. overview file and doc-files/*.html files) no additional headings are inserted
|
||||
// ... otherwise, (e.g. overview file and doc-files/**/*.html files) no additional headings are inserted
|
||||
case COMPILATION_UNIT -> fo.isNameCompatible("package", JavaFileObject.Kind.HTML) ? 1 : 0;
|
||||
|
||||
|
||||
@ -292,6 +292,13 @@ public class Checker extends DocTreePathScanner<Void, Void> {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Checks if the passed tree path corresponds to an entity, such as
|
||||
// the overview file and doc-files/**/*.html files.
|
||||
private boolean pseudoElement(TreePath p) {
|
||||
return p.getLeaf().getKind() == Tree.Kind.COMPILATION_UNIT
|
||||
&& p.getCompilationUnit().getSourceFile().getKind() == JavaFileObject.Kind.HTML;
|
||||
}
|
||||
|
||||
private void reportMissing(String code, Object... args) {
|
||||
env.messages.report(MISSING, Kind.WARNING, env.currPath.getLeaf(), code, args);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2022, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8008768
|
||||
* @bug 8008768 8287379
|
||||
* @summary Using {@inheritDoc} in simple tag defined via -tag fails
|
||||
* @library ../../lib
|
||||
* @modules jdk.javadoc/jdk.javadoc.internal.tool
|
||||
@ -33,13 +33,6 @@
|
||||
|
||||
import javadoc.tester.JavadocTester;
|
||||
|
||||
/**
|
||||
* DocTest documentation.
|
||||
*
|
||||
* @apiNote DocTest API note.
|
||||
* @implSpec DocTest implementation spec.
|
||||
* @implNote DocTest implementation note.
|
||||
*/
|
||||
public class DocTest extends JavadocTester {
|
||||
public static void main(String... args) throws Exception {
|
||||
DocTest tester = new DocTest();
|
||||
@ -51,9 +44,9 @@ public class DocTest extends JavadocTester {
|
||||
javadoc("-verbose",
|
||||
"-d", "DocTest",
|
||||
"-sourcepath", System.getProperty("test.src.path"),
|
||||
"-tag", "apiNote:optcm:<em>API Note</em>",
|
||||
"-tag", "implSpec:optcm:<em>Implementation Requirements</em>:",
|
||||
"-tag", "implNote:optcm:<em>Implementation Note</em>:",
|
||||
"-tag", "apiNote:a:API Note",
|
||||
"-tag", "implSpec:a:Implementation Requirements:",
|
||||
"-tag", "implNote:a:Implementation Note:",
|
||||
"-package",
|
||||
testSrc("DocTest.java")
|
||||
);
|
||||
@ -64,16 +57,6 @@ public class DocTest extends JavadocTester {
|
||||
checkOutput(Output.STDERR, false, "at com.sun");
|
||||
}
|
||||
|
||||
/**
|
||||
* DocTest() documentation.
|
||||
*
|
||||
* @apiNote DocTest() API note.
|
||||
* @implSpec DocTest() implementation spec.
|
||||
* @implNote DocTest() implementation note.
|
||||
*/
|
||||
public DocTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* DocTest.testMethod() documentation.
|
||||
*
|
||||
@ -85,43 +68,8 @@ public class DocTest extends JavadocTester {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* DocTestWithTags documentation.
|
||||
*
|
||||
* @apiNote DocTestWithTags API note.
|
||||
* <pre>
|
||||
* DocTestWithTags API note code sample.
|
||||
* </pre>
|
||||
* @implSpec DocTestWithTags implementation spec.
|
||||
* <pre>
|
||||
* DocTestWithTags implementation spec code sample.
|
||||
* </pre>
|
||||
* @implNote DocTestWithTags implementation note.
|
||||
* <pre>
|
||||
* DocTestWithTags implementation note code sample.
|
||||
* </pre>
|
||||
*/
|
||||
class DocTestWithTags {
|
||||
|
||||
/**
|
||||
* DocTestWithTags() documentation.
|
||||
*
|
||||
* @apiNote DocTestWithTags() API note.
|
||||
* <pre>
|
||||
* DocTestWithTags() API note code sample.
|
||||
* </pre>
|
||||
* @implSpec DocTestWithTags() implementation spec.
|
||||
* <pre>
|
||||
* DocTestWithTags() implementation spec code sample.
|
||||
* </pre>
|
||||
* @implNote DocTest() implementation note.
|
||||
* <pre>
|
||||
* DocTest() implementation note code sample.
|
||||
* </pre>
|
||||
*/
|
||||
public DocTestWithTags() {
|
||||
}
|
||||
|
||||
/**
|
||||
* DocTest.testMethod() documentation.
|
||||
*
|
||||
@ -131,11 +79,11 @@ class DocTestWithTags {
|
||||
* </pre>
|
||||
* @implSpec DocTestWithTags.testMethod() implementation spec.
|
||||
* <pre>
|
||||
* DocTestWithTags.testMethod() API implementation spec code sample.
|
||||
* DocTestWithTags.testMethod() implementation spec code sample.
|
||||
* </pre>
|
||||
* @implNote DocTest.testMethod() implementation note.
|
||||
* <pre>
|
||||
* DocTest.testMethod() API implementation code sample.
|
||||
* DocTest.testMethod() implementation note code sample.
|
||||
* </pre>
|
||||
*/
|
||||
public void testMethod() {
|
||||
@ -145,52 +93,26 @@ class DocTestWithTags {
|
||||
class MinimallyExtendsDocTest extends DocTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* SimpleExtendsDocTest documentation.
|
||||
*/
|
||||
class SimpleExtendsDocTest extends DocTest {
|
||||
|
||||
/**
|
||||
* SimpleExtendsDocTest() documentation.
|
||||
* SimpleExtendsDocTest.testMethod() documentation.
|
||||
*/
|
||||
public SimpleExtendsDocTest() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* SimpleExtendsDocTest.testMethod() documenation.
|
||||
*/
|
||||
@java.lang.Override
|
||||
@Override
|
||||
public void testMethod() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
class SimpleInheritDocDocTest extends DocTest {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public SimpleInheritDocDocTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@java.lang.Override
|
||||
@Override
|
||||
public void testMethod() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @apiNote {@inheritDoc}
|
||||
* @implSpec {@inheritDoc}
|
||||
* @implNote {@inheritDoc}
|
||||
*/
|
||||
class FullInheritDocDocTest extends DocTest {
|
||||
|
||||
/**
|
||||
@ -200,50 +122,21 @@ class FullInheritDocDocTest extends DocTest {
|
||||
* @implSpec {@inheritDoc}
|
||||
* @implNote {@inheritDoc}
|
||||
*/
|
||||
public FullInheritDocDocTest() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @apiNote {@inheritDoc}
|
||||
* @implSpec {@inheritDoc}
|
||||
* @implNote {@inheritDoc}
|
||||
*/
|
||||
@java.lang.Override
|
||||
@Override
|
||||
public void testMethod() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc} and FullInheritDocPlusDocTest documentation.
|
||||
*
|
||||
* @implSpec {@inheritDoc} and FullInheritDocPlusDocTest API note.
|
||||
* @implNote {@inheritDoc} and FullInheritDocPlusDocTest implementation specification.
|
||||
* @apiNote {@inheritDoc} and FullInheritDocPlusDocTest implementation note.
|
||||
*/
|
||||
class FullInheritDocPlusDocTest extends DocTest {
|
||||
|
||||
/**
|
||||
* {@inheritDoc} and FullInheritDocPlusDocTest() documentation.
|
||||
*
|
||||
* @implSpec {@inheritDoc} and FullInheritDocPlusDocTest() API note.
|
||||
* @implNote {@inheritDoc} and FullInheritDocPlusDocTest() implementation specification.
|
||||
* @apiNote {@inheritDoc} and FullInheritDocPlusDocTest() implementation note.
|
||||
*/
|
||||
public FullInheritDocPlusDocTest() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc} and FullInheritDocPlusDocTest.testMethod() documentation.
|
||||
*
|
||||
* @implSpec {@inheritDoc} and FullInheritDocPlusDocTest.testMethod() API note.
|
||||
* @implNote {@inheritDoc} and FullInheritDocPlusDocTest.testMethod() implementation specification.
|
||||
* @apiNote {@inheritDoc} and FullInheritDocPlusDocTest.testMethod() implementation note.
|
||||
* @implSpec {@inheritDoc} and FullInheritDocPlusDocTest.testMethod() implementation specification.
|
||||
* @implNote {@inheritDoc} and FullInheritDocPlusDocTest.testMethod() implementation note.
|
||||
* @apiNote {@inheritDoc} and FullInheritDocPlusDocTest.testMethod() API note.
|
||||
*/
|
||||
@java.lang.Override
|
||||
@Override
|
||||
public void testMethod() {
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8284299
|
||||
* @bug 8284299 8287379
|
||||
* @library /tools/lib ../../lib
|
||||
* @modules jdk.javadoc/jdk.javadoc.internal.tool
|
||||
* @build toolbox.ToolBox javadoc.tester.*
|
||||
@ -97,4 +97,171 @@ public class TestInheritDocWithinInappropriateTag extends JavadocTester {
|
||||
^
|
||||
""");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassOrInterfaceMainDescription(Path base) throws Exception {
|
||||
Path src = base.resolve("src");
|
||||
tb.writeJavaFiles(src,
|
||||
"""
|
||||
/** Class A. */
|
||||
public class A { }
|
||||
""",
|
||||
"""
|
||||
/** {@inheritDoc} */
|
||||
public class B extends A { }
|
||||
""",
|
||||
"""
|
||||
/** Interface C. */
|
||||
public interface C { }
|
||||
""",
|
||||
"""
|
||||
/** {@inheritDoc} */
|
||||
public interface D extends C { }
|
||||
""",
|
||||
"""
|
||||
/** Interface E. */
|
||||
public interface E { }
|
||||
""",
|
||||
"""
|
||||
/** {@inheritDoc} */
|
||||
public class F implements E { }
|
||||
""");
|
||||
javadoc("-Xdoclint:none",
|
||||
"-d", base.resolve("out").toString(),
|
||||
src.resolve("A.java").toString(),
|
||||
src.resolve("B.java").toString(),
|
||||
src.resolve("C.java").toString(),
|
||||
src.resolve("D.java").toString(),
|
||||
src.resolve("E.java").toString(),
|
||||
src.resolve("F.java").toString());
|
||||
checkExit(Exit.OK);
|
||||
new OutputChecker(Output.OUT).setExpectOrdered(false).check(
|
||||
"""
|
||||
B.java:1: warning: Tag @inheritDoc cannot be used in class documentation.\
|
||||
It can only be used in the following types of documentation: method.
|
||||
/** {@inheritDoc} */
|
||||
^
|
||||
""",
|
||||
"""
|
||||
D.java:1: warning: Tag @inheritDoc cannot be used in class documentation.\
|
||||
It can only be used in the following types of documentation: method.
|
||||
/** {@inheritDoc} */
|
||||
^
|
||||
""",
|
||||
"""
|
||||
F.java:1: warning: Tag @inheritDoc cannot be used in class documentation.\
|
||||
It can only be used in the following types of documentation: method.
|
||||
/** {@inheritDoc} */
|
||||
^
|
||||
""");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassOrInterfaceTypeParameter(Path base) throws Exception {
|
||||
Path src = base.resolve("src");
|
||||
tb.writeJavaFiles(src,
|
||||
"""
|
||||
/** @param <T> A's parameter */
|
||||
public class A<T> { }
|
||||
""",
|
||||
"""
|
||||
/** @param <T> {@inheritDoc} */
|
||||
public class B extends A { }
|
||||
""",
|
||||
"""
|
||||
/** @param <T> C's parameter */
|
||||
public interface C<T> { }
|
||||
""",
|
||||
"""
|
||||
/** @param <T> {@inheritDoc} */
|
||||
public interface D<T> extends C<T> { }
|
||||
""",
|
||||
"""
|
||||
/** @param <T> E's parameter */
|
||||
public interface E<T> { }
|
||||
""",
|
||||
"""
|
||||
/** @param <T> {@inheritDoc} */
|
||||
public class F<T> implements E<T> { }
|
||||
""");
|
||||
javadoc("-Xdoclint:none",
|
||||
"-d", base.resolve("out").toString(),
|
||||
src.resolve("A.java").toString(),
|
||||
src.resolve("B.java").toString(),
|
||||
src.resolve("C.java").toString(),
|
||||
src.resolve("D.java").toString(),
|
||||
src.resolve("E.java").toString(),
|
||||
src.resolve("F.java").toString());
|
||||
checkExit(Exit.OK);
|
||||
new OutputChecker(Output.OUT).setExpectOrdered(false).check(
|
||||
"""
|
||||
B.java:1: warning: Tag @inheritDoc cannot be used in class documentation.\
|
||||
It can only be used in the following types of documentation: method.
|
||||
/** @param <T> {@inheritDoc} */
|
||||
^
|
||||
""",
|
||||
"""
|
||||
D.java:1: warning: Tag @inheritDoc cannot be used in class documentation.\
|
||||
It can only be used in the following types of documentation: method.
|
||||
/** @param <T> {@inheritDoc} */
|
||||
^
|
||||
""",
|
||||
"""
|
||||
F.java:1: warning: Tag @inheritDoc cannot be used in class documentation.\
|
||||
It can only be used in the following types of documentation: method.
|
||||
/** @param <T> {@inheritDoc} */
|
||||
^
|
||||
""");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverview(Path base) throws Exception {
|
||||
Path src = base.resolve("src");
|
||||
tb.writeJavaFiles(src, """
|
||||
package p;
|
||||
|
||||
/** A class */
|
||||
public class C { }
|
||||
""");
|
||||
tb.writeFile(src.resolve("overview.html"), """
|
||||
<HTML lang="EN">
|
||||
<HEAD>
|
||||
<TITLE>overview</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
{@inheritDoc}
|
||||
</BODY>
|
||||
</HTML>
|
||||
""");
|
||||
tb.writeFile(
|
||||
src.resolve("p").resolve("doc-files").resolve("example.html"), """
|
||||
<HTML lang="EN">
|
||||
<HEAD>
|
||||
<TITLE>example</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
{@inheritDoc}
|
||||
</BODY>
|
||||
</HTML>
|
||||
""");
|
||||
javadoc("-Xdoclint:none",
|
||||
"-overview", src.resolve("overview.html").toString(),
|
||||
"-d", base.resolve("out").toString(),
|
||||
"-sourcepath", src.toString(),
|
||||
"p");
|
||||
checkExit(Exit.OK);
|
||||
new OutputChecker(Output.OUT).setExpectOrdered(false).check(
|
||||
"""
|
||||
overview.html:6: warning: Tag @inheritDoc cannot be used in overview documentation.\
|
||||
It can only be used in the following types of documentation: method.
|
||||
{@inheritDoc}
|
||||
^
|
||||
""",
|
||||
"""
|
||||
example.html:6: warning: Tag @inheritDoc cannot be used in overview documentation.\
|
||||
It can only be used in the following types of documentation: method.
|
||||
{@inheritDoc}
|
||||
^
|
||||
""");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2022, 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
|
||||
@ -86,12 +86,8 @@ public class TestRelativeLinks extends JavadocTester {
|
||||
"""
|
||||
<a href="C.html#class-fragment">fragment class link</a>""");
|
||||
|
||||
// subclass in same pacakge
|
||||
// subclass in same package
|
||||
checkOutput("pkg/D.html", true,
|
||||
"""
|
||||
<a href="relative-class-link.html">relative class link</a>""",
|
||||
"""
|
||||
<a href="C.html#class-fragment">fragment class link</a>""",
|
||||
"""
|
||||
<a href="relative-method-link.html">relative method link</a>""",
|
||||
"""
|
||||
@ -102,10 +98,6 @@ public class TestRelativeLinks extends JavadocTester {
|
||||
|
||||
// subclass in subpackage
|
||||
checkOutput("pkg/sub/F.html", true,
|
||||
"""
|
||||
<a href="../../pkg/relative-class-link.html">relative class link</a>""",
|
||||
"""
|
||||
<a href="../../pkg/C.html#class-fragment">fragment class link</a>""",
|
||||
"""
|
||||
<a href="../../pkg/relative-method-link.html">relative method link</a>""",
|
||||
"""
|
||||
@ -149,10 +141,6 @@ public class TestRelativeLinks extends JavadocTester {
|
||||
|
||||
// CLASS_USE
|
||||
checkOutput("pkg/class-use/C.html", true,
|
||||
"""
|
||||
<a href="../../pkg/relative-class-link.html">relative class link</a>""",
|
||||
"""
|
||||
<a href="../../pkg/C.html#class-fragment">fragment class link</a>""",
|
||||
"""
|
||||
<a href="../../pkg/relative-field-link.html">relative field link</a>""",
|
||||
"""
|
||||
@ -175,19 +163,7 @@ public class TestRelativeLinks extends JavadocTester {
|
||||
"""
|
||||
<a href="../../pkg/relative-package-link.html">relative package link</a>""",
|
||||
"""
|
||||
<a href="../../pkg/package-summary.html#package-fragment">package fragment link</a>""",
|
||||
// subclass inheriting relative link doc
|
||||
"""
|
||||
<a href="../../pkg/relative-class-link.html">relative class link</a>""",
|
||||
"""
|
||||
<a href="../../pkg/C.html#class-fragment">fragment class link</a>""");
|
||||
|
||||
// sibling package summary
|
||||
checkOutput("pkg2/package-summary.html", true,
|
||||
"""
|
||||
<a href="../pkg/relative-class-link.html">relative class link</a>""",
|
||||
"""
|
||||
<a href="../pkg/C.html#class-fragment">fragment class link</a>""");
|
||||
<a href="../../pkg/package-summary.html#package-fragment">package fragment link</a>""");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2021, 2022, 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
|
||||
@ -24,8 +24,6 @@
|
||||
package pkg;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* A class that extends C and inherits some of its comments.
|
||||
*/
|
||||
public class D extends C {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2021, 2022, 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
|
||||
@ -26,8 +26,6 @@ package pkg.sub;
|
||||
import pkg.C;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* A class that extends C and inherits some of its comments.
|
||||
*/
|
||||
public class F extends C {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2022, 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
|
||||
@ -26,9 +26,7 @@ package pkg2;
|
||||
import pkg.C;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* A class that extends pkg.C from onother package and inherits some of its comments.
|
||||
* A class that extends pkg.C from another package and inherits some of its comments.
|
||||
*/
|
||||
public class E extends C {
|
||||
|
||||
|
||||
@ -44,14 +44,11 @@ public class TestSimpleTagInherit extends JavadocTester {
|
||||
public void test() {
|
||||
javadoc("-d", "out",
|
||||
"-sourcepath", testSrc,
|
||||
"-tag", "custom:optcm:<em>Custom:</em>",
|
||||
"-tag", "custom:m:<em>Custom:</em>",
|
||||
"p");
|
||||
checkExit(Exit.OK);
|
||||
|
||||
checkOutput("p/TestClass.html", true,
|
||||
"""
|
||||
<dt><em>Custom:</em></dt>
|
||||
<dd>doc for BaseClass class</dd>""",
|
||||
"""
|
||||
<dt><em>Custom:</em></dt>
|
||||
<dd>doc for BaseClass method</dd>""");
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2022, 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
|
||||
@ -23,9 +23,6 @@
|
||||
|
||||
package p;
|
||||
|
||||
/**
|
||||
* @custom doc for BaseClass class
|
||||
*/
|
||||
public class BaseClass {
|
||||
/**
|
||||
* @custom doc for BaseClass method
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2022, 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
|
||||
@ -23,9 +23,6 @@
|
||||
|
||||
package p;
|
||||
|
||||
/**
|
||||
* @custom {@inheritDoc}
|
||||
*/
|
||||
public class TestClass extends BaseClass {
|
||||
/**
|
||||
* @custom {@inheritDoc}
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
@factory: block ........ ...... ....... .... ........... method ..... ...... ........
|
||||
@hidden: block ........ ...... ....... type ........... method field ...... ........
|
||||
{@index}: ..... overview module package type constructor method field inline ........
|
||||
{@inheritDoc}: ..... ........ ...... ....... type ........... method ..... inline ........
|
||||
{@inheritDoc}: ..... ........ ...... ....... .... ........... method ..... inline ........
|
||||
{@link}: ..... overview module package type constructor method field inline ........
|
||||
{@linkplain}: ..... overview module package type constructor method field inline ........
|
||||
{@literal}: ..... overview module package type constructor method field inline ........
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user