Skip to content
Permalink
Browse files
8260223: Handling of unnamed package in javadoc pages
Reviewed-by: jjg
  • Loading branch information
hns committed Feb 23, 2021
1 parent 8cfea7c commit a5c4b9a6b078b12596e3e31f7f67e82f17181fdb
Show file tree
Hide file tree
Showing 33 changed files with 192 additions and 102 deletions.
@@ -99,7 +99,7 @@ protected void addPackages(Content content) {
.setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colLast);
for (PackageElement pkg : configuration.packages) {
if (!(options.noDeprecated() && utils.isDeprecated(pkg))) {
Content packageLinkContent = getPackageLink(pkg, getPackageName(pkg));
Content packageLinkContent = getPackageLink(pkg, getLocalizedPackageName(pkg));
Content summaryContent = new ContentBuilder();
addSummaryComment(pkg, summaryContent);
table.addRow(pkg, packageLinkContent, summaryContent);
@@ -44,7 +44,6 @@
import jdk.javadoc.internal.doclets.formats.html.markup.TagName;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode;
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.util.ClassTree;
import jdk.javadoc.internal.doclets.toolkit.util.ClassUseMapper;
@@ -287,7 +286,7 @@ protected void addPackageAnnotationList(Content contentTree) {
for (PackageElement pkg : pkgToPackageAnnotations) {
Content summary = new ContentBuilder();
addSummaryComment(pkg, summary);
table.addRow(getPackageLink(pkg), summary);
table.addRow(getPackageLink(pkg, getLocalizedPackageName(pkg)), summary);
}
contentTree.add(table);
}
@@ -306,7 +305,7 @@ protected void addClassList(Content contentTree) {
Content link = contents.getContent("doclet.ClassUse_Uses.of.0.in.1",
getLink(new HtmlLinkInfo(configuration, HtmlLinkInfo.Kind.CLASS_USE_HEADER,
typeElement)),
getPackageLink(pkg, utils.getPackageName(pkg)));
getPackageLink(pkg, getLocalizedPackageName(pkg)));
Content heading = HtmlTree.HEADING(Headings.TypeUse.SUMMARY_HEADING, link);
htmlTree.add(heading);
addClassUse(pkg, htmlTree);
@@ -324,7 +323,7 @@ protected void addClassList(Content contentTree) {
*/
protected void addPackageUse(PackageElement pkg, Table table) {
Content pkgLink =
links.createLink(htmlIds.forPackage(pkg), new StringContent(utils.getPackageName(pkg)));
links.createLink(htmlIds.forPackage(pkg), getLocalizedPackageName(pkg));
Content summary = new ContentBuilder();
addSummaryComment(pkg, summary);
table.addRow(pkgLink, summary);
@@ -339,7 +338,7 @@ protected void addPackageUse(PackageElement pkg, Table table) {
protected void addClassUse(PackageElement pkg, Content contentTree) {
Content classLink = getLink(new HtmlLinkInfo(configuration,
HtmlLinkInfo.Kind.CLASS_USE_HEADER, typeElement));
Content pkgLink = getPackageLink(pkg, utils.getPackageName(pkg));
Content pkgLink = getPackageLink(pkg, getLocalizedPackageName(pkg));
classSubWriter.addUseInfo(pkgToClassAnnotations.get(pkg),
contents.getContent("doclet.ClassUse_Annotation", classLink,
pkgLink), contentTree);
@@ -122,8 +122,7 @@ public Content getHeader(String header) {
Content classPackageLabel = HtmlTree.SPAN(HtmlStyle.packageLabelInType, contents.packageLabel);
Content pkgNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, classPackageLabel);
pkgNameDiv.add(Entity.NO_BREAK_SPACE);
Content pkgNameContent = getPackageLink(pkg,
new StringContent(utils.getPackageName(pkg)));
Content pkgNameContent = getPackageLink(pkg, getLocalizedPackageName(pkg));
pkgNameDiv.add(pkgNameContent);
div.add(pkgNameDiv);
}
@@ -224,7 +224,7 @@ public class Contents {
constructorSummaryLabel = getContent("doclet.Constructor_Summary");
constructors = getContent("doclet.Constructors");
contentsHeading = getContent("doclet.Contents");
defaultPackageLabel = new StringContent(DocletConstants.DEFAULT_PACKAGE_NAME);
defaultPackageLabel = getContent("doclet.Unnamed_Package");
default_ = getContent("doclet.Default");
deprecatedAPI = getContent("doclet.Deprecated_API");
deprecatedLabel = getContent("doclet.navDeprecated");
@@ -564,12 +564,14 @@ protected Content getNavLinkMainTree(String label) {
}

/**
* Returns a packagename content.
* Returns a content object containing the package name. A localized content object is
* returned for an unnamed package. Use {@link Utils#getPackageName(PackageElement)} to
* get a static string for the unnamed package instead.
*
* @param packageElement the package to check
* @return package name content
*/
public Content getPackageName(PackageElement packageElement) {
public Content getLocalizedPackageName(PackageElement packageElement) {
return packageElement == null || packageElement.isUnnamed()
? contents.defaultPackageLabel
: getPackageLabel(packageElement.getQualifiedName());
@@ -608,24 +610,6 @@ protected DocPath pathString(PackageElement packageElement, DocPath name) {
return pathToRoot.resolve(docPaths.forPackage(packageElement).resolve(name));
}

/**
* Return the link to the given package.
*
* @param packageElement the package to link to.
* @param label the label for the link.
* @return a content tree for the package link.
*/
public Content getPackageLink(PackageElement packageElement, CharSequence label) {
return getPackageLink(packageElement, new StringContent(label));
}

public Content getPackageLink(PackageElement packageElement) {
StringContent content = packageElement.isUnnamed()
? new StringContent()
: new StringContent(utils.getPackageName(packageElement));
return getPackageLink(packageElement, content);
}

/**
* Return the link to the given package.
*
@@ -799,7 +783,7 @@ public Content getCrossClassLink(TypeElement classElement, String refMemName,
return links.createLink(link,
(label == null) || label.isEmpty() ? defaultLabel : label, style,
resources.getText("doclet.Href_Class_Or_Interface_Title",
utils.getPackageName(packageElement)), true);
getLocalizedPackageName(packageElement)), true);
}
}
return null;
@@ -250,16 +250,16 @@ private String getClassToolTip(TypeElement typeElement, boolean isTypeLink) {
utils.getSimpleName(typeElement));
} else if (utils.isInterface(typeElement)){
return resources.getText("doclet.Href_Interface_Title",
utils.getPackageName(utils.containingPackage(typeElement)));
m_writer.getLocalizedPackageName(utils.containingPackage(typeElement)));
} else if (utils.isAnnotationType(typeElement)) {
return resources.getText("doclet.Href_Annotation_Title",
utils.getPackageName(utils.containingPackage(typeElement)));
m_writer.getLocalizedPackageName(utils.containingPackage(typeElement)));
} else if (utils.isEnum(typeElement)) {
return resources.getText("doclet.Href_Enum_Title",
utils.getPackageName(utils.containingPackage(typeElement)));
m_writer.getLocalizedPackageName(utils.containingPackage(typeElement)));
} else {
return resources.getText("doclet.Href_Class_Title",
utils.getPackageName(utils.containingPackage(typeElement)));
m_writer.getLocalizedPackageName(utils.containingPackage(typeElement)));
}
}

@@ -254,7 +254,7 @@ protected void addClassInfo(TypeElement te, Content contentTree) {
contentTree.add(contents.getContent("doclet.in",
utils.getTypeElementKindName(te, false),
getPackageLink(utils.containingPackage(te),
utils.getPackageName(utils.containingPackage(te)))
getLocalizedPackageName(utils.containingPackage(te)))
));
}

@@ -50,7 +50,6 @@
import jdk.javadoc.internal.doclets.formats.html.markup.TagName;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode;
import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml;
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.ModuleSummaryWriter;
@@ -183,13 +182,12 @@ public Content getModuleHeader(String heading) {
HtmlTree bodyTree = getBody(getWindowTitle(mdle.getQualifiedName().toString()));
HtmlTree div = new HtmlTree(TagName.DIV);
div.setStyle(HtmlStyle.header);
Content label = mdle.isOpen() && (configuration.docEnv.getModuleMode() == ModuleMode.ALL)
? contents.openModuleLabel : contents.moduleLabel;
Content moduleHead = new ContentBuilder();
moduleHead.add(mdle.isOpen() && (configuration.docEnv.getModuleMode() == ModuleMode.ALL)
? contents.openModuleLabel : contents.moduleLabel);
moduleHead.add(" ").add(heading);
Content tHeading = HtmlTree.HEADING_TITLE(Headings.PAGE_TITLE_HEADING,
HtmlStyle.title, label);
tHeading.add(Entity.NO_BREAK_SPACE);
Content moduleHead = new RawHtml(heading);
tHeading.add(moduleHead);
HtmlStyle.title, moduleHead);
div.add(tHeading);
bodyContents.setHeader(getHeader(PageMode.MODULE, mdle))
.addMainContent(div);
@@ -605,7 +603,7 @@ public void addPackageSummary(HtmlTree li) {
PackageElement pkg = e.getKey();
PackageEntry entry = e.getValue();
List<Content> row = new ArrayList<>();
Content pkgLinkContent = getPackageLink(pkg, new StringContent(utils.getPackageName(pkg)));
Content pkgLinkContent = getPackageLink(pkg, getLocalizedPackageName(pkg));
row.add(pkgLinkContent);

if (showExportedTo) {
@@ -675,7 +673,7 @@ public void addIndirectPackages(Table table, Map<ModuleElement, SortedSet<Packag
String sep = "";
for (PackageElement pkg : pkgList) {
list.add(sep);
list.add(getPackageLink(pkg, new StringContent(utils.getPackageName(pkg))));
list.add(getPackageLink(pkg, getLocalizedPackageName(pkg)));
sep = " ";
}
table.addRow(moduleLinkContent, list);
@@ -106,7 +106,7 @@ protected void addIndex(Content main) {
for (PackageElement pkg : configuration.packages) {
if (!pkg.isUnnamed()) {
if (!(options.noDeprecated() && utils.isDeprecated(pkg))) {
Content packageLinkContent = getPackageLink(pkg, getPackageName(pkg));
Content packageLinkContent = getPackageLink(pkg, getLocalizedPackageName(pkg));
Content summaryContent = new ContentBuilder();
addSummaryComment(pkg, summaryContent);
table.addRow(pkg, packageLinkContent, summaryContent);
@@ -96,8 +96,10 @@ public static void generate(HtmlConfiguration configuration,
protected void generatePackageTreeFile() throws DocFileIOException {
HtmlTree body = getPackageTreeHeader();
Content mainContent = new ContentBuilder();
Content headContent = contents.getContent("doclet.Hierarchy_For_Package",
utils.getPackageName(packageElement));
Content headContent = packageElement.isUnnamed()
? contents.getContent("doclet.Hierarchy_For_Unnamed_Package")
: contents.getContent("doclet.Hierarchy_For_Package",
getLocalizedPackageName(packageElement));
Content heading = HtmlTree.HEADING(Headings.PAGE_TITLE_HEADING,
HtmlStyle.title, headContent);
Content div = HtmlTree.DIV(HtmlStyle.header, heading);
@@ -119,7 +119,7 @@ protected void generatePackageUseFile() throws DocFileIOException {
HtmlTree body = getPackageUseHeader();
Content mainContent = new ContentBuilder();
if (usingPackageToUsedClasses.isEmpty()) {
mainContent.add(contents.getContent("doclet.ClassUse_No.usage.of.0", utils.getPackageName(packageElement)));
mainContent.add(contents.getContent("doclet.ClassUse_No.usage.of.0", getLocalizedPackageName(packageElement)));
} else {
addPackageUse(mainContent);
}
@@ -153,15 +153,15 @@ protected void addPackageUse(Content contentTree) {
protected void addPackageList(Content contentTree) {
Content caption = contents.getContent(
"doclet.ClassUse_Packages.that.use.0",
getPackageLink(packageElement, utils.getPackageName(packageElement)));
getPackageLink(packageElement, getLocalizedPackageName(packageElement)));
Table table = new Table(HtmlStyle.summaryTable)
.setCaption(caption)
.setHeader(getPackageTableHeader())
.setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colLast);
for (String pkgname: usingPackageToUsedClasses.keySet()) {
PackageElement pkg = utils.elementUtils.getPackageElement(pkgname);
Content packageLink = links.createLink(htmlIds.forPackage(pkg),
new StringContent(utils.getPackageName(pkg)));
getLocalizedPackageName(pkg));
Content summary = new ContentBuilder();
if (pkg != null && !pkg.isUnnamed()) {
addSummaryComment(pkg, summary);
@@ -189,8 +189,8 @@ protected void addClassList(Content contentTree) {
.setId(htmlIds.forPackage(usingPackage));
Content caption = contents.getContent(
"doclet.ClassUse_Classes.in.0.used.by.1",
getPackageLink(packageElement, utils.getPackageName(packageElement)),
getPackageLink(usingPackage, utils.getPackageName(usingPackage)));
getPackageLink(packageElement, getLocalizedPackageName(packageElement)),
getPackageLink(usingPackage, getLocalizedPackageName(usingPackage)));
Table table = new Table(HtmlStyle.summaryTable)
.setCaption(caption)
.setHeader(classTableHeader)
@@ -94,8 +94,9 @@ public PackageWriterImpl(HtmlConfiguration configuration, PackageElement package
}

@Override
public Content getPackageHeader(String heading) {
HtmlTree bodyTree = getBody(getWindowTitle(utils.getPackageName(packageElement)));
public Content getPackageHeader() {
String packageName = getLocalizedPackageName(packageElement).toString();
HtmlTree bodyTree = getBody(getWindowTitle(packageName));
HtmlTree div = new HtmlTree(TagName.DIV);
div.setStyle(HtmlStyle.header);
if (configuration.showModules) {
@@ -107,11 +108,13 @@ public Content getPackageHeader(String heading) {
new StringContent(mdle.getQualifiedName().toString())));
div.add(moduleNameDiv);
}
Content packageHead = new ContentBuilder();
if (!packageElement.isUnnamed()) {
packageHead.add(contents.packageLabel).add(" ");
}
packageHead.add(packageName);
Content tHeading = HtmlTree.HEADING_TITLE(Headings.PAGE_TITLE_HEADING,
HtmlStyle.title, contents.packageLabel);
tHeading.add(Entity.NO_BREAK_SPACE);
Content packageHead = new StringContent(heading);
tHeading.add(packageHead);
HtmlStyle.title, packageHead);
div.add(tHeading);
bodyContents.setHeader(getHeader(PageMode.PACKAGE, packageElement))
.addMainContent(div);
@@ -74,6 +74,9 @@ public static Content getModuleSignature(ModuleElement mdle, ModuleWriterImpl mo
}

public static Content getPackageSignature(PackageElement pkg, PackageWriterImpl pkgWriter) {
if (pkg.isUnnamed()) {
return new StringContent();
}
Content signature = HtmlTree.DIV(HtmlStyle.packageSignature);
Content annotations = pkgWriter.getAnnotationInfo(pkg, true);
if (!annotations.isEmpty()) {
@@ -223,7 +223,7 @@ protected void addSummaryAPI(SortedSet<Element> apiList, HtmlId id,
break;
case PACKAGE:
PackageElement pkg = (PackageElement) e;
link = getPackageLink(pkg, getPackageName(pkg));
link = getPackageLink(pkg, getLocalizedPackageName(pkg));
break;
default:
link = getSummaryLink(e);
@@ -35,7 +35,6 @@
import jdk.javadoc.internal.doclets.formats.html.markup.TagName;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode;
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.util.ClassTree;
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
@@ -149,7 +148,7 @@ protected void addPackageTreeLinks(Content contentTree) {
}
DocPath link = pathString(pkg, DocPaths.PACKAGE_TREE);
Content li = HtmlTree.LI(links.createLink(link,
new StringContent(utils.getPackageName(pkg))));
getLocalizedPackageName(pkg)));
if (i < packages.size() - 1) {
li.add(", ");
}
@@ -29,6 +29,7 @@ doclet.Overview=Overview
doclet.Window_Overview_Summary=Overview
doclet.Element=Element
doclet.Package=Package
doclet.Unnamed_Package=Unnamed Package
doclet.Module=Module
doclet.Open_Module=Open Module
doclet.All_Packages=All Packages
@@ -125,6 +126,7 @@ doclet.also=also
doclet.Package_Hierarchies=Package Hierarchies:
doclet.Hierarchy_For_Package=Hierarchy For Package {0}
doclet.Hierarchy_For_All_Packages=Hierarchy For All Packages
doclet.Hierarchy_For_Unnamed_Package=Hierarchy For Unnamed Package
doclet.No_Script_Message=JavaScript is disabled on your browser.
doclet.Description_From_Interface=Description copied from interface:
doclet.Description_From_Class=Description copied from class:
@@ -45,10 +45,9 @@ public interface PackageSummaryWriter {
/**
* Get the header for the summary.
*
* @param heading Package name.
* @return the header to be added to the content tree
*/
Content getPackageHeader(String heading);
Content getPackageHeader();

/**
* Get the header for the package content.
@@ -108,7 +108,7 @@ public void build() throws DocletException {
* @throws DocletException if there is a problem while building the documentation
*/
protected void buildPackageDoc() throws DocletException {
Content contentTree = packageWriter.getPackageHeader(utils.getPackageName(packageElement));
Content contentTree = packageWriter.getPackageHeader();

buildContent();

1 comment on commit a5c4b9a

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on a5c4b9a Feb 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.