8181622: new {@index} tag generates multiple index entries
authorbpatel
Sat, 15 Jul 2017 14:51:42 -0700
changeset 45913 90f6a96c1603
parent 45912 865870b7fe9b
child 45914 0c6f13526872
8181622: new {@index} tag generates multiple index entries Reviewed-by: jjg, ksrini
langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractIndexWriter.java
langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java
langtools/test/jdk/javadoc/doclet/testModules/TestModules.java
langtools/test/jdk/javadoc/doclet/testModules/moduleA/module-info.java
langtools/test/jdk/javadoc/doclet/testModules/moduletags/module-info.java
langtools/test/jdk/javadoc/doclet/testSearch/TestSearch.java
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractIndexWriter.java	Sat Jul 15 11:06:32 2017 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractIndexWriter.java	Sat Jul 15 14:51:42 2017 -0700
@@ -455,7 +455,7 @@
      * @throws DocFileIOException if there is a problem creating the search index file
      */
     protected void createSearchIndexFile(DocPath searchIndexFile, DocPath searchIndexZip,
-            DocPath searchIndexJS, List<SearchIndexItem> searchIndex, String varName) throws DocFileIOException {
+            DocPath searchIndexJS, Collection<SearchIndexItem> searchIndex, String varName) throws DocFileIOException {
         if (!searchIndex.isEmpty()) {
             StringBuilder searchVar = new StringBuilder("[");
             boolean first = true;
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java	Sat Jul 15 11:06:32 2017 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java	Sat Jul 15 14:51:42 2017 -0700
@@ -224,7 +224,7 @@
 
     protected List<SearchIndexItem> packageSearchIndex = new ArrayList<>();
 
-    protected List<SearchIndexItem> tagSearchIndex = new ArrayList<>();
+    protected SortedSet<SearchIndexItem> tagSearchIndex = new TreeSet<>(makeSearchTagComparator());
 
     protected List<SearchIndexItem> typeSearchIndex = new ArrayList<>();
 
@@ -348,6 +348,16 @@
         return htmlTag.allowTag(this.htmlVersion);
     }
 
+    public Comparator<SearchIndexItem> 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
--- a/langtools/test/jdk/javadoc/doclet/testModules/TestModules.java	Sat Jul 15 11:06:32 2017 -0700
+++ b/langtools/test/jdk/javadoc/doclet/testModules/TestModules.java	Sat Jul 15 14:51:42 2017 -0700
@@ -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 @@
                 + "<a name=\"module.description\">\n"
                 + "<!--   -->\n"
                 + "</a>\n"
-                + "<div class=\"block\">This is a test description for the moduleA module. Search "
+                + "<div class=\"block\">This is a test description for the moduleA module with a Search "
                 + "phrase <a id=\"searchphrase\" class=\"searchTagResult\">search phrase</a>.</div>");
         checkOutput("moduleB-summary.html", found,
                 "<!-- ============ MODULE DESCRIPTION =========== -->\n"
@@ -454,7 +454,7 @@
                 + "<a id=\"module.description\">\n"
                 + "<!--   -->\n"
                 + "</a>\n"
-                + "<div class=\"block\">This is a test description for the moduleA module. Search "
+                + "<div class=\"block\">This is a test description for the moduleA module with a Search "
                 + "phrase <a id=\"searchphrase\" class=\"searchTagResult\">search phrase</a>.</div>");
         checkOutput("moduleB-summary.html", found,
                 "<section role=\"region\">\n"
@@ -755,7 +755,8 @@
                 + "<td class=\"colFirst\">transitive</td>\n"
                 + "<th class=\"colSecond\" scope=\"row\"><a href=\"moduleA-summary.html\">moduleA</a></th>\n"
                 + "<td class=\"colLast\">\n"
-                + "<div class=\"block\">This is a test description for the moduleA module.</div>\n"
+                + "<div class=\"block\">This is a test description for the moduleA module with a Search "
+                + "phrase <a id=\"searchphrase\" class=\"searchTagResult\">search phrase</a>.</div>\n"
                 + "</td>\n"
                 + "</tr>\n"
                 + "<tr class=\"rowColor\">\n"
@@ -839,7 +840,8 @@
                 "<dl>\n"
                 + "<dt><a href=\"moduleA-summary.html\">moduleA</a> - module moduleA</dt>\n"
                 + "<dd>\n"
-                + "<div class=\"block\">This is a test description for the moduleA module.</div>\n"
+                + "<div class=\"block\">This is a test description for the moduleA module with a Search "
+                + "phrase <a id=\"searchphrase\" class=\"searchTagResult\">search phrase</a>.</div>\n"
                 + "</dd>\n"
                 + "<dt><a href=\"moduleB-summary.html\">moduleB</a> - module moduleB</dt>\n"
                 + "<dd>\n"
@@ -854,13 +856,21 @@
                 + "search_word</a></span> - Search tag in moduleB</dt>\n"
                 + "<dd>&nbsp;</dd>\n"
                 + "</dl>");
+        checkOutput("index-all.html", false,
+                "<dt><span class=\"searchTagLink\"><a href=\"moduleA-summary.html#searchphrase\">"
+                + "search phrase</a></span> - Search tag in moduleA</dt>\n"
+                + "<dd>with description</dd>\n"
+                + "<dt><span class=\"searchTagLink\"><a href=\"moduleA-summary.html#searchphrase\">"
+                + "search phrase</a></span> - Search tag in moduleA</dt>\n"
+                + "<dd>with description</dd>");
     }
 
     void checkModuleModeCommon() {
         checkOutput("overview-summary.html", true,
                 "<th class=\"colFirst\" scope=\"row\"><a href=\"moduleA-summary.html\">moduleA</a></th>\n"
                 + "<td class=\"colLast\">\n"
-                + "<div class=\"block\">This is a test description for the moduleA module.</div>\n"
+                + "<div class=\"block\">This is a test description for the moduleA module with a Search "
+                + "phrase <a id=\"searchphrase\" class=\"searchTagResult\">search phrase</a>.</div>\n"
                 + "</td>",
                 "<th class=\"colFirst\" scope=\"row\"><a href=\"moduleB-summary.html\">moduleB</a></th>\n"
                 + "<td class=\"colLast\">\n"
@@ -868,7 +878,7 @@
                 + "</td>",
                 "<th class=\"colFirst\" scope=\"row\"><a href=\"moduletags-summary.html\">moduletags</a></th>\n"
                 + "<td class=\"colLast\">\n"
-                + "<div class=\"block\">This is a test description for the moduleA module.<br>\n"
+                + "<div class=\"block\">This is a test description for the moduletags module.<br>\n"
                 + " Type Link: <a href=\"testpkgmdltags/TestClassInModuleTags.html\" title=\"class in testpkgmdltags\"><code>TestClassInModuleTags</code></a>.<br>\n"
                 + " Member Link: <a href=\"testpkgmdltags/TestClassInModuleTags.html#testMethod-java.lang.String-\"><code>testMethod(String)</code></a>.<br>\n"
                 + " Package Link: <a href=\"testpkgmdltags/package-summary.html\"><code>testpkgmdltags</code></a>.<br></div>\n"
@@ -896,7 +906,8 @@
                 "<td class=\"colFirst\">transitive static</td>\n"
                 + "<th class=\"colSecond\" scope=\"row\"><a href=\"moduleA-summary.html\">moduleA</a></th>\n"
                 + "<td class=\"colLast\">\n"
-                + "<div class=\"block\">This is a test description for the moduleA module.</div>\n"
+                + "<div class=\"block\">This is a test description for the moduleA module with a Search "
+                + "phrase <a id=\"searchphrase\" class=\"searchTagResult\">search phrase</a>.</div>\n"
                 + "</td>",
                 "<table class=\"requiresSummary\" summary=\"Requires table, listing modules, and an explanation\">\n"
                 + "<caption><span>Requires</span><span class=\"tabEnd\">&nbsp;</span></caption>\n"
--- a/langtools/test/jdk/javadoc/doclet/testModules/moduleA/module-info.java	Sat Jul 15 11:06:32 2017 -0700
+++ b/langtools/test/jdk/javadoc/doclet/testModules/moduleA/module-info.java	Sat Jul 15 14:51:42 2017 -0700
@@ -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.
   */
--- a/langtools/test/jdk/javadoc/doclet/testModules/moduletags/module-info.java	Sat Jul 15 11:06:32 2017 -0700
+++ b/langtools/test/jdk/javadoc/doclet/testModules/moduletags/module-info.java	Sat Jul 15 14:51:42 2017 -0700
@@ -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.<br>
+  * This is a test description for the moduletags module.<br>
   * Type Link: {@link testpkgmdltags.TestClassInModuleTags}.<br>
   * Member Link: {@link testpkgmdltags.TestClassInModuleTags#testMethod(String)}.<br>
   * Package Link: {@link testpkgmdltags}.<br>
--- a/langtools/test/jdk/javadoc/doclet/testSearch/TestSearch.java	Sat Jul 15 11:06:32 2017 -0700
+++ b/langtools/test/jdk/javadoc/doclet/testSearch/TestSearch.java	Sat Jul 15 14:51:42 2017 -0700
@@ -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 @@
         checkInvalidUsageIndexTag();
         checkSearchOutput(true);
         checkSingleIndex(true);
+        checkSingleIndexSearchTagDuplication();
         checkJqueryAndImageFiles(true);
         checkSearchJS();
         checkFiles(true,
@@ -86,6 +87,7 @@
         checkDocLintErrors();
         checkSearchOutput(true);
         checkSingleIndex(true);
+        checkSingleIndexSearchTagDuplication();
         checkJqueryAndImageFiles(true);
         checkSearchJS();
         checkFiles(true,
@@ -127,6 +129,7 @@
         checkExit(Exit.OK);
         checkSearchOutput(true);
         checkSingleIndex(true);
+        checkSingleIndexSearchTagDuplication();
         checkJqueryAndImageFiles(true);
         checkSearchJS();
         checkFiles(true,
@@ -210,6 +213,7 @@
         checkInvalidUsageIndexTag();
         checkSearchOutput(true);
         checkSplitIndex();
+        checkSplitIndexSearchTagDuplication();
         checkJqueryAndImageFiles(true);
         checkSearchJS();
         checkFiles(true,
@@ -498,4 +502,34 @@
                 + "        }\n"
                 + "    });");
     }
+
+    void checkSingleIndexSearchTagDuplication() {
+        // Test for search tags duplication in index file.
+        checkOutput("index-all.html", true,
+                "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestError.html#SearchTagDeprecatedMethod\">"
+                + "SearchTagDeprecatedMethod</a></span> - Search tag in pkg2.TestError</dt>\n"
+                + "<dd>with description</dd>");
+        checkOutput("index-all.html", false,
+                "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestError.html#SearchTagDeprecatedMethod\">"
+                + "SearchTagDeprecatedMethod</a></span> - Search tag in pkg2.TestError</dt>\n"
+                + "<dd>with description</dd>\n"
+                + "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestError.html#SearchTagDeprecatedMethod\">"
+                + "SearchTagDeprecatedMethod</a></span> - Search tag in pkg2.TestError</dt>\n"
+                + "<dd>with description</dd>");
+    }
+
+    void checkSplitIndexSearchTagDuplication() {
+        // Test for search tags duplication in index file.
+        checkOutput("index-files/index-13.html", true,
+                "<dt><span class=\"searchTagLink\"><a href=\"../pkg2/TestError.html#SearchTagDeprecatedMethod\">"
+                + "SearchTagDeprecatedMethod</a></span> - Search tag in pkg2.TestError</dt>\n"
+                + "<dd>with description</dd>");
+        checkOutput("index-files/index-13.html", false,
+                "<dt><span class=\"searchTagLink\"><a href=\"../pkg2/TestError.html#SearchTagDeprecatedMethod\">"
+                + "SearchTagDeprecatedMethod</a></span> - Search tag in pkg2.TestError</dt>\n"
+                + "<dd>with description</dd>\n"
+                + "<dt><span class=\"searchTagLink\"><a href=\"../pkg2/TestError.html#SearchTagDeprecatedMethod\">"
+                + "SearchTagDeprecatedMethod</a></span> - Search tag in pkg2.TestError</dt>\n"
+                + "<dd>with description</dd>");
+    }
 }