From baabfbba3e7b5d9c860de38f1f9ed9cd36848f29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20Walln=C3=B6fer?= Date: Tue, 12 Nov 2024 09:23:29 +0000 Subject: [PATCH] 8341904: Search tag in inherited doc comment creates additional index item Reviewed-by: prappo --- .../html/taglets/InheritDocTaglet.java | 4 +- .../formats/html/taglets/TagletWriter.java | 38 ++++++++++++------- .../TestMemberInheritance.java | 20 ++++------ .../pkg2/DocumentedNonGenericChild.java | 7 +++- .../pkg2/UndocumentedGenericParent.java | 7 +++- 5 files changed, 46 insertions(+), 30 deletions(-) diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/InheritDocTaglet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/InheritDocTaglet.java index b05bb144f1b..4ba730cca9c 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/InheritDocTaglet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/InheritDocTaglet.java @@ -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 doc) { - replacement = writer.commentTagsToOutput(doc.value().method, null, + replacement = writer.commentTagsToOutput(doc.value().method, inheritDoc, doc.value().mainDescription, isFirstSentence); } } catch (DocFinder.NoOverriddenMethodFound e) { diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/TagletWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/TagletWriter.java index ca1b6ae016b..7b6c7060a6f 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/TagletWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/taglets/TagletWriter.java @@ -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(); + } + } } diff --git a/test/langtools/jdk/javadoc/doclet/testMemberInheritance/TestMemberInheritance.java b/test/langtools/jdk/javadoc/doclet/testMemberInheritance/TestMemberInheritance.java index 559f7b08d38..ab1142f6a23 100644 --- a/test/langtools/jdk/javadoc/doclet/testMemberInheritance/TestMemberInheritance.java +++ b/test/langtools/jdk/javadoc/doclet/testMemberInheritance/TestMemberInheritance.java @@ -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 java.lang.IllegalArgumentException, java.lang.InterruptedException, java.lang.IllegalStateException -
Returns some value with an inherited search tag.
"""); +
Returns some value with an inherited search tag.
"""); 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 java.lang.IllegalArgumentException, java.lang.InterruptedException, java.lang.IllegalStateException -
Returns some value with an inherited search tag.
"""); +
Returns some value with an inherited search tag.
"""); 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 = []"); } } diff --git a/test/langtools/jdk/javadoc/doclet/testMemberInheritance/pkg2/DocumentedNonGenericChild.java b/test/langtools/jdk/javadoc/doclet/testMemberInheritance/pkg2/DocumentedNonGenericChild.java index 74063aef210..1e341059494 100644 --- a/test/langtools/jdk/javadoc/doclet/testMemberInheritance/pkg2/DocumentedNonGenericChild.java +++ b/test/langtools/jdk/javadoc/doclet/testMemberInheritance/pkg2/DocumentedNonGenericChild.java @@ -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 { + /** + * {@inheritDoc} + */ + @Override + public void parentMethod2() {} } diff --git a/test/langtools/jdk/javadoc/doclet/testMemberInheritance/pkg2/UndocumentedGenericParent.java b/test/langtools/jdk/javadoc/doclet/testMemberInheritance/pkg2/UndocumentedGenericParent.java index b82c81ec9f1..c148626d2b7 100644 --- a/test/langtools/jdk/javadoc/doclet/testMemberInheritance/pkg2/UndocumentedGenericParent.java +++ b/test/langtools/jdk/javadoc/doclet/testMemberInheritance/pkg2/UndocumentedGenericParent.java @@ -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