8157682: @inheritDoc doesn't work with @exception

Co-authored-by: Yano, Masanori <yano-masanori@jp.fujitsu.com>
Co-authored-by: Jonathan Gibbons <jjg@openjdk.org>
Reviewed-by: prappo
This commit is contained in:
Jonathan Gibbons 2021-03-05 15:24:44 +00:00
parent 8c13d26dae
commit 97557826f5
2 changed files with 133 additions and 18 deletions

View File

@ -30,7 +30,6 @@ import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashSet;
@ -40,7 +39,7 @@ import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.TreeSet;
import java.util.TreeMap;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
@ -98,7 +97,12 @@ public class TagletManager {
public static final char SIMPLE_TAGLET_OPT_SEPARATOR = ':';
/**
* All taglets, keyed by their {@link Taglet#getName() name}.
* All taglets, keyed either by their {@link Taglet#getName() name},
* or by an alias.
*
* In general, taglets do <i>not</i> provide aliases;
* the one instance that does is {@code ThrowsTaglet}, which handles
* both {@code @throws} tags and {@code @exception} tags.
*/
private final LinkedHashMap<String, Taglet> allTaglets;
@ -577,17 +581,15 @@ public class TagletManager {
inlineTags = new LinkedHashMap<>();
for (Taglet t : allTaglets.values()) {
allTaglets.forEach((name, t) -> {
if (t.isInlineTag()) {
inlineTags.put(t.getName(), t);
}
if (t.isBlockTag()) {
for (Location l : t.getAllowedLocations()) {
blockTagletsByLocation.get(l).add(t);
}
if (t.isBlockTag() && t.getName().equals(name)) {
t.getAllowedLocations().forEach(l -> blockTagletsByLocation.get(l).add(t));
}
}
});
// init the serialized form tags for the serialized form page
serializedFormTags = new ArrayList<>();
@ -612,10 +614,7 @@ public class TagletManager {
addStandardTaglet(new ParamTaglet());
addStandardTaglet(new ReturnTaglet());
addStandardTaglet(new ThrowsTaglet());
addStandardTaglet(
new SimpleTaglet(EXCEPTION, null,
EnumSet.of(Location.METHOD, Location.CONSTRUCTOR)));
addStandardTaglet(new ThrowsTaglet(), EXCEPTION);
addStandardTaglet(
new SimpleTaglet(SINCE, resources.getText("doclet.Since"),
EnumSet.allOf(Location.class), !nosince));
@ -683,6 +682,14 @@ public class TagletManager {
standardTagsLowercase.add(Utils.toLowerCase(name));
}
private void addStandardTaglet(Taglet taglet, DocTree.Kind alias) {
addStandardTaglet(taglet);
String name = alias.tagName;
allTaglets.put(name, taglet);
standardTags.add(name);
standardTagsLowercase.add(Utils.toLowerCase(name));
}
public boolean isKnownCustomTag(String tagName) {
return allTaglets.containsKey(tagName);
}
@ -729,12 +736,11 @@ public class TagletManager {
* a need for a corresponding update to the spec.
*/
private void showTaglets(PrintStream out) {
Set<Taglet> taglets = new TreeSet<>(Comparator.comparing(Taglet::getName));
taglets.addAll(allTaglets.values());
Map<String, Taglet> taglets = new TreeMap<>(allTaglets);
for (Taglet t : taglets) {
taglets.forEach((n, t) -> {
// give preference to simpler block form if a tag can be either
String name = t.isBlockTag() ? "@" + t.getName() : "{@" + t.getName() + "}";
String name = t.isBlockTag() ? "@" + n : "{@" + n + "}";
out.println(String.format("%20s", name) + ": "
+ format(t.isBlockTag(), "block")+ " "
+ format(t.inOverview(), "overview") + " "
@ -746,7 +752,7 @@ public class TagletManager {
+ format(t.inField(), "field") + " "
+ format(t.isInlineTag(), "inline")+ " "
+ format((t instanceof SimpleTaglet) && !((SimpleTaglet) t).enabled, "disabled"));
}
});
}
private String format(boolean b, String s) {

View File

@ -0,0 +1,109 @@
/*
* Copyright (c) 2021, 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 8157682
* @summary at-inheritDoc doesn't work with at-exception
* @library /tools/lib ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build toolbox.ToolBox javadoc.tester.*
* @run main TestExceptionInheritance
*/
import java.nio.file.Path;
import javadoc.tester.JavadocTester;
import toolbox.ToolBox;
public class TestExceptionInheritance extends JavadocTester {
public static void main(String... args) throws Exception {
TestExceptionInheritance tester = new TestExceptionInheritance();
tester.runTests(m -> new Object[] { Path.of(m.getName()) });
}
ToolBox tb = new ToolBox();
@Test
public void testExceptionException(Path base) throws Exception {
test(base, "exception", "exception");
}
@Test
public void testExceptionThrows(Path base) throws Exception {
test(base, "exception", "throws");
}
@Test
public void testThrowsException(Path base) throws Exception {
test(base, "throws", "exception");
}
@Test
public void testThrowsThrows(Path base) throws Exception {
test(base, "throws", "throws");
}
void test(Path base, String a, String b) throws Exception {
Path src = base.resolve("src");
tb.writeJavaFiles(src,
"""
package p;
public class A {
/**
* @param x a number
* @##A## NullPointerException if x is null
* @##A## IllegalArgumentException if {@code x < 0}
*/
public void m(Integer x) { }
}
""".replace("##A##", a),
"""
package p;
public class A_Sub extends A {
/**
* @param x {@inheritDoc}
* @##B## NullPointerException {@inheritDoc}
* @##B## IllegalArgumentException {@inheritDoc}
*/
@Override
public void m(Integer x) { }
}
""".replace("##B##", b)
);
javadoc("-d", base.resolve("out").toString(),
"-sourcepath", src.toString(),
"--no-platform-links",
"p");
checkExit(Exit.OK);
checkOutput("p/A_Sub.html", true,
"<code>java.lang.NullPointerException</code> - if x is null");
checkOutput("p/A_Sub.html", true,
"<code>java.lang.IllegalArgumentException</code> - if <code>x &lt; 0</code>");
}
}