Skip to content
Permalink
Browse files
8259283: use new HtmlId and HtmlIds classes
Reviewed-by: hannesw
  • Loading branch information
jonathan-gibbons committed Jan 13, 2021
1 parent 5df2a94 commit 916ab4e7d8aeac010d9ff267a67a9da34017eac3
Showing 39 changed files with 729 additions and 469 deletions.
@@ -282,61 +282,4 @@ protected TypeElement implementsMethodInIntfac(ExecutableElement method,
}
return null;
}

/**
* For backward compatibility, include an anchor using the erasures of the
* parameters. NOTE: We won't need this method anymore after we fix
* see tags so that they use the type instead of the erasure.
*
* @param executableElement the ExecutableElement to anchor to.
* @return the 1.4.x style anchor for the executable element.
*/
protected String getErasureAnchor(ExecutableElement executableElement) {
final StringBuilder buf = new StringBuilder(executableElement.getSimpleName());
buf.append("(");
List<? extends VariableElement> parameters = executableElement.getParameters();
boolean foundTypeVariable = false;
for (int i = 0; i < parameters.size(); i++) {
if (i > 0) {
buf.append(",");
}
TypeMirror t = parameters.get(i).asType();
SimpleTypeVisitor9<Boolean, Void> stv = new SimpleTypeVisitor9<>() {
boolean foundTypeVariable = false;

@Override
public Boolean visitArray(ArrayType t, Void p) {
visit(t.getComponentType());
buf.append(utils.getDimension(t));
return foundTypeVariable;
}

@Override
public Boolean visitTypeVariable(TypeVariable t, Void p) {
buf.append(utils.asTypeElement(t).getQualifiedName());
foundTypeVariable = true;
return foundTypeVariable;
}

@Override
public Boolean visitDeclared(DeclaredType t, Void p) {
buf.append(utils.getQualifiedTypeName(t));
return foundTypeVariable;
}

@Override
protected Boolean defaultAction(TypeMirror e, Void p) {
buf.append(e);
return foundTypeVariable;
}
};

boolean isTypeVariable = stv.visit(t);
if (!foundTypeVariable) {
foundTypeVariable = isTypeVariable;
}
}
buf.append(")");
return foundTypeVariable ? writer.links.getName(buf.toString()) : null;
}
}
@@ -68,6 +68,7 @@ public abstract class AbstractMemberWriter implements MemberSummaryWriter, Membe
protected final Contents contents;
protected final Resources resources;
protected final Links links;
protected final HtmlIds htmlIds;

protected final TypeElement typeElement;

@@ -80,6 +81,7 @@ public AbstractMemberWriter(SubWriterHolderWriter writer, TypeElement typeElemen
this.contents = configuration.getContents();
this.resources = configuration.docResources;
this.links = writer.links;
this.htmlIds = configuration.htmlIds;
}

public AbstractMemberWriter(SubWriterHolderWriter writer) {
@@ -117,7 +117,7 @@ protected void addContents(Content content) {
Table table = new Table(HtmlStyle.summaryTable)
.setHeader(new TableHeader(contents.classLabel, contents.descriptionLabel))
.setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colLast)
.setId("all-classes-table")
.setId(HtmlIds.ALL_CLASSES_TABLE)
.setDefaultTab(resources.getText("doclet.All_Classes"))
.addTab(contents.interfaceSummary, utils::isInterface)
.addTab(contents.classSummary, e -> utils.isOrdinaryClass((TypeElement)e))
@@ -77,7 +77,7 @@ public Content getMemberSummaryHeader(TypeElement typeElement,
@Override
public void addSummary(Content summariesList, Content content) {
writer.addSummary(HtmlStyle.memberSummary,
SectionName.ANNOTATION_TYPE_OPTIONAL_ELEMENT_SUMMARY, summariesList, content);
HtmlIds.ANNOTATION_TYPE_OPTIONAL_ELEMENT_SUMMARY, summariesList, content);
}

@Override
@@ -84,7 +84,7 @@ public Content getMemberTreeHeader() {
@Override
public void addSummary(Content summariesList, Content content) {
writer.addSummary(HtmlStyle.memberSummary,
SectionName.ANNOTATION_TYPE_REQUIRED_ELEMENT_SUMMARY, summariesList, content);
HtmlIds.ANNOTATION_TYPE_REQUIRED_ELEMENT_SUMMARY, summariesList, content);
}

@Override
@@ -114,7 +114,7 @@ public Content getAnnotationDocTreeHeader(Element member) {
new StringContent(simpleName));
annotationDocTree.add(heading);
return HtmlTree.SECTION(HtmlStyle.detail, annotationDocTree)
.setId(simpleName + utils.signature((ExecutableElement) member, typeElement));
.setId(htmlIds.forMember(typeElement, (ExecutableElement) member));
}

@Override
@@ -303,7 +303,8 @@ protected void addClassList(Content contentTree) {
HtmlTree ul = new HtmlTree(TagName.UL);
ul.setStyle(HtmlStyle.blockList);
for (PackageElement pkg : pkgSet) {
HtmlTree htmlTree = HtmlTree.SECTION(HtmlStyle.detail).setId(getPackageAnchorName(pkg));
HtmlTree htmlTree = HtmlTree.SECTION(HtmlStyle.detail)
.setId(htmlIds.forPackage(pkg));
Content link = contents.getContent("doclet.ClassUse_Uses.of.0.in.1",
getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.CLASS_USE_HEADER,
typeElement)),
@@ -325,7 +326,7 @@ protected void addClassList(Content contentTree) {
*/
protected void addPackageUse(PackageElement pkg, Table table) {
Content pkgLink =
links.createLink(getPackageAnchorName(pkg), new StringContent(utils.getPackageName(pkg)));
links.createLink(htmlIds.forPackage(pkg), new StringContent(utils.getPackageName(pkg)));
Content summary = new ContentBuilder();
addSummaryComment(pkg, summary);
table.addRow(pkgLink, summary);
@@ -30,20 +30,17 @@
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.stream.Collectors;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ModuleElement;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.RecordComponentElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.SimpleElementVisitor8;

import com.sun.source.doctree.DeprecatedTree;
import com.sun.source.doctree.DocTree;
import javax.lang.model.element.ElementKind;
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.formats.html.markup.Entity;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlAttr;
@@ -59,7 +56,6 @@
import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper;
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
import jdk.javadoc.internal.doclets.toolkit.util.DocletConstants;

/**
* Generate the Class Information Page.
@@ -200,7 +196,7 @@ public void addClassSignature(String modifiers, Content classInfoTree) {
}
if (previewModifiers.contains(modifiersPart)) {
mods.add(modifiersPart);
mods.add(HtmlTree.SUP(links.createLink(getPreviewSectionAnchor(typeElement),
mods.add(HtmlTree.SUP(links.createLink(htmlIds.forPreviewSection(typeElement),
contents.previewMark)));
} else {
mods.add(modifiersPart);
@@ -498,7 +494,7 @@ public Content getMemberDetailsTree(Content contentTree) {
HtmlTree section = HtmlTree.SECTION(HtmlStyle.details, contentTree);
// The following id is required by the Navigation bar
if (utils.isAnnotationType(typeElement)) {
section.setId(SectionName.ANNOTATION_TYPE_ELEMENT_DETAIL.getName());
section.setId(HtmlIds.ANNOTATION_TYPE_ELEMENT_DETAIL);
}
return section;
}
@@ -36,6 +36,7 @@
import jdk.javadoc.internal.doclets.formats.html.markup.BodyContents;
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.formats.html.markup.Entity;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlId;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.TagName;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
@@ -108,7 +109,7 @@ public void addLinkToPackageContent(PackageElement pkg,
//add link to summary
Content link;
if (pkg.isUnnamed()) {
link = links.createLink(SectionName.UNNAMED_PACKAGE_ANCHOR,
link = links.createLink(HtmlIds.UNNAMED_PACKAGE_ANCHOR,
contents.defaultPackageLabel, "", "");
} else {
String parsedPackageName = utils.parsePackageName(pkg);
@@ -145,24 +146,24 @@ public Content getConstantSummaries() {
@Override
public void addPackageName(PackageElement pkg, Content summariesTree, boolean first) {
Content pkgNameContent;
String anchorName;
HtmlId anchorName;
if (!first) {
summariesTree.add(summaryTree);
}
if (pkg.isUnnamed()) {
anchorName = SectionName.UNNAMED_PACKAGE_ANCHOR.getName();
anchorName = HtmlIds.UNNAMED_PACKAGE_ANCHOR;
pkgNameContent = contents.defaultPackageLabel;
} else {
String parsedPackageName = utils.parsePackageName(pkg);
anchorName = parsedPackageName;
anchorName = htmlIds.forPackage(pkg);
pkgNameContent = getPackageLabel(parsedPackageName);
}
Content headingContent = new StringContent(".*");
Content heading = HtmlTree.HEADING_TITLE(Headings.ConstantsSummary.PACKAGE_HEADING,
pkgNameContent);
heading.add(headingContent);
summaryTree = HtmlTree.SECTION(HtmlStyle.constantsSummary, heading)
.setId(links.getName(anchorName));
.setId(anchorName);
}

@Override
@@ -216,8 +217,8 @@ public void addConstantMembers(TypeElement typeElement, Collection<VariableEleme
*/
private Content getTypeColumn(VariableElement member) {
Content typeContent = new ContentBuilder();
String id = currentTypeElement.getQualifiedName() + "." + member.getSimpleName();
Content code = new HtmlTree(TagName.CODE).setId(id);
Content code = new HtmlTree(TagName.CODE)
.setId(htmlIds.forMember(currentTypeElement, member));
for (Modifier mod : member.getModifiers()) {
Content modifier = new StringContent(mod.toString());
code.add(modifier);
@@ -34,6 +34,7 @@

import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.formats.html.markup.Entity;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlId;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.TagName;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
@@ -101,7 +102,7 @@ public Content getMemberSummaryHeader(TypeElement typeElement,
@Override
public void addSummary(Content summariesList, Content content) {
writer.addSummary(HtmlStyle.constructorSummary,
SectionName.CONSTRUCTOR_SUMMARY, summariesList, content);
HtmlIds.CONSTRUCTOR_SUMMARY, summariesList, content);
}

@Override
@@ -116,16 +117,16 @@ public Content getConstructorDetailsTreeHeader(Content memberDetailsTree) {

@Override
public Content getConstructorDocTreeHeader(ExecutableElement constructor) {
String erasureAnchor;
Content constructorDocTree = new ContentBuilder();
HtmlTree heading = HtmlTree.HEADING(Headings.TypeDeclaration.MEMBER_HEADING,
new StringContent(name(constructor)));
if ((erasureAnchor = getErasureAnchor(constructor)) != null) {
HtmlId erasureAnchor = htmlIds.forErasure(constructor);
if (erasureAnchor != null) {
heading.setId(erasureAnchor);
}
constructorDocTree.add(heading);
return HtmlTree.SECTION(HtmlStyle.detail, constructorDocTree)
.setId(links.getAnchor(constructor));
.setId(htmlIds.forMember(constructor));
}

@Override
@@ -161,7 +162,7 @@ public void addTags(ExecutableElement constructor, Content constructorDocTree) {
public Content getConstructorDetails(Content constructorDetailsTreeHeader, Content constructorDetailsTree) {
return writer.getDetailsListItem(
HtmlTree.SECTION(HtmlStyle.constructorDetails)
.setId(SectionName.CONSTRUCTOR_DETAIL.getName())
.setId(HtmlIds.CONSTRUCTOR_DETAIL)
.add(constructorDetailsTreeHeader)
.add(constructorDetailsTree));
}
@@ -80,14 +80,14 @@ public static void generate(HtmlConfiguration configuration) throws DocFileIOExc

@Override
protected void addExtraSection(DeprecatedAPIListBuilder list, Content content) {
addSummaryAPI(list.getForRemoval(), "forRemoval",
addSummaryAPI(list.getForRemoval(), HtmlIds.FOR_REMOVAL,
"doclet.For_Removal", "doclet.Element", content);
}

@Override
protected void addExtraIndexLink(DeprecatedAPIListBuilder list, Content target) {
if (!list.getForRemoval().isEmpty()) {
addIndexLink("forRemoval", "doclet.For_Removal", target);
addIndexLink(HtmlIds.FOR_REMOVAL, "doclet.For_Removal", target);
}
}

@@ -71,7 +71,7 @@ public Content getMemberSummaryHeader(TypeElement typeElement,
@Override
public void addSummary(Content summariesList, Content content) {
writer.addSummary(HtmlStyle.constantsSummary,
SectionName.ENUM_CONSTANT_SUMMARY, summariesList, content);
HtmlIds.ENUM_CONSTANT_SUMMARY, summariesList, content);
}

@Override
@@ -93,7 +93,7 @@ public Content getEnumConstantsTreeHeader(VariableElement enumConstant,
new StringContent(name(enumConstant)));
enumConstantsTree.add(heading);
return HtmlTree.SECTION(HtmlStyle.detail, enumConstantsTree)
.setId(name(enumConstant));
.setId(htmlIds.forMember(enumConstant));
}

@Override
@@ -129,7 +129,7 @@ public Content getEnumConstantsDetails(Content enumConstantsDetailsTreeHeader,
Content enumConstantsDetailsTree) {
return writer.getDetailsListItem(
HtmlTree.SECTION(HtmlStyle.constantDetails)
.setId(SectionName.ENUM_CONSTANT_DETAIL.getName())
.setId(HtmlIds.ENUM_CONSTANT_DETAIL)
.add(enumConstantsDetailsTreeHeader)
.add(enumConstantsDetailsTree));
}
@@ -74,7 +74,7 @@ public Content getMemberSummaryHeader(TypeElement typeElement,
@Override
public void addSummary(Content summariesList, Content content) {
writer.addSummary(HtmlStyle.fieldSummary,
SectionName.FIELD_SUMMARY, summariesList, content);
HtmlIds.FIELD_SUMMARY, summariesList, content);
}

@Override
@@ -93,7 +93,8 @@ public Content getFieldDocTreeHeader(VariableElement field) {
Content heading = HtmlTree.HEADING(Headings.TypeDeclaration.MEMBER_HEADING,
new StringContent(name(field)));
fieldTree.add(heading);
return HtmlTree.SECTION(HtmlStyle.detail, fieldTree).setId(name(field));
return HtmlTree.SECTION(HtmlStyle.detail, fieldTree)
.setId(htmlIds.forMember(field));
}

@Override
@@ -130,7 +131,7 @@ public void addTags(VariableElement field, Content fieldTree) {
public Content getFieldDetails(Content fieldDetailsTreeHeader, Content fieldDetailsTree) {
return writer.getDetailsListItem(
HtmlTree.SECTION(HtmlStyle.fieldDetails)
.setId(SectionName.FIELD_DETAIL.getName())
.setId(HtmlIds.FIELD_DETAIL)
.add(fieldDetailsTreeHeader)
.add(fieldDetailsTree));
}
@@ -175,8 +176,7 @@ public void addInheritedSummaryLabel(TypeElement typeElement, Content inheritedT
}
HtmlTree labelHeading = HtmlTree.HEADING(Headings.TypeDeclaration.INHERITED_SUMMARY_HEADING,
label);
labelHeading.setId(SectionName.FIELDS_INHERITANCE.getName()
+ links.getName(configuration.getClassName(typeElement)));
labelHeading.setId(htmlIds.forInheritedFields(typeElement));
labelHeading.add(Entity.NO_BREAK_SPACE);
labelHeading.add(classLink);
inheritedTree.add(labelHeading);
@@ -134,6 +134,8 @@ public class HtmlConfiguration extends BaseConfiguration {

public DocPaths docPaths;

public HtmlIds htmlIds;

public Map<Element, List<DocPath>> localStylesheetMap = new HashMap<>();

private final HtmlOptions options;
@@ -208,6 +210,7 @@ protected void initConfiguration(DocletEnvironment docEnv,
Function<String, String> resourceKeyMapper) {
super.initConfiguration(docEnv, resourceKeyMapper);
contents = new Contents(this);
htmlIds = new HtmlIds(this);
}

private final Runtime.Version docletVersion;

1 comment on commit 916ab4e

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 916ab4e Jan 13, 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.