changeset 53663:99eb43bc3595

8213716: javadoc search not working with Japanese and Chinese locales Reviewed-by: jjg
author hannesw
date Tue, 27 Nov 2018 13:02:28 +0100
parents 93afbb11063b
children b80549fdb52f
files src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractIndexWriter.java src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SearchIndexItem.java src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TagletWriterImpl.java src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/doclets.properties src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/doclets_ja.properties src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/doclets_zh_CN.properties test/langtools/jdk/javadoc/doclet/testSearch/TestSearch.java
diffstat 7 files changed, 68 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractIndexWriter.java	Tue Nov 27 11:09:53 2018 +0000
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractIndexWriter.java	Tue Nov 27 13:02:28 2018 +0100
@@ -223,7 +223,7 @@
         String moduleName = utils.getFullyQualifiedName(mdle);
         Content link = getModuleLink(mdle, new StringContent(moduleName));
         si.setLabel(moduleName);
-        si.setCategory(resources.getText("doclet.Modules"));
+        si.setCategory(SearchIndexItem.Category.MODULES);
         Content dt = HtmlTree.DT(link);
         dt.addContent(" - ");
         dt.addContent(contents.module_);
@@ -247,7 +247,7 @@
             si.setContainingModule(utils.getFullyQualifiedName(utils.containingModule(pkg)));
         }
         si.setLabel(utils.getPackageName(pkg));
-        si.setCategory(resources.getText("doclet.Packages"));
+        si.setCategory(SearchIndexItem.Category.PACKAGES);
         Content dt = HtmlTree.DT(link);
         dt.addContent(" - ");
         dt.addContent(contents.package_);
@@ -270,7 +270,7 @@
                         LinkInfoImpl.Kind.INDEX, typeElement).strong(true));
         si.setContainingPackage(utils.getPackageName(utils.containingPackage(typeElement)));
         si.setLabel(utils.getSimpleName(typeElement));
-        si.setCategory(resources.getText("doclet.Types"));
+        si.setCategory(SearchIndexItem.Category.TYPES);
         Content dt = HtmlTree.DT(link);
         dt.addContent(" - ");
         addClassInfo(typeElement, dt);
@@ -318,7 +318,7 @@
         }  else {
             si.setLabel(name);
         }
-        si.setCategory(resources.getText("doclet.Members"));
+        si.setCategory(SearchIndexItem.Category.MEMBERS);
         Content span = HtmlTree.SPAN(HtmlStyle.memberNameLink,
                 getDocLink(LinkInfoImpl.Kind.INDEX, member, name));
         Content dt = HtmlTree.DT(span);
@@ -439,7 +439,7 @@
         }
         if (!configuration.packages.isEmpty()) {
             SearchIndexItem si = new SearchIndexItem();
-            si.setCategory(resources.getText("doclet.Packages"));
+            si.setCategory(SearchIndexItem.Category.PACKAGES);
             si.setLabel(resources.getText("doclet.All_Packages"));
             si.setUrl(DocPaths.ALLPACKAGES_INDEX.getPath());
             configuration.packageSearchIndex.add(si);
@@ -447,7 +447,7 @@
         createSearchIndexFile(DocPaths.PACKAGE_SEARCH_INDEX_JSON, DocPaths.PACKAGE_SEARCH_INDEX_ZIP,
                 DocPaths.PACKAGE_SEARCH_INDEX_JS, configuration.packageSearchIndex, "packageSearchIndex");
         SearchIndexItem si = new SearchIndexItem();
-        si.setCategory(resources.getText("doclet.Types"));
+        si.setCategory(SearchIndexItem.Category.TYPES);
         si.setLabel(resources.getText("doclet.All_Classes"));
         si.setUrl(DocPaths.ALLCLASSES_INDEX.getPath());
         configuration.typeSearchIndex.add(si);
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SearchIndexItem.java	Tue Nov 27 11:09:53 2018 +0000
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SearchIndexItem.java	Tue Nov 27 13:02:28 2018 +0100
@@ -35,9 +35,17 @@
  */
 public class SearchIndexItem {
 
+    enum Category {
+        MODULES,
+        PACKAGES,
+        TYPES,
+        MEMBERS,
+        SEARCH_TAGS
+    }
+
+    private Category category;
     private String label = "";
     private String url = "";
-    private String category = "";
     private String containingModule = "";
     private String containingPackage = "";
     private String containingClass = "";
@@ -72,7 +80,7 @@
         containingClass = c;
     }
 
-    public void setCategory(String c) {
+    public void setCategory(Category c) {
         category = c;
     }
 
@@ -94,11 +102,13 @@
 
     public String toString() {
         StringBuilder item = new StringBuilder("");
-        if (category.equals("Modules")) {
+        switch (category) {
+        case MODULES:
             item.append("{")
                     .append("\"l\":\"").append(label).append("\"")
                     .append("}");
-        } else if (category.equals("Packages")) {
+            break;
+        case PACKAGES:
             item.append("{");
             if (!containingModule.isEmpty()) {
                 item.append("\"m\":\"").append(containingModule).append("\",");
@@ -108,7 +118,8 @@
                 item.append(",\"url\":\"").append(url).append("\"");
             }
             item.append("}");
-        } else if (category.equals("Types")) {
+            break;
+        case TYPES:
             item.append("{");
             if (!containingPackage.equals("")) {
                 item.append("\"p\":\"").append(containingPackage).append("\",");
@@ -118,7 +129,8 @@
                 item.append(",\"url\":\"").append(url).append("\"");
             }
             item.append("}");
-        } else if (category.equals("Members")) {
+            break;
+        case MEMBERS:
             item.append("{")
                     .append("\"p\":\"").append(containingPackage).append("\",")
                     .append("\"c\":\"").append(containingClass).append("\",")
@@ -127,7 +139,8 @@
                 item.append(",\"url\":\"").append(url).append("\"");
             }
             item.append("}");
-        } else {
+            break;
+        case SEARCH_TAGS:
             item.append("{")
                     .append("\"l\":\"").append(label).append("\",")
                     .append("\"h\":\"").append(holder).append("\",");
@@ -136,6 +149,9 @@
             }
             item.append("\"u\":\"").append(url).append("\"")
                     .append("}");
+            break;
+        default:
+            throw new IllegalStateException("category not set");
         }
         return item.toString();
     }
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TagletWriterImpl.java	Tue Nov 27 11:09:53 2018 +0000
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TagletWriterImpl.java	Tue Nov 27 13:02:28 2018 +0100
@@ -457,8 +457,7 @@
                         return null;
                     }
                 }.visit(element);
-                Contents contents = configuration.getContents();
-                si.setCategory(contents.getContent("doclet.SearchTags").toString());
+                si.setCategory(SearchIndexItem.Category.SEARCH_TAGS);
                 configuration.tagSearchIndex.add(si);
             }
         }
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/doclets.properties	Tue Nov 27 11:09:53 2018 +0000
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/doclets.properties	Tue Nov 27 13:02:28 2018 +0100
@@ -211,9 +211,6 @@
 doclet.Type=Type
 doclet.Modifier_and_Type=Modifier and Type
 doclet.Implementation=Implementation(s):
-doclet.Types=Types
-doclet.Members=Members
-doclet.SearchTags=SearchTags
 doclet.search=SEARCH:
 doclet.Field=Field
 doclet.Property=Property
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/doclets_ja.properties	Tue Nov 27 11:09:53 2018 +0000
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/doclets_ja.properties	Tue Nov 27 13:02:28 2018 +0100
@@ -202,9 +202,6 @@
 doclet.Type=\u30BF\u30A4\u30D7
 doclet.Modifier_and_Type=\u4FEE\u98FE\u5B50\u3068\u30BF\u30A4\u30D7
 doclet.Implementation=\u5B9F\u88C5:
-doclet.Types=\u30BF\u30A4\u30D7
-doclet.Members=\u30E1\u30F3\u30D0\u30FC
-doclet.SearchTags=SearchTags
 doclet.search=SEARCH:
 doclet.Field=\u30D5\u30A3\u30FC\u30EB\u30C9
 doclet.Property=\u30D7\u30ED\u30D1\u30C6\u30A3
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/doclets_zh_CN.properties	Tue Nov 27 11:09:53 2018 +0000
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/doclets_zh_CN.properties	Tue Nov 27 13:02:28 2018 +0100
@@ -202,9 +202,6 @@
 doclet.Type=\u7C7B\u578B
 doclet.Modifier_and_Type=\u4FEE\u9970\u7B26\u548C\u7C7B\u578B
 doclet.Implementation=\u5B9E\u73B0:
-doclet.Types=\u7C7B\u578B
-doclet.Members=\u6210\u5458
-doclet.SearchTags=\u641C\u7D22\u6807\u8BB0
 doclet.search=SEARCH:
 doclet.Field=\u5B57\u6BB5
 doclet.Property=\u5C5E\u6027
--- a/test/langtools/jdk/javadoc/doclet/testSearch/TestSearch.java	Tue Nov 27 11:09:53 2018 +0000
+++ b/test/langtools/jdk/javadoc/doclet/testSearch/TestSearch.java	Tue Nov 27 13:02:28 2018 +0100
@@ -362,6 +362,44 @@
         checkSearchIndex(false);
     }
 
+    @Test
+    void testJapaneseLocale() {
+        javadoc("-locale", "ja_JP",
+                "-d", "out-jp",
+                "--no-module-directories",
+                "-Xdoclint:none",
+                "-sourcepath", testSrc,
+                "-use",
+                "pkg", "pkg1", "pkg2", "pkg3");
+        checkExit(Exit.OK);
+        checkOutput(Output.OUT, true,
+                "\u30d1\u30c3\u30b1\u30fc\u30b8pkg\u306e\u30bd\u30fc\u30b9\u30fb\u30d5\u30a1" +
+                        "\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3093\u3067\u3044\u307e\u3059...\n",
+                "\u30d1\u30c3\u30b1\u30fc\u30b8pkg1\u306e\u30bd\u30fc\u30b9\u30fb\u30d5\u30a1" +
+                        "\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3093\u3067\u3044\u307e\u3059...\n");
+        checkSearchJS();
+        checkSearchIndex(true);
+    }
+
+    @Test
+    void testChineseLocale() {
+        javadoc("-locale", "zh_CN",
+                "-d", "out-cn",
+                "--no-module-directories",
+                "-Xdoclint:none",
+                "-sourcepath", testSrc,
+                "-use",
+                "pkg", "pkg1", "pkg2", "pkg3");
+        checkExit(Exit.OK);
+        checkOutput(Output.OUT, true,
+                "\u6b63\u5728\u52a0\u8f7d\u7a0b\u5e8f\u5305pkg\u7684\u6e90\u6587\u4ef6...\n",
+                "\u6b63\u5728\u52a0\u8f7d\u7a0b\u5e8f\u5305pkg1\u7684\u6e90\u6587\u4ef6...\n",
+                "\u6b63\u5728\u52a0\u8f7d\u7a0b\u5e8f\u5305pkg2\u7684\u6e90\u6587\u4ef6...\n",
+                "\u6b63\u5728\u52a0\u8f7d\u7a0b\u5e8f\u5305pkg3\u7684\u6e90\u6587\u4ef6...\n");
+        checkSearchJS();
+        checkSearchIndex(true);
+    }
+
     void checkDocLintErrors() {
         checkOutput(Output.OUT, true,
                 "A sample method. Testing search tag for {@index \"unclosed quote}.",