Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
/ jdk19 Public archive

Commit

Permalink
8288058: Broken links on constant-values page
Browse files Browse the repository at this point in the history
Reviewed-by: prappo
  • Loading branch information
jonathan-gibbons committed Jun 28, 2022
1 parent a814293 commit c42b796
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
package jdk.javadoc.internal.doclets.formats.html;

import java.util.Collection;
import java.util.Set;

import javax.lang.model.element.Modifier;
import javax.lang.model.element.PackageElement;
Expand Down Expand Up @@ -97,20 +96,16 @@ public Content getContentsHeader() {
}

@Override
public void addLinkToPackageContent(PackageElement pkg,
Set<PackageElement> printedPackageHeaders, Content content) {
public void addLinkToPackageContent(String abbrevPackageName, Content content) {
//add link to summary
Content link;
if (pkg.isUnnamed()) {
if (abbrevPackageName.isEmpty()) {
link = links.createLink(HtmlIds.UNNAMED_PACKAGE_ANCHOR,
contents.defaultPackageLabel, "");
} else {
String parsedPackageName = utils.parsePackageName(pkg);
Content packageNameContent = Text.of(parsedPackageName + ".*");
link = links.createLink(DocLink.fragment(parsedPackageName),
Content packageNameContent = Text.of(abbrevPackageName + ".*");
link = links.createLink(DocLink.fragment(abbrevPackageName),
packageNameContent, "");
PackageElement abbrevPkg = configuration.workArounds.getAbbreviatedPackageElement(pkg);
printedPackageHeaders.add(abbrevPkg);
}
content.add(HtmlTree.LI(link));
}
Expand All @@ -136,26 +131,25 @@ public Content getConstantSummaries() {
}

@Override
public void addPackageName(PackageElement pkg, Content toContent, boolean first) {
Content pkgNameContent;
public void addPackageGroup(String abbrevPackageName, Content toContent) {
Content headingContent;
HtmlId anchorName;
if (!first) {
toContent.add(summarySection);
}
if (pkg.isUnnamed()) {
if (abbrevPackageName.isEmpty()) {
anchorName = HtmlIds.UNNAMED_PACKAGE_ANCHOR;
pkgNameContent = contents.defaultPackageLabel;
headingContent = contents.defaultPackageLabel;
} else {
String parsedPackageName = utils.parsePackageName(pkg);
anchorName = htmlIds.forPackage(pkg);
pkgNameContent = getPackageLabel(parsedPackageName);
anchorName = htmlIds.forPackageName(abbrevPackageName);
headingContent = new ContentBuilder(
getPackageLabel(abbrevPackageName),
Text.of(".*"));
}
var headingContent = Text.of(".*");
var heading = HtmlTree.HEADING_TITLE(Headings.ConstantsSummary.PACKAGE_HEADING,
pkgNameContent);
heading.add(headingContent);
var heading = HtmlTree.HEADING_TITLE(
Headings.ConstantsSummary.PACKAGE_HEADING,
headingContent);
summarySection = HtmlTree.SECTION(HtmlStyle.constantsSummary, heading)
.setId(anchorName);

toContent.add(summarySection);
}

@Override
Expand All @@ -175,7 +169,7 @@ public void addConstantMembers(TypeElement typeElement, Collection<VariableEleme
currentTypeElement = typeElement;

//generate links backward only to public classes.
Content classlink = (utils.isPublic(typeElement) || utils.isProtected(typeElement)) ?
Content classLink = (utils.isPublic(typeElement) || utils.isProtected(typeElement)) ?
getLink(new HtmlLinkInfo(configuration,
HtmlLinkInfo.Kind.CONSTANT_SUMMARY, typeElement)) :
Text.of(utils.getFullyQualifiedName(typeElement));
Expand All @@ -186,7 +180,7 @@ public void addConstantMembers(TypeElement typeElement, Collection<VariableEleme
caption.add(enclosingPackage.getQualifiedName());
caption.add(".");
}
caption.add(classlink);
caption.add(classLink);

Table table = new Table(HtmlStyle.summaryTable)
.setCaption(caption)
Expand Down Expand Up @@ -245,9 +239,6 @@ private Content getValue(VariableElement member) {

@Override
public void addConstantSummaries(Content content) {
if (summarySection != null) {
content.add(summarySection);
}
bodyContents.addMainContent(content);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022, 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
Expand Down Expand Up @@ -134,6 +134,19 @@ HtmlId forPackage(PackageElement element) {
: HtmlId.of(element.getQualifiedName().toString());
}

/**
* Returns an id for a package name.
*
* @param pkgName the package name
*
* @return the id
*/
HtmlId forPackageName(String pkgName) {
return pkgName.isEmpty()
? UNNAMED_PACKAGE_ANCHOR
: HtmlId.of(pkgName);
}

/**
* Returns an id for a class or interface.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,10 @@ public interface ConstantsSummaryWriter {
/**
* Adds the given package name link to the constant content list.
*
* @param pkg the {@link PackageElement} to index.
* @param writtenPackageHeaders the set of package headers that have already
* been indexed, we want to index utmost once.
* @param content the content to which the link will be added
* @param abbrevPackageName the abbreviated package name
* @param content the content to which the link will be added
*/
void addLinkToPackageContent(PackageElement pkg, Set<PackageElement> writtenPackageHeaders,
Content content);
void addLinkToPackageContent(String abbrevPackageName, Content content);

/**
* Add the content list to the documentation.
Expand All @@ -78,17 +75,12 @@ void addLinkToPackageContent(PackageElement pkg, Set<PackageElement> writtenPack
Content getConstantSummaries();

/**
* Adds the given package name.
* Adds a header for the given abbreviated package name.
*
* @param pkg the parsed package name. We only Write the
* first 2 directory levels of the package
* name. For example, java.lang.ref would be
* indexed as java.lang.*.
* @param abbrevPackageName the abbreviated package name
* @param toContent the summaries documentation
* @param first true if the first package is listed
* be written
*/
void addPackageName(PackageElement pkg, Content toContent, boolean first);
void addPackageGroup(String abbrevPackageName, Content toContent);

/**
* Get the class summary header for the constants summary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,22 +500,6 @@ public ExecutableElement findMethod(TypeElement te, String methodName,
}
}

// TODO: we need to eliminate this, as it is hacky.
/**
* Returns a representation of the package truncated to two levels.
* For instance if the given package represents foo.bar.baz will return
* a representation of foo.bar
* @param pkg the PackageElement
* @return an abbreviated PackageElement
*/
public PackageElement getAbbreviatedPackageElement(PackageElement pkg) {
String parsedPackageName = utils.parsePackageName(pkg);
ModuleElement encl = (ModuleElement) pkg.getEnclosingElement();
return encl == null
? utils.elementUtils.getPackageElement(parsedPackageName)
: ((JavacElements) utils.elementUtils).getPackageElement(encl, parsedPackageName);
}

public boolean isPreviewAPI(Element el) {
Symbol sym = (Symbol) el;
return (sym.flags() & Flags.PREVIEW_API) != 0;
Expand Down

1 comment on commit c42b796

@openjdk-notifier
Copy link

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.