8305407: ExternalSpecsWriter should ignore white-space differences in spec titles

Reviewed-by: hannesw
This commit is contained in:
Jonathan Gibbons 2023-04-07 14:15:46 +00:00
parent 6b2a86a65e
commit a8871f5d26
3 changed files with 51 additions and 5 deletions
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html
test/langtools/jdk/javadoc/doclet/testSpecTag

@ -132,7 +132,7 @@ public class ExternalSpecsWriter extends HtmlDocletWriter {
for (IndexItem ii : configuration.mainIndex.getItems(DocTree.Kind.SPEC)) {
if (ii.getDocTree() instanceof SpecTree st) {
String url = st.getURL().toString();
String title = st.getTitle().toString();
String title = ii.getLabel(); // normalized form of st.getTitle()
itemsByTitle
.computeIfAbsent(title, l -> new HashMap<>())
.computeIfAbsent(url, u -> new ArrayList<>())

@ -222,9 +222,9 @@ public class TagletWriterImpl extends TagletWriter {
DocTree searchTerm = tag.getSearchTerm();
String tagText = (searchTerm instanceof TextTree tt) ? tt.getBody() : "";
if (tagText.charAt(0) == '"' && tagText.charAt(tagText.length() - 1) == '"') {
tagText = tagText.substring(1, tagText.length() - 1)
.replaceAll("\\s+", " ");
tagText = tagText.substring(1, tagText.length() - 1);
}
tagText = tagText.replaceAll("\\s+", " ");
Content desc = htmlWriter.commentTagsToContent(element, tag.getDescription(), context.within(tag));
String descText = extractText(desc);
@ -771,7 +771,8 @@ public class TagletWriterImpl extends TagletWriter {
String specTreeURL = specTree.getURL().getBody();
List<? extends DocTree> specTreeLabel = specTree.getTitle();
Content label = htmlWriter.commentTagsToContent(holder, specTreeLabel, isFirstSentence);
return getExternalSpecContent(holder, specTree, specTreeURL, textOf(specTreeLabel), label);
return getExternalSpecContent(holder, specTree, specTreeURL,
textOf(specTreeLabel).replaceAll("\\s+", " "), label);
}
Content getExternalSpecContent(Element holder, DocTree docTree, String url, String searchText, Content title) {

@ -23,7 +23,7 @@
/*
* @test
* @bug 6251738 8226279 8297802 8296546
* @bug 6251738 8226279 8297802 8296546 8305407
* @summary JDK-8226279 javadoc should support a new at-spec tag
* @library /tools/lib ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
@ -415,6 +415,51 @@ public class TestSpecTag extends JavadocTester {
.replace("#FILE#", src.resolve("p").resolve("C.java").toString()));
}
@Test
public void testDifferentWhitespaceTitlesForURL(Path base) throws IOException {
Path src = base.resolve("src");
tb.writeJavaFiles(src, """
package p;
/** Class C. */
public class C {
private C() { }
/**
* Method m1.
* @spec http://example.com/index.html abc def
*/
public void m1() { }
/**
* Method m2.
* @spec http://example.com/index.html abc def
*/
public void m2() { }
}
""");
javadoc("-d", base.resolve("out").toString(),
"--source-path", src.toString(),
"p");
checkExit(Exit.OK);
checkOutput(Output.OUT, false, "error");
checkOutput("external-specs.html", true,
"""
<div class="summary-table two-column-summary">
<div class="table-header col-first">Specification</div>
<div class="table-header col-last">Referenced In</div>
<div class="col-first even-row-color"><a href="http://example.com/index.html">abc def</a></div>
<div class="col-last even-row-color">
<ul class="ref-list">
<li><code><a href="p/C.html#abcdef">p.C.m1()</a></code></li>
<li><code><a href="p/C.html#abcdef-1">p.C.m2()</a></code></li>
</ul>
</div>
</div>""");
}
@Test
public void testMultipleURLsForTitle(Path base) throws IOException {
Path src = base.resolve("src");