8341904: Search tag in inherited doc comment creates additional index item

Reviewed-by: prappo
This commit is contained in:
Hannes Wallnöfer 2024-11-12 09:23:29 +00:00
parent 4fa760a1ed
commit baabfbba3e
5 changed files with 46 additions and 30 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -128,7 +128,7 @@ public class InheritDocTaglet extends BaseTaglet {
d = docFinder.search(src, m -> extractMainDescription(m, isFirstSentence, utils)); d = docFinder.search(src, m -> extractMainDescription(m, isFirstSentence, utils));
} }
if (d instanceof Result.Conclude<Documentation> doc) { if (d instanceof Result.Conclude<Documentation> doc) {
replacement = writer.commentTagsToOutput(doc.value().method, null, replacement = writer.commentTagsToOutput(doc.value().method, inheritDoc,
doc.value().mainDescription, isFirstSentence); doc.value().mainDescription, isFirstSentence);
} }
} catch (DocFinder.NoOverriddenMethodFound e) { } catch (DocFinder.NoOverriddenMethodFound e) {

View File

@ -368,21 +368,22 @@ public class TagletWriter {
} }
Content createAnchorAndSearchIndex(Element element, String tagText, Content tagContent, String desc, DocTree tree) { Content createAnchorAndSearchIndex(Element element, String tagText, Content tagContent, String desc, DocTree tree) {
Content result; // Only create index item for tags in their native location.
if (context.isFirstSentence && context.inSummary || context.inTags.contains(DocTree.Kind.INDEX) if (context.isFirstSentence && context.inSummary
|| context.inTags.contains(DocTree.Kind.INDEX)
|| context.inTags.contains(DocTree.Kind.INHERIT_DOC)
|| isDifferentTypeElement(element)
|| !htmlWriter.isIndexable()) { || !htmlWriter.isIndexable()) {
result = tagContent; return tagContent;
} else {
HtmlId id = HtmlIds.forText(tagText, htmlWriter.indexAnchorTable);
result = HtmlTree.SPAN(id, HtmlStyles.searchTagResult, tagContent);
if (options.createIndex() && !tagText.isEmpty()) {
String holder = getHolderName(element);
IndexItem item = IndexItem.of(element, tree, tagText, holder, desc,
new DocLink(htmlWriter.path, id.name()));
configuration.indexBuilder.add(item);
}
} }
return result; HtmlId id = HtmlIds.forText(tagText, htmlWriter.indexAnchorTable);
if (options.createIndex() && !tagText.isEmpty()) {
String holder = getHolderName(element);
IndexItem item = IndexItem.of(element, tree, tagText, holder, desc,
new DocLink(htmlWriter.path, id.name()));
configuration.indexBuilder.add(item);
}
return HtmlTree.SPAN(id, HtmlStyles.searchTagResult, tagContent);
} }
public String getHolderName(Element element) { public String getHolderName(Element element) {
@ -471,4 +472,15 @@ public class TagletWriter {
.replaceAll("\\R", "\n"); // normalize newlines .replaceAll("\\R", "\n"); // normalize newlines
return s.length() > TAG_LIST_ITEM_MAX_INLINE_LENGTH || s.contains(","); return s.length() > TAG_LIST_ITEM_MAX_INLINE_LENGTH || s.contains(",");
} }
// Test if element is the same as or belongs to the current page element
private boolean isDifferentTypeElement(Element element) {
if (element.getKind().isDeclaredType()) {
return element != getCurrentPageElement();
} else if (element.getKind() == ElementKind.OTHER) {
return false;
} else {
return utils.getEnclosingTypeElement(element) != getCurrentPageElement();
}
}
} }

View File

@ -24,7 +24,7 @@
/* /*
* @test * @test
* @bug 4638588 4635809 6256068 6270645 8025633 8026567 8162363 8175200 * @bug 4638588 4635809 6256068 6270645 8025633 8026567 8162363 8175200
* 8192850 8182765 8220217 8224052 8237383 * 8192850 8182765 8220217 8224052 8237383 8341904
* @summary Test to make sure that members are inherited properly in the Javadoc. * @summary Test to make sure that members are inherited properly in the Javadoc.
* Verify that inheritance labels are correct. * Verify that inheritance labels are correct.
* @library ../../lib * @library ../../lib
@ -152,8 +152,7 @@ public class TestMemberInheritance extends JavadocTester {
throws <span class="exceptions">java.lang.IllegalArgumentException, throws <span class="exceptions">java.lang.IllegalArgumentException,
java.lang.InterruptedException, java.lang.InterruptedException,
java.lang.IllegalStateException</span></div> java.lang.IllegalStateException</span></div>
<div class="block">Returns some value with an <span id="inheritedsearchtag" clas\ <div class="block">Returns some value with an inherited search tag.</div>""");
s="search-tag-result">inherited search tag</span>.</div>""");
checkOutput("pkg2/DocumentedNonGenericChild.html", true, checkOutput("pkg2/DocumentedNonGenericChild.html", true,
""" """
@ -218,10 +217,8 @@ public class TestMemberInheritance extends JavadocTester {
{"p":"pkg2","c":"DocumentedNonGenericChild","l":"parentField"}""", {"p":"pkg2","c":"DocumentedNonGenericChild","l":"parentField"}""",
""" """
{"p":"pkg2","c":"DocumentedNonGenericChild","l":"parentMethod(String)","u":"parentMethod(T)"}"""); {"p":"pkg2","c":"DocumentedNonGenericChild","l":"parentMethod(String)","u":"parentMethod(T)"}""");
checkOutput("tag-search-index.js", true, // Search tags from inherited doc comments are not added to the index (8341904).
""" checkOutput("tag-search-index.js", true, "tagSearchIndex = []");
{"l":"inherited search tag","h":"pkg2.UndocumentedGenericParent.parentMethod(Str\
ing)","u":"pkg2/DocumentedNonGenericChild.html#inheritedsearchtag"}""");
} }
@ -246,8 +243,7 @@ public class TestMemberInheritance extends JavadocTester {
throws <span class="exceptions">java.lang.IllegalArgumentException, throws <span class="exceptions">java.lang.IllegalArgumentException,
java.lang.InterruptedException, java.lang.InterruptedException,
java.lang.IllegalStateException</span></div> java.lang.IllegalStateException</span></div>
<div class="block">Returns some value with an <span id="inheritedsearchtag" clas\ <div class="block">Returns some value with an inherited search tag.</div>""");
s="search-tag-result">inherited search tag</span>.</div>""");
checkOutput("index-files/index-9.html", true, checkOutput("index-files/index-9.html", true,
""" """
@ -270,10 +266,8 @@ public class TestMemberInheritance extends JavadocTester {
{"p":"pkg2","c":"DocumentedNonGenericChild","l":"parentField"}""", {"p":"pkg2","c":"DocumentedNonGenericChild","l":"parentField"}""",
""" """
{"p":"pkg2","c":"DocumentedNonGenericChild","l":"parentMethod(String)","u":"parentMethod(T)"}"""); {"p":"pkg2","c":"DocumentedNonGenericChild","l":"parentMethod(String)","u":"parentMethod(T)"}""");
checkOutput("tag-search-index.js", true, // Search tags from inherited doc comments are not added to the index (8341904).
""" checkOutput("tag-search-index.js", true, "tagSearchIndex = []");
{"l":"inherited search tag","h":"pkg2.UndocumentedGenericParent.parentMethod(Str\
ing)","u":"pkg2/DocumentedNonGenericChild.html#inheritedsearchtag"}""");
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,4 +25,9 @@ package pkg2;
public abstract class DocumentedNonGenericChild extends UndocumentedGenericParent<String, InterruptedException, IllegalArgumentException> { public abstract class DocumentedNonGenericChild extends UndocumentedGenericParent<String, InterruptedException, IllegalArgumentException> {
/**
* {@inheritDoc}
*/
@Override
public void parentMethod2() {}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -38,4 +38,9 @@ abstract class UndocumentedGenericParent<T, E extends Throwable, F extends Throw
* @throws IllegalStateException illegal state * @throws IllegalStateException illegal state
*/ */
protected abstract T parentMethod(T t) throws F, E, IllegalStateException; protected abstract T parentMethod(T t) throws F, E, IllegalStateException;
/**
* Method with systemProperty tag. {@systemProperty parent.system.prop}.
*/
public abstract void parentMethod2();
} }