8182736: javadoc generates bad names and broken module graph links

Co-authored-by: Bhavesh Patel <bhavesh.patel@oracle.com>
Reviewed-by: jjg, bpatel, darcy, ksrini
This commit is contained in:
Jonathan Gibbons 2017-06-26 18:48:31 -07:00
parent a247f0373f
commit e7e662c3bb
8 changed files with 139 additions and 28 deletions
langtools
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets
test/jdk/javadoc/doclet/testModules

@ -140,7 +140,9 @@ public class AbstractIndexWriter extends HtmlDocletWriter {
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 @@ public class AbstractIndexWriter extends HtmlDocletWriter {
* @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 @@ public class AbstractIndexWriter extends HtmlDocletWriter {
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"));

@ -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 @@ public class TagletWriterImpl extends TagletWriter {
@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;
}

@ -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 @@ public class ModuleSummaryBuilder extends AbstractBuilder {
* @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);

@ -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 @@ public class IndexBuilder {
*/
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));

@ -1682,7 +1682,7 @@ public class Utils {
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 @@ public class Utils {
/**
* 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 class Utils {
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 @@ public class Utils {
@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);
}
@ -1915,6 +1914,11 @@ public class Utils {
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 @@ public class Utils {
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

@ -372,7 +372,20 @@ public class TestModules extends JavadocTester {
"--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 @@ public class TestModules extends JavadocTester {
"<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>");
}
}

@ -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;
}

@ -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() { }
}