Skip to content

Commit

Permalink
8305407: ExternalSpecsWriter should ignore white-space differences in…
Browse files Browse the repository at this point in the history
… spec titles

Reviewed-by: hannesw
  • Loading branch information
jonathan-gibbons committed Apr 7, 2023
1 parent 6b2a86a commit a8871f5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
Expand Up @@ -132,7 +132,7 @@ protected void checkUniqueItems() {
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<>())
Expand Down
Expand Up @@ -222,9 +222,9 @@ protected Content indexTagOutput(Element element, IndexTree tag) {
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);
Expand Down Expand Up @@ -771,7 +771,8 @@ private Content specTagToContent(Element holder, SpecTree specTree) {
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) {
Expand Down
47 changes: 46 additions & 1 deletion test/langtools/jdk/javadoc/doclet/testSpecTag/TestSpecTag.java
Expand Up @@ -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
Expand Down Expand Up @@ -415,6 +415,51 @@ public void m2() { }
.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");
Expand Down

1 comment on commit a8871f5

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.