Skip to content

Commit

Permalink
8335122: Reorganize internal low-level support for HTML in jdk.javadoc
Browse files Browse the repository at this point in the history
Reviewed-by: hannesw
  • Loading branch information
jonathan-gibbons committed Aug 2, 2024
1 parent f2e1205 commit 7deee74
Show file tree
Hide file tree
Showing 107 changed files with 1,377 additions and 1,395 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.SimpleTypeVisitor14;

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.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.markup.TagName;
import jdk.javadoc.internal.doclets.formats.html.markup.Text;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyles;
import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable;
import jdk.javadoc.internal.html.Content;
import jdk.javadoc.internal.html.ContentBuilder;
import jdk.javadoc.internal.html.Entity;
import jdk.javadoc.internal.html.HtmlTag;
import jdk.javadoc.internal.html.HtmlTree;
import jdk.javadoc.internal.html.Text;

import static jdk.javadoc.internal.doclets.formats.html.HtmlLinkInfo.Kind.LINK_TYPE_PARAMS;
import static jdk.javadoc.internal.doclets.formats.html.HtmlLinkInfo.Kind.LINK_TYPE_PARAMS_AND_BOUNDS;
Expand Down Expand Up @@ -108,7 +109,7 @@ protected Content getSummaryLink(Element member) {
}
String signature = utils.flatSignature((ExecutableElement) member, typeElement);
if (signature.length() > 2) {
content.add(new HtmlTree(TagName.WBR));
content.add(new HtmlTree(HtmlTag.WBR));
}
content.add(signature);

Expand All @@ -120,7 +121,7 @@ protected Content getSummaryLink(Element member) {
protected void addSummaryLink(HtmlLinkInfo.Kind context, TypeElement te, Element member,
Content target) {
ExecutableElement ee = (ExecutableElement)member;
Content memberLink = writer.getDocLink(context, te, ee, name(ee), HtmlStyle.memberNameLink);
Content memberLink = writer.getDocLink(context, te, ee, name(ee), HtmlStyles.memberNameLink);
var code = HtmlTree.CODE(memberLink);
addParameters(ee, code);
target.add(code);
Expand All @@ -143,7 +144,7 @@ protected void addTypeParameters(ExecutableElement member, Content target) {
// Add explicit line break between method type parameters and
// return type in member summary table to avoid random wrapping.
if (typeParameters.charCount() > 10) {
target.add(new HtmlTree(TagName.BR));
target.add(new HtmlTree(HtmlTag.BR));
} else {
target.add(Entity.NO_BREAK_SPACE);
}
Expand Down Expand Up @@ -232,7 +233,7 @@ protected void addParameters(ExecutableElement member, Content target) {
Content params = getParameters(member, false);
if (params.charCount() > 2) {
// only add <wbr> for non-empty parameters
target.add(new HtmlTree(TagName.WBR));
target.add(new HtmlTree(HtmlTag.WBR));
}
target.add(params);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@

import com.sun.source.doctree.DocTree;

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.HtmlStyle;
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.markup.HtmlStyles;
import jdk.javadoc.internal.doclets.toolkit.Resources;
import jdk.javadoc.internal.doclets.toolkit.util.DocFinder;
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable;
import jdk.javadoc.internal.html.Content;
import jdk.javadoc.internal.html.ContentBuilder;
import jdk.javadoc.internal.html.Entity;
import jdk.javadoc.internal.html.HtmlTag;
import jdk.javadoc.internal.html.HtmlTree;

import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.ANNOTATION_TYPE_MEMBER;
import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.ANNOTATION_TYPE_MEMBER_OPTIONAL;
Expand Down Expand Up @@ -450,7 +451,7 @@ protected abstract void addInheritedSummaryLink(TypeElement typeElement,
*/
protected void addModifiersAndType(Element member, TypeMirror type,
Content target) {
var code = new HtmlTree(TagName.CODE);
var code = new HtmlTree(HtmlTag.CODE);
addModifiers(member, code);
if (type == null) {
code.add(switch (member.getKind()) {
Expand Down Expand Up @@ -518,7 +519,7 @@ protected void addDeprecatedInfo(Element member, Content target) {
var t = configuration.tagletManager.getTaglet(DocTree.Kind.DEPRECATED);
Content output = t.getAllBlockTagOutput(member, writer.getTagletWriterInstance(false));
if (!output.isEmpty()) {
target.add(HtmlTree.DIV(HtmlStyle.deprecationBlock, output));
target.add(HtmlTree.DIV(HtmlStyles.deprecationBlock, output));
}
}

Expand Down Expand Up @@ -570,9 +571,9 @@ protected void addUseInfo(List<? extends Element> members, Content heading, Cont
return;
}
boolean printedUseTableHeader = false;
var useTable = new Table<Void>(HtmlStyle.summaryTable)
var useTable = new Table<Void>(HtmlStyles.summaryTable)
.setCaption(heading)
.setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colSecond, HtmlStyle.colLast);
.setColumnStyles(HtmlStyles.colFirst, HtmlStyles.colSecond, HtmlStyles.colLast);
for (Element element : members) {
TypeElement te = (typeElement == null)
? utils.getEnclosingTypeElement(element)
Expand All @@ -588,7 +589,7 @@ protected void addUseInfo(List<? extends Element> members, Content heading, Cont
&& !utils.isConstructor(element)
&& !utils.isTypeElement(element)) {

var name = HtmlTree.SPAN(HtmlStyle.typeNameLabel);
var name = HtmlTree.SPAN(HtmlStyles.typeNameLabel);
name.add(name(te) + ".");
typeContent.add(name);
}
Expand Down Expand Up @@ -669,7 +670,7 @@ public Content getInheritedSummaryHeader(TypeElement tElement) {
* @return the inherited summary links
*/
public Content getInheritedSummaryLinks() {
return new HtmlTree(TagName.CODE);
return new HtmlTree(HtmlTag.CODE);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@

package jdk.javadoc.internal.doclets.formats.html;

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.HtmlStyle;
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.BodyContents;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyles;
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
import jdk.javadoc.internal.html.Content;
import jdk.javadoc.internal.html.ContentBuilder;
import jdk.javadoc.internal.html.HtmlTree;
import jdk.javadoc.internal.html.RawHtml;

/**
* Abstract class to generate the top-level "overview" files.
Expand Down Expand Up @@ -135,8 +136,8 @@ protected void addConfigurationTitle(Content target) {
if (!doctitle.isEmpty()) {
var title = RawHtml.of(doctitle);
var heading = HtmlTree.HEADING(Headings.PAGE_TITLE_HEADING,
HtmlStyle.title, title);
var div = HtmlTree.DIV(HtmlStyle.header, heading);
HtmlStyles.title, title);
var div = HtmlTree.DIV(HtmlStyles.header, heading);
target.add(div);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@

package jdk.javadoc.internal.doclets.formats.html;

import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.markup.TagName;
import jdk.javadoc.internal.doclets.toolkit.util.ClassTree;
import jdk.javadoc.internal.doclets.toolkit.util.ClassTree.Hierarchy;
import jdk.javadoc.internal.doclets.toolkit.util.DocPath;

import javax.lang.model.element.TypeElement;
import java.util.Collection;
import java.util.SortedSet;
import java.util.TreeSet;

import javax.lang.model.element.TypeElement;

import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyles;
import jdk.javadoc.internal.doclets.toolkit.util.ClassTree;
import jdk.javadoc.internal.doclets.toolkit.util.ClassTree.Hierarchy;
import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
import jdk.javadoc.internal.html.Content;
import jdk.javadoc.internal.html.HtmlTag;
import jdk.javadoc.internal.html.HtmlTree;


/**
* Abstract class to print the class hierarchy page for all the Classes. This
Expand Down Expand Up @@ -77,10 +79,10 @@ protected AbstractTreeWriter(HtmlConfiguration configuration,
protected void addLevelInfo(TypeElement parent, Collection<TypeElement> collection,
Hierarchy hierarchy, Content content) {
if (!collection.isEmpty()) {
var ul = new HtmlTree(TagName.UL);
var ul = new HtmlTree(HtmlTag.UL);
for (TypeElement local : collection) {
var li = new HtmlTree(TagName.LI);
li.setStyle(HtmlStyle.circle);
var li = new HtmlTree(HtmlTag.LI);
li.setStyle(HtmlStyles.circle);
addPartialInfo(local, li);
addExtendsImplements(parent, local, li);
addLevelInfo(local, hierarchy.subtypes(local), hierarchy, li); // Recurse
Expand All @@ -104,7 +106,7 @@ protected void addTree(Hierarchy hierarchy, String heading, Content content) {
Content headingContent = contents.getContent(heading);
var sectionHeading = HtmlTree.HEADING_TITLE(Headings.CONTENT_HEADING,
headingContent);
var section = HtmlTree.SECTION(HtmlStyle.hierarchy, sectionHeading);
var section = HtmlTree.SECTION(HtmlStyles.hierarchy, sectionHeading);
addLevelInfo(!utils.isPlainInterface(firstTypeElement) ? firstTypeElement : null,
roots, hierarchy, section);
content.add(section);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@
import javax.lang.model.element.TypeElement;

import com.sun.source.doctree.DeprecatedTree;
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.HtmlStyle;
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.BodyContents;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyles;
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
import jdk.javadoc.internal.doclets.toolkit.util.Utils.ElementFlag;
import jdk.javadoc.internal.html.Content;
import jdk.javadoc.internal.html.ContentBuilder;
import jdk.javadoc.internal.html.HtmlTree;

/**
* Generate the file with list of all the classes in this run.
Expand Down Expand Up @@ -79,9 +81,9 @@ public void buildPage() throws DocFileIOException {
* @param target the content to which the links will be added
*/
protected void addContents(Content target) {
var table = new Table<TypeElement>(HtmlStyle.summaryTable)
var table = new Table<TypeElement>(HtmlStyles.summaryTable)
.setHeader(new TableHeader(contents.classLabel, contents.descriptionLabel))
.setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colLast)
.setColumnStyles(HtmlStyles.colFirst, HtmlStyles.colLast)
.setId(HtmlIds.ALL_CLASSES_TABLE)
.setDefaultTab(contents.allClassesAndInterfacesLabel)
.addTab(contents.interfaces, utils::isPlainInterface)
Expand All @@ -96,8 +98,8 @@ protected void addContents(Content target) {
}
Content titleContent = contents.allClassesAndInterfacesLabel;
var pHeading = HtmlTree.HEADING_TITLE(Headings.PAGE_TITLE_HEADING,
HtmlStyle.title, titleContent);
var headerDiv = HtmlTree.DIV(HtmlStyle.header, pHeading);
HtmlStyles.title, titleContent);
var headerDiv = HtmlTree.DIV(HtmlStyles.header, pHeading);
target.add(headerDiv);
if (!table.isEmpty()) {
target.add(table);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@

import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode;
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.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.markup.Text;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyles;
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
import jdk.javadoc.internal.html.Content;
import jdk.javadoc.internal.html.ContentBuilder;
import jdk.javadoc.internal.html.HtmlTree;
import jdk.javadoc.internal.html.Text;

/**
* Generate the file with list of all the packages in this run.
Expand All @@ -60,8 +61,8 @@ public void buildPage() throws DocFileIOException {
addPackages(mainContent);
Content titleContent = contents.allPackagesLabel;
var pHeading = HtmlTree.HEADING_TITLE(Headings.PAGE_TITLE_HEADING,
HtmlStyle.title, titleContent);
var headerDiv = HtmlTree.DIV(HtmlStyle.header, pHeading);
HtmlStyles.title, titleContent);
var headerDiv = HtmlTree.DIV(HtmlStyles.header, pHeading);
HtmlTree body = getBody(getWindowTitle(label));
body.add(new BodyContents()
.setHeader(getHeader(PageMode.ALL_PACKAGES))
Expand All @@ -77,10 +78,10 @@ public void buildPage() throws DocFileIOException {
* @param target the content to which the links will be added
*/
protected void addPackages(Content target) {
var table = new Table<PackageElement>(HtmlStyle.summaryTable)
var table = new Table<PackageElement>(HtmlStyles.summaryTable)
.setCaption(Text.of(contents.packageSummaryLabel.toString()))
.setHeader(new TableHeader(contents.packageLabel, contents.descriptionLabel))
.setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colLast);
.setColumnStyles(HtmlStyles.colFirst, HtmlStyles.colLast);
for (PackageElement pkg : configuration.packages) {
if (!(options.noDeprecated() && utils.isDeprecated(pkg))) {
Content packageLinkContent = getPackageLink(pkg, getLocalizedPackageName(pkg));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeMirror;

import jdk.javadoc.internal.doclets.formats.html.markup.Comment;
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.markup.Text;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyles;
import jdk.javadoc.internal.doclets.toolkit.BaseOptions;
import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable;
import jdk.javadoc.internal.html.Comment;
import jdk.javadoc.internal.html.Content;
import jdk.javadoc.internal.html.ContentBuilder;
import jdk.javadoc.internal.html.HtmlTree;
import jdk.javadoc.internal.html.Text;


/**
Expand Down Expand Up @@ -96,7 +97,7 @@ protected void buildAnnotationTypeMember(Content target) {
for (Element member : members) {
currentMember = member;
Content annotationContent = getAnnotationHeaderContent(currentMember);
Content div = HtmlTree.DIV(HtmlStyle.horizontalScroll);
Content div = HtmlTree.DIV(HtmlStyles.horizontalScroll);
buildAnnotationTypeMemberChildren(div);
annotationContent.add(div);
memberList.add(writer.getMemberListItem(annotationContent));
Expand Down Expand Up @@ -181,7 +182,7 @@ public Content getMemberSummaryHeader(Content content) {

@Override
public void buildSummary(Content summariesList, Content content) {
writer.addSummary(HtmlStyle.memberSummary,
writer.addSummary(HtmlStyles.memberSummary,
switch (kind) {
case ANNOTATION_TYPE_MEMBER_REQUIRED -> HtmlIds.ANNOTATION_TYPE_REQUIRED_ELEMENT_SUMMARY;
case ANNOTATION_TYPE_MEMBER_OPTIONAL -> HtmlIds.ANNOTATION_TYPE_OPTIONAL_ELEMENT_SUMMARY;
Expand Down Expand Up @@ -209,7 +210,7 @@ protected Content getAnnotationHeaderContent(Element member) {
var heading = HtmlTree.HEADING(Headings.TypeDeclaration.MEMBER_HEADING,
Text.of(name(member)));
content.add(heading);
return HtmlTree.SECTION(HtmlStyle.detail, content)
return HtmlTree.SECTION(HtmlStyles.detail, content)
.setId(htmlIds.forMember((ExecutableElement) member).getFirst());
}

Expand Down Expand Up @@ -238,7 +239,7 @@ protected void addTags(Element member, Content annotationContent) {

protected Content getAnnotationDetails(Content annotationDetailsHeader, Content annotationDetails) {
Content c = new ContentBuilder(annotationDetailsHeader, annotationDetails);
return getMember(HtmlTree.SECTION(HtmlStyle.memberDetails, c));
return getMember(HtmlTree.SECTION(HtmlStyles.memberDetails, c));
}

@Override
Expand Down Expand Up @@ -278,10 +279,10 @@ public TableHeader getSummaryTableHeader(Element member) {

@Override
protected Table<Element> createSummaryTable() {
return new Table<Element>(HtmlStyle.summaryTable)
return new Table<Element>(HtmlStyles.summaryTable)
.setCaption(getCaption())
.setHeader(getSummaryTableHeader(typeElement))
.setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colSecond, HtmlStyle.colLast);
.setColumnStyles(HtmlStyles.colFirst, HtmlStyles.colSecond, HtmlStyles.colLast);
}

@Override
Expand All @@ -292,7 +293,7 @@ public void addInheritedSummaryLabel(TypeElement typeElement, Content content) {
protected void addSummaryLink(HtmlLinkInfo.Kind context, TypeElement typeElement, Element member,
Content content) {
Content memberLink = writer.getDocLink(context, utils.getEnclosingTypeElement(member), member,
name(member), HtmlStyle.memberNameLink);
name(member), HtmlStyles.memberNameLink);
var code = HtmlTree.CODE(memberLink);
content.add(code);
}
Expand Down Expand Up @@ -331,7 +332,7 @@ protected void addDefaultValueInfo(Element member, Content annotationContent) {
ExecutableElement ee = (ExecutableElement) member;
AnnotationValue value = ee.getDefaultValue();
if (value != null) {
var dl = HtmlTree.DL(HtmlStyle.notes);
var dl = HtmlTree.DL(HtmlStyles.notes);
dl.add(HtmlTree.DT(contents.default_));
dl.add(HtmlTree.DD(HtmlTree.CODE(Text.of(value.toString()))));
annotationContent.add(dl);
Expand Down
Loading

0 comments on commit 7deee74

Please sign in to comment.