Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -128,7 +128,7 @@ private Content retrieveInheritedDocumentation(TagletWriter writer,
d = docFinder.search(src, m -> extractMainDescription(m, isFirstSentence, utils));
}
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);
}
} catch (DocFinder.NoOverriddenMethodFound e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,21 +369,22 @@ public Content createAnchorAndSearchIndex(Element element, String tagText, Strin

@SuppressWarnings("preview")
Content createAnchorAndSearchIndex(Element element, String tagText, Content tagContent, String desc, DocTree tree) {
Content result;
if (context.isFirstSentence && context.inSummary || context.inTags.contains(DocTree.Kind.INDEX)
// Only create index item for tags in their native location.
if (context.isFirstSentence && context.inSummary
|| context.inTags.contains(DocTree.Kind.INDEX)
|| context.inTags.contains(DocTree.Kind.INHERIT_DOC)
|| isDifferentTypeElement(element)
|| !htmlWriter.isIndexable()) {
result = 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 tagContent;
}
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) {
Expand Down Expand Up @@ -472,4 +473,15 @@ private boolean isLongOrHasComma(Content c) {
.replaceAll("\\R", "\n"); // normalize newlines
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().isClass() || element.getKind().isInterface()) {
return element != getCurrentPageElement();
} else if (element.getKind() == ElementKind.OTHER) {
return false;
} else {
return utils.getEnclosingTypeElement(element) != getCurrentPageElement();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/*
* @test
* @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.
* Verify that inheritance labels are correct.
* @library ../../lib
Expand Down Expand Up @@ -152,8 +152,7 @@ interface in pkg">BaseInterface</a></code></dd>
throws <span class="exceptions">java.lang.IllegalArgumentException,
java.lang.InterruptedException,
java.lang.IllegalStateException</span></div>
<div class="block">Returns some value with an <span id="inheritedsearchtag" clas\
s="search-tag-result">inherited search tag</span>.</div>""");
<div class="block">Returns some value with an inherited search tag.</div>""");

checkOutput("pkg2/DocumentedNonGenericChild.html", true,
"""
Expand Down Expand Up @@ -218,10 +217,8 @@ interface in pkg">BaseInterface</a></code></dd>
{"p":"pkg2","c":"DocumentedNonGenericChild","l":"parentField"}""",
"""
{"p":"pkg2","c":"DocumentedNonGenericChild","l":"parentMethod(String)","u":"parentMethod(T)"}""");
checkOutput("tag-search-index.js", true,
"""
{"l":"inherited search tag","h":"pkg2.UndocumentedGenericParent.parentMethod(Str\
ing)","u":"pkg2/DocumentedNonGenericChild.html#inheritedsearchtag"}""");
// Search tags from inherited doc comments are not added to the index (8341904).
checkOutput("tag-search-index.js", true, "tagSearchIndex = []");

}

Expand All @@ -246,8 +243,7 @@ public void testSplitIndex() {
throws <span class="exceptions">java.lang.IllegalArgumentException,
java.lang.InterruptedException,
java.lang.IllegalStateException</span></div>
<div class="block">Returns some value with an <span id="inheritedsearchtag" clas\
s="search-tag-result">inherited search tag</span>.</div>""");
<div class="block">Returns some value with an inherited search tag.</div>""");

checkOutput("index-files/index-9.html", true,
"""
Expand All @@ -270,10 +266,8 @@ public void testSplitIndex() {
{"p":"pkg2","c":"DocumentedNonGenericChild","l":"parentField"}""",
"""
{"p":"pkg2","c":"DocumentedNonGenericChild","l":"parentMethod(String)","u":"parentMethod(T)"}""");
checkOutput("tag-search-index.js", true,
"""
{"l":"inherited search tag","h":"pkg2.UndocumentedGenericParent.parentMethod(Str\
ing)","u":"pkg2/DocumentedNonGenericChild.html#inheritedsearchtag"}""");
// Search tags from inherited doc comments are not added to the index (8341904).
checkOutput("tag-search-index.js", true, "tagSearchIndex = []");
}

}
Original file line number Diff line number Diff line change
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,4 +25,9 @@

public abstract class DocumentedNonGenericChild extends UndocumentedGenericParent<String, InterruptedException, IllegalArgumentException> {

/**
* {@inheritDoc}
*/
@Override
public void parentMethod2() {}
}
Original file line number Diff line number Diff line change
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -38,4 +38,9 @@ abstract class UndocumentedGenericParent<T, E extends Throwable, F extends Throw
* @throws IllegalStateException illegal state
*/
protected abstract T parentMethod(T t) throws F, E, IllegalStateException;

/**
* Method with systemProperty tag. {@systemProperty parent.system.prop}.
*/
public abstract void parentMethod2();
}