8341904: Search tag in inherited doc comment creates additional index item
Reviewed-by: prappo
This commit is contained in:
parent
4fa760a1ed
commit
baabfbba3e
@ -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
|
||||
@ -128,7 +128,7 @@ public class InheritDocTaglet extends BaseTaglet {
|
||||
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) {
|
||||
|
@ -368,21 +368,22 @@ public class TagletWriter {
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -471,4 +472,15 @@ public class TagletWriter {
|
||||
.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().isDeclaredType()) {
|
||||
return element != getCurrentPageElement();
|
||||
} else if (element.getKind() == ElementKind.OTHER) {
|
||||
return false;
|
||||
} else {
|
||||
return utils.getEnclosingTypeElement(element) != getCurrentPageElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
@ -152,8 +152,7 @@ public class TestMemberInheritance extends JavadocTester {
|
||||
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,
|
||||
"""
|
||||
@ -218,10 +217,8 @@ public class TestMemberInheritance extends JavadocTester {
|
||||
{"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 = []");
|
||||
|
||||
}
|
||||
|
||||
@ -246,8 +243,7 @@ public class TestMemberInheritance extends JavadocTester {
|
||||
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,
|
||||
"""
|
||||
@ -270,10 +266,8 @@ public class TestMemberInheritance extends JavadocTester {
|
||||
{"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 = []");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
@ -25,4 +25,9 @@ package pkg2;
|
||||
|
||||
public abstract class DocumentedNonGenericChild extends UndocumentedGenericParent<String, InterruptedException, IllegalArgumentException> {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void parentMethod2() {}
|
||||
}
|
||||
|
@ -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
|
||||
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user