8225321: Repeated use of {@systemProperty} in a file causes duplicate ids
Reviewed-by: hannesw
This commit is contained in:
parent
332d079057
commit
948577bb1f
@ -27,6 +27,7 @@ package jdk.javadoc.internal.doclets.formats.html;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
@ -196,6 +197,14 @@ public class HtmlDocletWriter {
|
|||||||
|
|
||||||
protected Script mainBodyScript;
|
protected Script mainBodyScript;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A table of the anchors used for at-index and related tags,
|
||||||
|
* so that they can be made unique by appending a suitable suffix.
|
||||||
|
* (Ideally, javadoc should be tracking all id's generated in a file
|
||||||
|
* to avoid generating duplicates.)
|
||||||
|
*/
|
||||||
|
Map<String, Integer> indexAnchorTable = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor to construct the HtmlStandardWriter object.
|
* Constructor to construct the HtmlStandardWriter object.
|
||||||
*
|
*
|
||||||
|
@ -409,11 +409,16 @@ public class TagletWriterImpl extends TagletWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Content createAnchorAndSearchIndex(Element element, String tagText, String desc){
|
private Content createAnchorAndSearchIndex(Element element, String tagText, String desc){
|
||||||
String anchorName = htmlWriter.links.getName(tagText);
|
|
||||||
Content result = null;
|
Content result = null;
|
||||||
if (isFirstSentence && inSummary) {
|
if (isFirstSentence && inSummary) {
|
||||||
result = new StringContent(tagText);
|
result = new StringContent(tagText);
|
||||||
} else {
|
} else {
|
||||||
|
String anchorName = htmlWriter.links.getName(tagText);
|
||||||
|
int count = htmlWriter.indexAnchorTable.computeIfAbsent(anchorName, s -> 0);
|
||||||
|
htmlWriter.indexAnchorTable.put(anchorName, count + 1);
|
||||||
|
if (count > 0) {
|
||||||
|
anchorName += "-" + count;
|
||||||
|
}
|
||||||
result = HtmlTree.A_ID(HtmlStyle.searchTagResult, anchorName, new StringContent(tagText));
|
result = HtmlTree.A_ID(HtmlStyle.searchTagResult, anchorName, new StringContent(tagText));
|
||||||
if (configuration.createindex && !tagText.isEmpty()) {
|
if (configuration.createindex && !tagText.isEmpty()) {
|
||||||
SearchIndexItem si = new SearchIndexItem();
|
SearchIndexItem si = new SearchIndexItem();
|
||||||
|
@ -47,7 +47,7 @@ public class TestIndexTaglet extends JavadocTester {
|
|||||||
|
|
||||||
public static void main(String... args) throws Exception {
|
public static void main(String... args) throws Exception {
|
||||||
TestIndexTaglet tester = new TestIndexTaglet();
|
TestIndexTaglet tester = new TestIndexTaglet();
|
||||||
tester.runTests(m -> new Object[]{Paths.get(m.getName())});
|
tester.runTests(m -> new Object[] { Paths.get(m.getName()) });
|
||||||
}
|
}
|
||||||
|
|
||||||
TestIndexTaglet() {
|
TestIndexTaglet() {
|
||||||
@ -104,4 +104,27 @@ public class TestIndexTaglet extends JavadocTester {
|
|||||||
checkOutput(Output.OUT, true,
|
checkOutput(Output.OUT, true,
|
||||||
"warning: {@index} tag, which expands to <a>, within <a>");
|
"warning: {@index} tag, which expands to <a>, within <a>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDuplicateReferences(Path base) throws Exception {
|
||||||
|
Path srcDir = base.resolve("src");
|
||||||
|
Path outDir = base.resolve("out");
|
||||||
|
|
||||||
|
new ClassBuilder(tb, "pkg.A")
|
||||||
|
.setModifiers("public", "class")
|
||||||
|
.setComments("This is a class. Here is {@index foo first}.")
|
||||||
|
.addMembers(MethodBuilder.parse("public void m() {}")
|
||||||
|
.setComments("This is a method. Here is {@index foo second}."))
|
||||||
|
.write(srcDir);
|
||||||
|
|
||||||
|
javadoc("-d", outDir.toString(),
|
||||||
|
"-sourcepath", srcDir.toString(),
|
||||||
|
"pkg");
|
||||||
|
|
||||||
|
checkExit(Exit.OK);
|
||||||
|
|
||||||
|
checkOutput("pkg/A.html", true,
|
||||||
|
"This is a class. Here is <a id=\"foo\" class=\"searchTagResult\">foo</a>.",
|
||||||
|
"This is a method. Here is <a id=\"foo-1\" class=\"searchTagResult\">foo</a>.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ public class TestSystemPropertyTaglet extends JavadocTester {
|
|||||||
|
|
||||||
public static void main(String... args) throws Exception {
|
public static void main(String... args) throws Exception {
|
||||||
TestSystemPropertyTaglet tester = new TestSystemPropertyTaglet();
|
TestSystemPropertyTaglet tester = new TestSystemPropertyTaglet();
|
||||||
tester.runTests(m -> new Object[]{Paths.get(m.getName())});
|
tester.runTests(m -> new Object[] { Paths.get(m.getName()) });
|
||||||
}
|
}
|
||||||
|
|
||||||
TestSystemPropertyTaglet() {
|
TestSystemPropertyTaglet() {
|
||||||
@ -118,4 +118,27 @@ public class TestSystemPropertyTaglet extends JavadocTester {
|
|||||||
checkOutput(Output.OUT, true,
|
checkOutput(Output.OUT, true,
|
||||||
"warning: {@systemProperty} tag, which expands to <a>, within <a>");
|
"warning: {@systemProperty} tag, which expands to <a>, within <a>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDuplicateReferences(Path base) throws Exception {
|
||||||
|
Path srcDir = base.resolve("src");
|
||||||
|
Path outDir = base.resolve("out");
|
||||||
|
|
||||||
|
new ClassBuilder(tb, "pkg.A")
|
||||||
|
.setModifiers("public", "class")
|
||||||
|
.setComments("This is a class. Here is {@systemProperty foo}.")
|
||||||
|
.addMembers(MethodBuilder.parse("public void m() {}")
|
||||||
|
.setComments("This is a method. Here is {@systemProperty foo}."))
|
||||||
|
.write(srcDir);
|
||||||
|
|
||||||
|
javadoc("-d", outDir.toString(),
|
||||||
|
"-sourcepath", srcDir.toString(),
|
||||||
|
"pkg");
|
||||||
|
|
||||||
|
checkExit(Exit.OK);
|
||||||
|
|
||||||
|
checkOutput("pkg/A.html", true,
|
||||||
|
"This is a class. Here is <code><a id=\"foo\" class=\"searchTagResult\">foo</a></code>.",
|
||||||
|
"This is a method. Here is <code><a id=\"foo-1\" class=\"searchTagResult\">foo</a></code>.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user