diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractExecutableMemberWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractExecutableMemberWriter.java index 1759c0c7263ac..eff6d391b4499 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractExecutableMemberWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractExecutableMemberWriter.java @@ -51,6 +51,7 @@ import static jdk.javadoc.internal.doclets.formats.html.LinkInfoImpl.Kind.MEMBER; import static jdk.javadoc.internal.doclets.formats.html.LinkInfoImpl.Kind.MEMBER_TYPE_PARAMS; import static jdk.javadoc.internal.doclets.formats.html.LinkInfoImpl.Kind.RECEIVER_TYPE; +import static jdk.javadoc.internal.doclets.formats.html.LinkInfoImpl.Kind.THROWS_TYPE; /** * Print method and constructor info. @@ -254,19 +255,16 @@ protected Content getParameters(ExecutableElement member, boolean includeAnnotat */ protected Content getExceptions(ExecutableElement member) { List exceptions = utils.asInstantiatedMethodType(typeElement, member).getThrownTypes(); - Content htmltree = new ContentBuilder(); - if (!exceptions.isEmpty()) { - Content link = writer.getLink(new LinkInfoImpl(configuration, MEMBER, exceptions.get(0))); - htmltree.add(link); - for (int i = 1; i < exceptions.size(); i++) { - htmltree.add(","); - htmltree.add(DocletConstants.NL); - Content exceptionLink = writer.getLink(new LinkInfoImpl(configuration, MEMBER, - exceptions.get(i))); - htmltree.add(exceptionLink); + Content htmlTree = new ContentBuilder(); + for (TypeMirror t : exceptions) { + if (!htmlTree.isEmpty()) { + htmlTree.add(","); + htmlTree.add(DocletConstants.NL); } + Content link = writer.getLink(new LinkInfoImpl(configuration, THROWS_TYPE, t)); + htmlTree.add(link); } - return htmltree; + return htmlTree; } protected TypeElement implementsMethodInIntfac(ExecutableElement method, @@ -303,7 +301,7 @@ protected String getErasureAnchor(ExecutableElement executableElement) { buf.append(","); } TypeMirror t = parameters.get(i).asType(); - SimpleTypeVisitor9 stv = new SimpleTypeVisitor9() { + SimpleTypeVisitor9 stv = new SimpleTypeVisitor9<>() { boolean foundTypeVariable = false; @Override diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/LinkInfoImpl.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/LinkInfoImpl.java index 7ab8c39c632fe..8e886f9b88c7a 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/LinkInfoImpl.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/LinkInfoImpl.java @@ -208,14 +208,19 @@ public enum Kind { PROPERTY_COPY, /** - * A receiver type + * A receiver type. */ RECEIVER_TYPE, /** - * A record component within a class signature + * A record component within a class signature. */ - RECORD_COMPONENT + RECORD_COMPONENT, + + /** + * A type thrown from a method. + */ + THROWS_TYPE } public final HtmlConfiguration configuration; @@ -389,9 +394,8 @@ public final void setContext(Kind c) { case RETURN_TYPE: case SUMMARY_RETURN_TYPE: - excludeTypeBounds = true; - break; case EXECUTABLE_MEMBER_PARAM: + case THROWS_TYPE: excludeTypeBounds = true; break; } diff --git a/test/langtools/jdk/javadoc/doclet/testThrows/TestThrows.java b/test/langtools/jdk/javadoc/doclet/testThrows/TestThrows.java new file mode 100644 index 0000000000000..8cc50456b8cf2 --- /dev/null +++ b/test/langtools/jdk/javadoc/doclet/testThrows/TestThrows.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2002, 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. + */ + + /* + * @test + * @bug 8253700 + * @summary spurious "extends Throwable" at end of method declaration + * throws section. Make sure that the link is below a Throws heading. + * @library /tools/lib ../../lib + * @modules jdk.javadoc/jdk.javadoc.internal.tool + * @build javadoc.tester.* toolbox.ToolBox + * @run main TestThrows + */ + + import java.io.IOException; + import java.nio.file.Path; + + import toolbox.ToolBox; + + import javadoc.tester.JavadocTester; + + public class TestThrows extends JavadocTester { + + public static void main(String... args) throws Exception { + TestThrows tester = new TestThrows(); + tester.runTests(m -> new Object[] { Path.of(m.getName()) }); + } + + private final ToolBox tb = new ToolBox(); + + @Test + public void testThrowsWithBound(Path base) throws IOException { + Path src = base.resolve("src"); + tb.writeJavaFiles(src, + """ + /** + * This is interface C. + */ + public interface C { + /** + * Method m. + * @param the throwable + * @throws T if a specific error occurs + * @throws Exception if an exception occurs + */ + void m() throws T, Exception; + } + """); + + javadoc("-d", base.resolve("out").toString(), + src.resolve("C.java").toString()); + checkExit(Exit.OK); + + checkOutput("C.html", true, + """ +
<T extends java\ + .lang.Throwable> void m() + throws T, + java.lang.Exception
+ """, + """ +
+
Type Parameters:
+
T - the throwable
+
Throws:
+
T - if a specific error occurs
+
java.lang.Exception - if an exception occurs
+
+ """); + } +}