8256208: Javadoc's generated overview does not show classes of unnamed package

Reviewed-by: jjg
This commit is contained in:
Hannes Wallnöfer 2021-11-09 15:05:07 +00:00
parent f65db88b74
commit e35abe3235
5 changed files with 67 additions and 13 deletions
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html
test/langtools/jdk/javadoc/doclet/testUnnamedPackage

@ -296,12 +296,6 @@ public class HtmlConfiguration extends BaseConfiguration {
} else {
if (showModules) {
topFile = DocPath.empty.resolve(docPaths.moduleSummary(modules.first()));
} else if (packages.size() == 1 && packages.first().isUnnamed()) {
List<TypeElement> classes = new ArrayList<>(getIncludedTypeElements());
if (!classes.isEmpty()) {
TypeElement te = getValidClass(classes);
topFile = docPaths.forClass(te);
}
} else if (!packages.isEmpty()) {
topFile = docPaths.forPackage(packages.first()).resolve(DocPaths.PACKAGE_SUMMARY);
}

@ -105,13 +105,11 @@ public class PackageIndexWriter extends AbstractOverviewIndexWriter {
}
for (PackageElement pkg : configuration.packages) {
if (!pkg.isUnnamed()) {
if (!(options.noDeprecated() && utils.isDeprecated(pkg))) {
Content packageLinkContent = getPackageLink(pkg, getLocalizedPackageName(pkg));
Content summaryContent = new ContentBuilder();
addSummaryComment(pkg, summaryContent);
table.addRow(pkg, packageLinkContent, summaryContent);
}
if (!(options.noDeprecated() && utils.isDeprecated(pkg))) {
Content packageLinkContent = getPackageLink(pkg, getLocalizedPackageName(pkg));
Content summaryContent = new ContentBuilder();
addSummaryComment(pkg, summaryContent);
table.addRow(pkg, packageLinkContent, summaryContent);
}
}

@ -24,6 +24,7 @@
/*
* @test
* @bug 4904075 4774450 5015144 8043698 8196201 8203791 8184205 8260223
* 8256208
* @summary Reference unnamed package as "Unnamed", not empty string.
* Generate a package summary for the unnamed package.
* @library ../../lib
@ -48,6 +49,12 @@ public class TestUnnamedPackage extends JavadocTester {
testSrc("src1/C.java"));
checkExit(Exit.OK);
checkOutput("index.html", true,
"""
<script type="text/javascript">window.location.replace('package-summary.html')</script>
<noscript>
<meta http-equiv="Refresh" content="0;package-summary.html">
</noscript>""");
checkOutput("package-summary.html", true,
"""
<h1 title="Unnamed Package" class="title">Unnamed Package</h1>""",
@ -156,4 +163,25 @@ public class TestUnnamedPackage extends JavadocTester {
eters of type <a href="../A.html" title="class in Unnamed Package">A</a>""");
}
@Test
public void testMixed() {
javadoc("-d", "out-mixed",
"-sourcepath", testSrc("src1"),
testSrc("src1/C.java"),
"pkg");
checkExit(Exit.OK);
checkOutput("index.html", true,
"""
<div class="col-first even-row-color all-packages-table all-packages-table-tab1"\
><a href="package-summary.html">Unnamed Package</a></div>
<div class="col-last even-row-color all-packages-table all-packages-table-tab1">
<div class="block">This is a package comment for the unnamed package.</div>
</div>
<div class="col-first odd-row-color all-packages-table all-packages-table-tab1">\
<a href="pkg/package-summary.html">pkg</a></div>
<div class="col-last odd-row-color all-packages-table all-packages-table-tab1">
<div class="block">This is a package comment for package pkg.</div>""");
}
}

@ -0,0 +1,29 @@
/*
* Copyright (c) 2021, 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.
*
* 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 pkg;
/**
* This is class D in the package pkg.
*/
public class D {}

@ -0,0 +1,5 @@
<html>
<body>
This is a package comment for package pkg.
</body>
</html>