Skip to content

Commit dd4a1bb

Browse files
author
Pavel Rappo
committedApr 6, 2022
8284299: Handle inheritDoc misuse more gracefully
Reviewed-by: jjg
1 parent 46ce2ef commit dd4a1bb

File tree

3 files changed

+104
-1
lines changed

3 files changed

+104
-1
lines changed
 

‎src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/doclets.properties

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ doclet.Version=Version:
115115
doclet.Factory=Factory:
116116
doclet.UnknownTag={0} is an unknown tag.
117117
doclet.UnknownTagLowercase={0} is an unknown tag -- same as a known tag except for case.
118+
doclet.inheritDocWithinInappropriateTag=@inheritDoc cannot be used within this tag
118119
doclet.noInheritedDoc=@inheritDoc used but {0} does not override or implement any method.
119120
doclet.tag_misuse=Tag {0} cannot be used in {1} documentation. It can only be used in the following types of documentation: {2}.
120121
doclet.Package_Summary=Package Summary

‎src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/InheritDocTaglet.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ private Content retrieveInheritedDocumentation(TagletWriter writer,
8282
? utils.flatSignature((ExecutableElement)e, writer.getCurrentPageElement())
8383
: "");
8484
//This tag does not support inheritance.
85-
messages.warning(e, "doclet.noInheritedDoc", message);
85+
var path = writer.configuration().utils.getCommentHelper(e).getDocTreePath(holderTag);
86+
messages.warning(path, "doclet.inheritDocWithinInappropriateTag", message);
87+
return replacement;
8688
}
8789
Input input = new DocFinder.Input(utils, e,
8890
(InheritableTaglet) inheritableTaglet, new DocFinder.DocTreeInfo(holderTag, e),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright (c) 2022, 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 8284299
27+
* @library /tools/lib ../../lib
28+
* @modules jdk.javadoc/jdk.javadoc.internal.tool
29+
* @build toolbox.ToolBox javadoc.tester.*
30+
* @run main TestInheritDocWithinInappropriateTag
31+
*/
32+
33+
import java.nio.file.Path;
34+
35+
import javadoc.tester.JavadocTester;
36+
import toolbox.ToolBox;
37+
38+
public class TestInheritDocWithinInappropriateTag extends JavadocTester {
39+
40+
public static void main(String... args) throws Exception {
41+
new TestInheritDocWithinInappropriateTag()
42+
.runTests(m -> new Object[]{Path.of(m.getName())});
43+
}
44+
45+
private final ToolBox tb = new ToolBox();
46+
47+
@Test
48+
public void test(Path base) throws Exception {
49+
Path src = base.resolve("src");
50+
tb.writeJavaFiles(src,
51+
"""
52+
public class A {
53+
/**
54+
* A.x().
55+
*/
56+
public void x() { }
57+
}
58+
""",
59+
"""
60+
public class B extends A {
61+
/**
62+
* {@summary {@inheritDoc}}
63+
*
64+
* {@link Object#hashCode() {@inheritDoc}}
65+
* {@linkplain Object#hashCode() {@inheritDoc}}
66+
*
67+
* {@index term {@inheritDoc}}
68+
*/
69+
@Override
70+
public void x() { }
71+
}
72+
""");
73+
javadoc("-Xdoclint:none",
74+
"-d", base.resolve("out").toString(),
75+
src.resolve("A.java").toString(),
76+
src.resolve("B.java").toString());
77+
checkExit(Exit.OK);
78+
new OutputChecker(Output.OUT).setExpectOrdered(false).check(
79+
"""
80+
warning: @inheritDoc cannot be used within this tag
81+
* {@summary {@inheritDoc}}
82+
^
83+
""",
84+
"""
85+
warning: @inheritDoc cannot be used within this tag
86+
* {@link Object#hashCode() {@inheritDoc}}
87+
^
88+
""",
89+
"""
90+
warning: @inheritDoc cannot be used within this tag
91+
* {@linkplain Object#hashCode() {@inheritDoc}}
92+
^
93+
""",
94+
"""
95+
warning: @inheritDoc cannot be used within this tag
96+
* {@index term {@inheritDoc}}
97+
^
98+
""");
99+
}
100+
}

0 commit comments

Comments
 (0)
Please sign in to comment.