changeset 4167:0d0ac75b0f6c jdk-9+176

8182736: javadoc generates bad names and broken module graph links Reviewed-by: jjg, bpatel, darcy, ksrini Contributed-by: bhavesh.patel@oracle.com, jonathan.gibbons@oracle.com
author jjg
date Mon, 26 Jun 2017 18:48:31 -0700
parents 141a3c187e1a
children 552f8fdfba55
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/TagletWriterImpl.java src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ModuleSummaryBuilder.java src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/IndexBuilder.java src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java test/jdk/javadoc/doclet/testModules/TestModules.java test/jdk/javadoc/doclet/testModules/test.moduleFullName/module-info.java test/jdk/javadoc/doclet/testModules/test.moduleFullName/testpkgmdlfullname/TestClassInTestModuleFullName.java
diffstat 8 files changed, 139 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractIndexWriter.java	Thu Jun 22 18:42:48 2017 +0000
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractIndexWriter.java	Mon Jun 26 18:48:31 2017 -0700
@@ -140,7 +140,9 @@
         int j = 0;
         Content dl = new HtmlTree(HtmlTag.DL);
         while (i < memberListSize && j < searchListSize) {
-            String name = utils.getSimpleName(memberlist.get(i));
+            Element elem = memberlist.get(i);
+            String name = (utils.isModule(elem))
+                    ? utils.getFullyQualifiedName(elem) : utils.getSimpleName(elem);
             if (name.compareTo(searchList.get(j).getLabel()) < 0) {
                 addDescription(dl, memberlist.get(i));
                 i++;
@@ -222,7 +224,7 @@
      * @param dlTree the content tree to which the description will be added
      */
     protected void addDescription(ModuleElement mdle, Content dlTree, SearchIndexItem si) {
-        String moduleName = utils.getSimpleName(mdle);
+        String moduleName = utils.getFullyQualifiedName(mdle);
         Content link = getModuleLink(mdle, new StringContent(moduleName));
         si.setLabel(moduleName);
         si.setCategory(resources.getText("doclet.Modules"));
@@ -246,7 +248,7 @@
     protected void addDescription(PackageElement pkg, Content dlTree, SearchIndexItem si) {
         Content link = getPackageLink(pkg, new StringContent(utils.getPackageName(pkg)));
         if (configuration.showModules) {
-            si.setContainingModule(utils.getSimpleName(utils.containingModule(pkg)));
+            si.setContainingModule(utils.getFullyQualifiedName(utils.containingModule(pkg)));
         }
         si.setLabel(utils.getPackageName(pkg));
         si.setCategory(resources.getText("doclet.Packages"));
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TagletWriterImpl.java	Thu Jun 22 18:42:48 2017 +0000
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TagletWriterImpl.java	Mon Jun 26 18:48:31 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -115,7 +115,7 @@
                 @Override
                 public Void visitModule(ModuleElement e, Void p) {
                     si.setUrl(DocPaths.moduleSummary(e).getPath() + "#" + anchorName);
-                    si.setHolder(utils.getSimpleName(element));
+                    si.setHolder(utils.getFullyQualifiedName(element));
                     return null;
                 }
 
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ModuleSummaryBuilder.java	Thu Jun 22 18:42:48 2017 +0000
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/ModuleSummaryBuilder.java	Mon Jun 26 18:48:31 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -131,7 +131,7 @@
      * @throws DocletException if there is a problem while building the documentation
      */
     public void buildModuleDoc(XMLNode node, Content contentTree) throws DocletException {
-        contentTree = moduleWriter.getModuleHeader(mdle.getSimpleName().toString());
+        contentTree = moduleWriter.getModuleHeader(mdle.getQualifiedName().toString());
         buildChildren(node, contentTree);
         moduleWriter.addModuleFooter(contentTree);
         moduleWriter.printDocument(contentTree);
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/IndexBuilder.java	Thu Jun 22 18:42:48 2017 +0000
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/IndexBuilder.java	Mon Jun 26 18:48:31 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -199,7 +199,7 @@
      */
     protected void addModulesToIndexMap() {
         for (ModuleElement mdle : configuration.modules) {
-            String mdleName = mdle.getSimpleName().toString();
+            String mdleName = mdle.getQualifiedName().toString();
             char ch = (mdleName.length() == 0)
                     ? '*'
                     : Character.toUpperCase(mdleName.charAt(0));
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java	Thu Jun 22 18:42:48 2017 +0000
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java	Mon Jun 26 18:48:31 2017 -0700
@@ -1682,7 +1682,7 @@
         return new Utils.ElementComparator<Element>() {
             @Override
             public int compare(Element mod1, Element mod2) {
-                return compareNames(mod1, mod2);
+                return compareFullyQualifiedNames(mod1, mod2);
             }
         };
     }
@@ -1772,9 +1772,8 @@
 
     /**
      * Returns a Comparator for index file presentations, and are sorted as follows.
-     *  If comparing modules then simply compare the simple names,
-     *  comparing packages then simply compare the qualified names, if comparing a package with a
-     *  module/type/member then compare the FullyQualifiedName of the package
+     *  If comparing modules and packages then simply compare the qualified names, if comparing a module
+     *  or a package with a type/member then compare the FullyQualifiedName of the module or a package
      *  with the SimpleName of the entity, otherwise
      *  1. compare the ElementKind ex: Module, Package, Interface etc.
      *  2a. if equal and if the type is of ExecutableElement(Constructor, Methods),
@@ -1786,10 +1785,9 @@
     public Comparator<Element> makeIndexUseComparator() {
         return new Utils.ElementComparator<Element>() {
             /**
-             * Compare two given elements, if comparing two modules, return the
-             * comparison of SimpleName, if comparing two packages, return the
-             * comparison of FullyQualifiedName, if comparing a package with a
-             * module/type/member then compare the FullyQualifiedName of the package
+             * Compare two given elements, if comparing two modules or two packages, return the
+             * comparison of FullyQualifiedName, if comparing a module or a package with a
+             * type/member then compare the FullyQualifiedName of the module or the package
              * with the SimpleName of the entity, then sort on the kinds, then on
              * the parameters only if the type is an ExecutableElement,
              * the parameters are compared and finally the qualified names.
@@ -1802,16 +1800,17 @@
             @Override
             public int compare(Element e1, Element e2) {
                 int result = 0;
-                if (isModule(e1) && isModule(e2)) {
-                    return compareNames(e1, e2);
+                if ((isModule(e1) || isPackage(e1)) && (isModule(e2) || isPackage(e2))) {
+                    result = compareFullyQualifiedNames(e1, e2);
+                    if (result != 0) {
+                        return result;
+                    }
+                    return compareElementTypeKinds(e1, e2);
                 }
-                if (isPackage(e1) && isPackage(e2)) {
-                    return compareFullyQualifiedNames(e1, e2);
-                }
-                if (isPackage(e1) || isPackage(e2)) {
-                    result = (isPackage(e1))
-                            ? compareStrings(getFullyQualifiedName(e1), getSimpleName(e2))
-                            : compareStrings(getSimpleName(e1), getFullyQualifiedName(e2));
+                if (isModule(e1) || isPackage(e1)) {
+                    result = compareStrings(getFullyQualifiedName(e1), getSimpleName(e2));
+                } else if (isModule(e2) || isPackage(e2)) {
+                    result = compareStrings(getSimpleName(e1), getFullyQualifiedName(e2));
                 } else {
                     result = compareNames(e1, e2);
                 }
@@ -1916,6 +1915,11 @@
     public String getFullyQualifiedName(Element e, final boolean outer) {
         return new SimpleElementVisitor9<String, Void>() {
             @Override
+            public String visitModule(ModuleElement e, Void p) {
+                return e.getQualifiedName().toString();
+            }
+
+            @Override
             public String visitPackage(PackageElement e, Void p) {
                 return e.getQualifiedName().toString();
             }
@@ -2527,7 +2531,7 @@
             snvisitor = new SimpleElementVisitor9<String, Void>() {
                 @Override
                 public String visitModule(ModuleElement e, Void p) {
-                    return e.getSimpleName().toString();
+                    return e.getQualifiedName().toString();  // temp fix for 8182736
                 }
 
                 @Override
--- a/test/jdk/javadoc/doclet/testModules/TestModules.java	Thu Jun 22 18:42:48 2017 +0000
+++ b/test/jdk/javadoc/doclet/testModules/TestModules.java	Mon Jun 26 18:48:31 2017 -0700
@@ -372,7 +372,20 @@
                 "--module", "moduleB",
                 "testpkg2mdlB", "testpkgmdlB");
         checkExit(Exit.OK);
-        //checkOverviewSummaryPackages();
+        checkGroupOptionSingleModule();
+    }
+
+    /**
+     * Test -group option for a single module.
+     */
+    @Test
+    void testModuleName() {
+        javadoc("-d", "out-modulename", "-use",
+                "--module-source-path", testSrc,
+                "--module", "moduleB,test.moduleFullName",
+                "testpkg2mdlB", "testpkgmdlB", "testpkgmdlfullname");
+        checkExit(Exit.OK);
+        checkModuleName(true);
     }
 
     void checkDescription(boolean found) {
@@ -1089,4 +1102,35 @@
                 "<table class=\"overviewSummary\" summary=\"Modules table, listing modules, and an explanation\">\n"
                 + "<caption><span>Modules</span><span class=\"tabEnd\">&nbsp;</span></caption>");
     }
+
+    void checkModuleName(boolean found) {
+        checkOutput("test.moduleFullName-summary.html", found,
+                "<div class=\"header\">\n"
+                + "<h1 title=\"Module\" class=\"title\">Module&nbsp;test.moduleFullName</h1>\n"
+                + "</div>");
+        checkOutput("index-all.html", found,
+                "<h2 class=\"title\">T</h2>\n"
+                + "<dl>\n"
+                + "<dt><a href=\"test.moduleFullName-summary.html\">test.moduleFullName</a> - module test.moduleFullName</dt>\n"
+                + "<dd>\n"
+                + "<div class=\"block\">This is a test description for the test.moduleFullName.</div>\n"
+                + "</dd>");
+        checkOutput("module-overview-frame.html", found,
+                "<h2 title=\"Modules\">Modules</h2>\n"
+                + "<ul title=\"Modules\">\n"
+                + "<li><a href=\"moduleB-frame.html\" target=\"packageListFrame\" onclick=\"updateModuleFrame('moduleB-type-frame.html','moduleB-summary.html');\">moduleB</a></li>\n"
+                + "<li><a href=\"test.moduleFullName-frame.html\" target=\"packageListFrame\" onclick=\"updateModuleFrame('test.moduleFullName-type-frame.html','test.moduleFullName-summary.html');\">test.moduleFullName</a></li>\n"
+                + "</ul>");
+        checkOutput("test.moduleFullName-summary.html", !found,
+                "<div class=\"header\">\n"
+                + "<h1 title=\"Module\" class=\"title\">Module&nbsp;moduleFullName</h1>\n"
+                + "</div>");
+        checkOutput("index-all.html", !found,
+                "<dl>\n"
+                + "<dt><a href=\"test.moduleFullName-summary.html\">moduleFullName</a> - module moduleFullName</dt>\n"
+                + "<dd>\n"
+                + "<div class=\"block\">This is a test description for the test.moduleFullName.</div>\n"
+                + "</dd>\n"
+                + "</dl>");
 }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javadoc/doclet/testModules/test.moduleFullName/module-info.java	Mon Jun 26 18:48:31 2017 -0700
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+  * This is a test description for the test.moduleFullName.
+  *
+  */
+module test.moduleFullName {
+    exports testpkgmdlfullname;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javadoc/doclet/testModules/test.moduleFullName/testpkgmdlfullname/TestClassInTestModuleFullName.java	Mon Jun 26 18:48:31 2017 -0700
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package testpkgmdlfullname;
+
+public class TestClassInTestModuleFullName {
+    public void testMethod() { }
+}