diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java index a4596536bc92..9d26192d5a4c 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java @@ -296,12 +296,6 @@ protected void setTopFile() { } else { if (showModules) { topFile = DocPath.empty.resolve(docPaths.moduleSummary(modules.first())); - } else if (packages.size() == 1 && packages.first().isUnnamed()) { - List 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); } diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageIndexWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageIndexWriter.java index 61ee3c7507f8..11bb4d6def59 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageIndexWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageIndexWriter.java @@ -105,13 +105,11 @@ protected void addIndex(Content main) { } 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); } } diff --git a/test/langtools/jdk/javadoc/doclet/testUnnamedPackage/TestUnnamedPackage.java b/test/langtools/jdk/javadoc/doclet/testUnnamedPackage/TestUnnamedPackage.java index a88260f3d56e..9f9dce38a645 100644 --- a/test/langtools/jdk/javadoc/doclet/testUnnamedPackage/TestUnnamedPackage.java +++ b/test/langtools/jdk/javadoc/doclet/testUnnamedPackage/TestUnnamedPackage.java @@ -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 void test() { testSrc("src1/C.java")); checkExit(Exit.OK); + checkOutput("index.html", true, + """ + + """); checkOutput("package-summary.html", true, """

Unnamed Package

""", @@ -156,4 +163,25 @@ public void testUse() { eters of type A"""); } + + @Test + public void testMixed() { + javadoc("-d", "out-mixed", + "-sourcepath", testSrc("src1"), + testSrc("src1/C.java"), + "pkg"); + checkExit(Exit.OK); + + checkOutput("index.html", true, + """ +
Unnamed Package
+
+
This is a package comment for the unnamed package.
+
+
\ + pkg
+
+
This is a package comment for package pkg.
"""); + } } diff --git a/test/langtools/jdk/javadoc/doclet/testUnnamedPackage/src1/pkg/D.java b/test/langtools/jdk/javadoc/doclet/testUnnamedPackage/src1/pkg/D.java new file mode 100644 index 000000000000..9d2e399758d4 --- /dev/null +++ b/test/langtools/jdk/javadoc/doclet/testUnnamedPackage/src1/pkg/D.java @@ -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 {} diff --git a/test/langtools/jdk/javadoc/doclet/testUnnamedPackage/src1/pkg/package.html b/test/langtools/jdk/javadoc/doclet/testUnnamedPackage/src1/pkg/package.html new file mode 100644 index 000000000000..100df50ca6c7 --- /dev/null +++ b/test/langtools/jdk/javadoc/doclet/testUnnamedPackage/src1/pkg/package.html @@ -0,0 +1,5 @@ + + + This is a package comment for package pkg. + +