From f26667d2a26e23e331b8699347ea771d768959b3 Mon Sep 17 00:00:00 2001 From: Bhavesh Patel Date: Sat, 15 Jul 2017 14:51:42 -0700 Subject: [PATCH] 8181622: new {@index} tag generates multiple index entries Reviewed-by: jjg, ksrini --- .../formats/html/AbstractIndexWriter.java | 2 +- .../formats/html/HtmlConfiguration.java | 12 ++++++- .../doclet/testModules/TestModules.java | 27 +++++++++----- .../testModules/moduleA/module-info.java | 4 +-- .../testModules/moduletags/module-info.java | 4 +-- .../javadoc/doclet/testSearch/TestSearch.java | 36 ++++++++++++++++++- 6 files changed, 70 insertions(+), 15 deletions(-) diff --git a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractIndexWriter.java b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractIndexWriter.java index e5665ccb7ad..f2c93a70827 100644 --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractIndexWriter.java +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractIndexWriter.java @@ -455,7 +455,7 @@ public class AbstractIndexWriter extends HtmlDocletWriter { * @throws DocFileIOException if there is a problem creating the search index file */ protected void createSearchIndexFile(DocPath searchIndexFile, DocPath searchIndexZip, - DocPath searchIndexJS, List searchIndex, String varName) throws DocFileIOException { + DocPath searchIndexJS, Collection searchIndex, String varName) throws DocFileIOException { if (!searchIndex.isEmpty()) { StringBuilder searchVar = new StringBuilder("["); boolean first = true; diff --git a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java index 6090ff9d46d..6b214b9052e 100644 --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java @@ -224,7 +224,7 @@ public class HtmlConfiguration extends BaseConfiguration { protected List packageSearchIndex = new ArrayList<>(); - protected List tagSearchIndex = new ArrayList<>(); + protected SortedSet tagSearchIndex = new TreeSet<>(makeSearchTagComparator()); protected List typeSearchIndex = new ArrayList<>(); @@ -348,6 +348,16 @@ public class HtmlConfiguration extends BaseConfiguration { return htmlTag.allowTag(this.htmlVersion); } + public Comparator makeSearchTagComparator() { + return (SearchIndexItem sii1, SearchIndexItem sii2) -> { + int result = (sii1.getLabel()).compareTo(sii2.getLabel()); + if (result == 0) { + result = (sii1.getHolder()).compareTo(sii2.getHolder()); + } + return result; + }; + } + /** * Decide the page which will appear first in the right-hand frame. It will * be "overview-summary.html" if "-overview" option is used or no diff --git a/langtools/test/jdk/javadoc/doclet/testModules/TestModules.java b/langtools/test/jdk/javadoc/doclet/testModules/TestModules.java index 316d8b60d51..5e6d7dc5069 100644 --- a/langtools/test/jdk/javadoc/doclet/testModules/TestModules.java +++ b/langtools/test/jdk/javadoc/doclet/testModules/TestModules.java @@ -25,7 +25,7 @@ * @test * @bug 8154119 8154262 8156077 8157987 8154261 8154817 8135291 8155995 8162363 * 8168766 8168688 8162674 8160196 8175799 8174974 8176778 8177562 8175218 8175823 8166306 - * 8178043 + * 8178043 8181622 * @summary Test modules support in javadoc. * @author bpatel * @library ../lib @@ -394,7 +394,7 @@ public class TestModules extends JavadocTester { + "\n" + "\n" + "\n" - + "
This is a test description for the moduleA module. Search " + + "
This is a test description for the moduleA module with a Search " + "phrase search phrase.
"); checkOutput("moduleB-summary.html", found, "\n" @@ -454,7 +454,7 @@ public class TestModules extends JavadocTester { + "\n" + "\n" + "\n" - + "
This is a test description for the moduleA module. Search " + + "
This is a test description for the moduleA module with a Search " + "phrase search phrase.
"); checkOutput("moduleB-summary.html", found, "
\n" @@ -755,7 +755,8 @@ public class TestModules extends JavadocTester { + "transitive\n" + "moduleA\n" + "\n" - + "
This is a test description for the moduleA module.
\n" + + "
This is a test description for the moduleA module with a Search " + + "phrase search phrase.
\n" + "\n" + "\n" + "\n" @@ -839,7 +840,8 @@ public class TestModules extends JavadocTester { "
\n" + "
moduleA - module moduleA
\n" + "
\n" - + "
This is a test description for the moduleA module.
\n" + + "
This is a test description for the moduleA module with a Search " + + "phrase search phrase.
\n" + "
\n" + "
moduleB - module moduleB
\n" + "
\n" @@ -854,13 +856,21 @@ public class TestModules extends JavadocTester { + "search_word - Search tag in moduleB\n" + "
 
\n" + "
"); + checkOutput("index-all.html", false, + "
" + + "search phrase - Search tag in moduleA
\n" + + "
with description
\n" + + "
" + + "search phrase - Search tag in moduleA
\n" + + "
with description
"); } void checkModuleModeCommon() { checkOutput("overview-summary.html", true, "moduleA\n" + "\n" - + "
This is a test description for the moduleA module.
\n" + + "
This is a test description for the moduleA module with a Search " + + "phrase search phrase.
\n" + "", "moduleB\n" + "\n" @@ -868,7 +878,7 @@ public class TestModules extends JavadocTester { + "", "moduletags\n" + "\n" - + "
This is a test description for the moduleA module.
\n" + + "
This is a test description for the moduletags module.
\n" + " Type Link: TestClassInModuleTags.
\n" + " Member Link: testMethod(String).
\n" + " Package Link: testpkgmdltags.
\n" @@ -896,7 +906,8 @@ public class TestModules extends JavadocTester { "transitive static\n" + "moduleA\n" + "\n" - + "
This is a test description for the moduleA module.
\n" + + "
This is a test description for the moduleA module with a Search " + + "phrase search phrase.
\n" + "", "\n" + "\n" diff --git a/langtools/test/jdk/javadoc/doclet/testModules/moduleA/module-info.java b/langtools/test/jdk/javadoc/doclet/testModules/moduleA/module-info.java index db081128374..9dad71bfaa4 100644 --- a/langtools/test/jdk/javadoc/doclet/testModules/moduleA/module-info.java +++ b/langtools/test/jdk/javadoc/doclet/testModules/moduleA/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2017, 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 @@ -24,7 +24,7 @@ */ /** - * This is a test description for the moduleA module. Search phrase {@index "search phrase" with description}. + * This is a test description for the moduleA module with a Search phrase {@index "search phrase" with description}. * * @deprecated This module is deprecated. */ diff --git a/langtools/test/jdk/javadoc/doclet/testModules/moduletags/module-info.java b/langtools/test/jdk/javadoc/doclet/testModules/moduletags/module-info.java index 1b0d2b24083..8c9df22713e 100644 --- a/langtools/test/jdk/javadoc/doclet/testModules/moduletags/module-info.java +++ b/langtools/test/jdk/javadoc/doclet/testModules/moduletags/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2017, 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 @@ -24,7 +24,7 @@ */ /** - * This is a test description for the moduleA module.
+ * This is a test description for the moduletags module.
* Type Link: {@link testpkgmdltags.TestClassInModuleTags}.
* Member Link: {@link testpkgmdltags.TestClassInModuleTags#testMethod(String)}.
* Package Link: {@link testpkgmdltags}.
diff --git a/langtools/test/jdk/javadoc/doclet/testSearch/TestSearch.java b/langtools/test/jdk/javadoc/doclet/testSearch/TestSearch.java index 94c4866197b..f7af913ec28 100644 --- a/langtools/test/jdk/javadoc/doclet/testSearch/TestSearch.java +++ b/langtools/test/jdk/javadoc/doclet/testSearch/TestSearch.java @@ -23,7 +23,7 @@ /* * @test - * @bug 8141492 8071982 8141636 8147890 8166175 8168965 8176794 8175218 8147881 + * @bug 8141492 8071982 8141636 8147890 8166175 8168965 8176794 8175218 8147881 8181622 * @summary Test the search feature of javadoc. * @author bpatel * @library ../lib @@ -65,6 +65,7 @@ public class TestSearch extends JavadocTester { checkInvalidUsageIndexTag(); checkSearchOutput(true); checkSingleIndex(true); + checkSingleIndexSearchTagDuplication(); checkJqueryAndImageFiles(true); checkSearchJS(); checkFiles(true, @@ -86,6 +87,7 @@ public class TestSearch extends JavadocTester { checkDocLintErrors(); checkSearchOutput(true); checkSingleIndex(true); + checkSingleIndexSearchTagDuplication(); checkJqueryAndImageFiles(true); checkSearchJS(); checkFiles(true, @@ -127,6 +129,7 @@ public class TestSearch extends JavadocTester { checkExit(Exit.OK); checkSearchOutput(true); checkSingleIndex(true); + checkSingleIndexSearchTagDuplication(); checkJqueryAndImageFiles(true); checkSearchJS(); checkFiles(true, @@ -210,6 +213,7 @@ public class TestSearch extends JavadocTester { checkInvalidUsageIndexTag(); checkSearchOutput(true); checkSplitIndex(); + checkSplitIndexSearchTagDuplication(); checkJqueryAndImageFiles(true); checkSearchJS(); checkFiles(true, @@ -498,4 +502,34 @@ public class TestSearch extends JavadocTester { + " }\n" + " });"); } + + void checkSingleIndexSearchTagDuplication() { + // Test for search tags duplication in index file. + checkOutput("index-all.html", true, + "
" + + "SearchTagDeprecatedMethod - Search tag in pkg2.TestError
\n" + + "
with description
"); + checkOutput("index-all.html", false, + "
" + + "SearchTagDeprecatedMethod - Search tag in pkg2.TestError
\n" + + "
with description
\n" + + "
" + + "SearchTagDeprecatedMethod - Search tag in pkg2.TestError
\n" + + "
with description
"); + } + + void checkSplitIndexSearchTagDuplication() { + // Test for search tags duplication in index file. + checkOutput("index-files/index-13.html", true, + "
" + + "SearchTagDeprecatedMethod - Search tag in pkg2.TestError
\n" + + "
with description
"); + checkOutput("index-files/index-13.html", false, + "
" + + "SearchTagDeprecatedMethod - Search tag in pkg2.TestError
\n" + + "
with description
\n" + + "
" + + "SearchTagDeprecatedMethod - Search tag in pkg2.TestError
\n" + + "
with description
"); + } }
Requires