Skip to content

Commit

Permalink
JDK-8338133: Cleanup direct use of new HtmlTree
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-gibbons committed Aug 29, 2024
1 parent 777ed2b commit 2245c72
Show file tree
Hide file tree
Showing 28 changed files with 286 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected Content getSummaryLink(Element member) {
}
String signature = utils.flatSignature((ExecutableElement) member, typeElement);
if (signature.length() > 2) {
content.add(new HtmlTree(HtmlTag.WBR));
content.add(HtmlTree.WBR());
}
content.add(signature);

Expand Down Expand Up @@ -144,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(HtmlTag.BR));
target.add(HtmlTree.BR());
} else {
target.add(Entity.NO_BREAK_SPACE);
}
Expand Down Expand Up @@ -233,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(HtmlTag.WBR));
target.add(HtmlTree.WBR());
}
target.add(params);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ protected abstract void addInheritedSummaryLink(TypeElement typeElement,
*/
protected void addModifiersAndType(Element member, TypeMirror type,
Content target) {
var code = new HtmlTree(HtmlTag.CODE);
var code = HtmlTree.CODE();
addModifiers(member, code);
if (type == null) {
code.add(switch (member.getKind()) {
Expand Down Expand Up @@ -670,7 +670,7 @@ public Content getInheritedSummaryHeader(TypeElement tElement) {
* @return the inherited summary links
*/
public Content getInheritedSummaryLinks() {
return new HtmlTree(HtmlTag.CODE);
return HtmlTree.CODE();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ protected AbstractTreeWriter(HtmlConfiguration configuration,
protected void addLevelInfo(TypeElement parent, Collection<TypeElement> collection,
Hierarchy hierarchy, Content content) {
if (!collection.isEmpty()) {
var ul = new HtmlTree(HtmlTag.UL);
var ul = HtmlTree.UL();
for (TypeElement local : collection) {
var li = new HtmlTree(HtmlTag.LI);
li.setStyle(HtmlStyles.circle);
var li = HtmlTree.LI(HtmlStyles.circle);
addPartialInfo(local, li);
addExtendsImplements(parent, local, li);
addLevelInfo(local, hierarchy.subtypes(local), hierarchy, li); // Recurse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ protected HtmlTree getClassUseHeader() {
HtmlTree body = getBody(getWindowTitle(title));
ContentBuilder headingContent = new ContentBuilder();
headingContent.add(contents.getContent("doclet.ClassUse_Title", cltype));
headingContent.add(new HtmlTree(HtmlTag.BR));
headingContent.add(HtmlTree.BR());
headingContent.add(clname);
var heading = HtmlTree.HEADING_TITLE(Headings.PAGE_TITLE_HEADING,
HtmlStyles.title, headingContent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ protected void buildClassInfo(Content target) {
buildInterfaceUsageInfo(c);
buildNestedClassInfo(c);
buildFunctionalInterfaceInfo(c);
c.add(new HtmlTree(HtmlTag.HR));
c.add(HtmlTree.HR());
var div = HtmlTree.DIV(HtmlStyles.horizontalScroll);
buildClassSignature(div);
buildDeprecationInfo(div);
Expand Down Expand Up @@ -461,7 +461,7 @@ private Content getTypeParameters() {
var first = true;
for (TypeParameterElement t : typeParams) {
if (!first) {
content.add(",").add(new HtmlTree(HtmlTag.WBR));
content.add(",").add(HtmlTree.WBR());
}
var typeParamLink = getLink(linkInfo.forType(t.asType()));
content.add(needsId
Expand Down Expand Up @@ -689,11 +689,9 @@ public Void visitType(TypeElement e, Void p) {

protected void addFunctionalInterfaceInfo (Content target) {
if (utils.isFunctionalInterface(typeElement)) {
var dl = HtmlTree.DL(HtmlStyles.notes);
dl.add(HtmlTree.DT(contents.functionalInterface));
var dd = new HtmlTree(HtmlTag.DD);
dd.add(contents.functionalInterfaceMessage);
dl.add(dd);
var dl = HtmlTree.DL(HtmlStyles.notes)
.add(HtmlTree.DT(contents.functionalInterface))
.add(HtmlTree.DD(contents.functionalInterfaceMessage));
target.add(dl);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ void addConstantMembers(TypeElement typeElement, Collection<VariableElement> fie
*/
private Content getTypeColumn(VariableElement member) {
Content typeContent = new ContentBuilder();
var code = new HtmlTree(HtmlTag.CODE)
var code = HtmlTree.CODE()
.setId(htmlIds.forMember(currentTypeElement, member));
for (Modifier mod : member.getModifiers()) {
code.add(Text.of(mod.toString()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public void addInheritedSummaryLabel(TypeElement typeElement, Content content) {
@Override
protected void addSummaryType(Element member, Content content) {
if (threeColumnSummary()) {
var code = new HtmlTree(HtmlTag.CODE);
var code = HtmlTree.CODE();
if (utils.isProtected(member)) {
code.add("protected ");
} else if (utils.isPrivate(member)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ protected void addHelpFileContents(Content content) {
tableOfContents.addLink(HtmlIds.TOP_OF_PAGE, mainHeading);
tableOfContents.pushNestedList();
content.add(HtmlTree.HEADING(Headings.PAGE_TITLE_HEADING, HtmlStyles.title, mainHeading))
.add(new HtmlTree(HtmlTag.HR))
.add(HtmlTree.HR())
.add(getNavigationSection())
.add(new HtmlTree(HtmlTag.HR))
.add(HtmlTree.HR())
.add(getPageKindSection())
.add(new HtmlTree(HtmlTag.HR))
.add(HtmlTree.HR())
.add(HtmlTree.SPAN(HtmlStyles.helpFootnote,
getContent("doclet.help.footnote")));
tableOfContents.popNestedList();
Expand Down Expand Up @@ -255,7 +255,7 @@ private Content getPageKindSection() {
getContent("doclet.help.class_interface.implementations"),
getContent("doclet.help.class_interface.declaration"),
getContent("doclet.help.class_interface.description")))
.add(new HtmlTree(HtmlTag.BR))
.add(HtmlTree.BR())
.add(newHelpSectionList(
contents.nestedClassSummary,
contents.enumConstantSummary,
Expand All @@ -265,7 +265,7 @@ private Content getPageKindSection() {
contents.methodSummary,
contents.annotateTypeRequiredMemberSummaryLabel,
contents.annotateTypeOptionalMemberSummaryLabel))
.add(new HtmlTree(HtmlTag.BR))
.add(HtmlTree.BR())
.add(newHelpSectionList(
contents.enumConstantDetailLabel,
contents.fieldDetailsLabel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ public HtmlTree getFooter() {
return (bottom == null || bottom.isEmpty())
? null
: HtmlTree.FOOTER()
.add(new HtmlTree(HtmlTag.HR))
.add(HtmlTree.HR())
.add(HtmlTree.P(HtmlStyles.legalCopy,
HtmlTree.SMALL(
RawHtml.of(replaceDocRootDir(bottom)))));
Expand Down Expand Up @@ -2405,7 +2405,7 @@ static String getGenerator(Class<?> clazz) {
* @return an HtmlTree for the BODY tag
*/
public HtmlTree getBody(String title) {
var body = new HtmlTree(HtmlTag.BODY).setStyle(getBodyStyle());
var body = HtmlTree.BODY(getBodyStyle());

this.winTitle = title;
// Don't print windowtitle script for overview-frame, allclasses-frame
Expand Down Expand Up @@ -2601,7 +2601,7 @@ private Content withPreviewFeatures(String key, String className, String feature
});
return contents.getContent(key,
HtmlTree.CODE(Text.of(className)),
new HtmlTree(HtmlTag.EM).add(featureName),
HtmlTree.EM(featureName),
featureCodes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,14 @@ protected Content getTypeParameterLinks(HtmlLinkInfo linkInfo) {
}
if (!vars.isEmpty()) {
if (linkInfo.addLineBreakOpportunitiesInTypeParameters()) {
links.add(new HtmlTree(HtmlTag.WBR));
links.add(HtmlTree.WBR());
}
links.add("<");
boolean many = false;
for (TypeMirror t : vars) {
if (many) {
links.add(",");
links.add(new HtmlTree(HtmlTag.WBR));
links.add(HtmlTree.WBR());
if (linkInfo.addLineBreaksInTypeParameters()) {
links.add(Text.NL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void buildPage() throws DocFileIOException {
Script script = new Script("window.location.replace(")
.appendStringLiteral(targetPath, '\'')
.append(")");
var metaRefresh = new HtmlTree(HtmlTag.META)
var metaRefresh = HtmlTree.of(HtmlTag.META)
.put(HtmlAttr.HTTP_EQUIV, "Refresh")
.put(HtmlAttr.CONTENT, "0;" + targetPath);
head.addContent(script.asContent(), HtmlTree.NOSCRIPT(metaRefresh));
Expand All @@ -103,9 +103,8 @@ public void buildPage() throws DocFileIOException {

bodyContent.add(HtmlTree.P(HtmlTree.A(targetPath, Text.of(targetPath))));

var body = new HtmlTree(HtmlTag.BODY).setStyle(HtmlStyles.indexRedirectPage);
var main = HtmlTree.MAIN(bodyContent);
body.add(main);
var body = HtmlTree.BODY(HtmlStyles.indexRedirectPage)
.add(bodyContent);

HtmlDocument htmlDocument = new HtmlDocument(
HtmlTree.HTML(configuration.getLocale().getLanguage(), head, body));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ protected void addElementDescription(IndexItem item, Content target) {
default -> throw new Error();
}
target.add(dt);
var dd = new HtmlTree(HtmlTag.DD);
var dd = HtmlTree.DD();
if (element.getKind() == ElementKind.MODULE || element.getKind() == ElementKind.PACKAGE) {
addSummaryComment(element, dd);
} else {
Expand Down Expand Up @@ -261,7 +261,7 @@ protected void addTagDescription(IndexItem item, Content target) {
dt.add(" - ");
dt.add(contents.getContent("doclet.Search_tag_in", item.getHolder()));
target.add(dt);
var dd = new HtmlTree(HtmlTag.DD);
var dd = HtmlTree.DD();
if (item.getDescription().isEmpty()) {
dd.add(Entity.NO_BREAK_SPACE);
} else {
Expand Down Expand Up @@ -348,7 +348,7 @@ protected void addLinksForIndexes(List<Character> allFirstCharacters, Content co
content.add(Entity.NO_BREAK_SPACE);
}

content.add(new HtmlTree(HtmlTag.BR));
content.add(HtmlTree.BR());
var pageLinks = Stream.of(IndexItem.Category.values())
.flatMap(c -> mainIndex.getItems(c).stream())
.filter(i -> !(i.isElementItem() || i.isTagItem()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ protected void buildModuleDoc() throws DocletException {
*/
protected void buildContent() {
Content moduleContent = getContentHeader();
moduleContent.add(new HtmlTree(HtmlTag.HR));
moduleContent.add(HtmlTree.HR());
Content div = HtmlTree.DIV(HtmlStyles.horizontalScroll);
addModuleSignature(div);
buildModuleDescription(div);
Expand Down Expand Up @@ -825,7 +825,7 @@ public void addProvidesList(Table<?> table) {
}
// Only display the implementation details in the "all" mode.
if (moduleMode == ModuleMode.ALL && !implSet.isEmpty()) {
desc.add(new HtmlTree(HtmlTag.BR));
desc.add(HtmlTree.BR());
desc.add("(");
var implSpan = HtmlTree.SPAN(HtmlStyles.implementationLabel, contents.implementation);
desc.add(implSpan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,14 @@ public Content getContent() {
}
var navigationBar = HtmlTree.NAV();

var navContent = new HtmlTree(HtmlTag.DIV);
var navContent = HtmlTree.DIV(HtmlStyles.navContent);
Content skipNavLinks = contents.getContent("doclet.Skip_navigation_links");
String toggleNavLinks = configuration.getDocResources().getText("doclet.Toggle_navigation_links");
navigationBar.add(MarkerComments.START_OF_TOP_NAVBAR);
// The mobile menu button uses three empty spans to produce its animated icon
HtmlTree iconSpan = HtmlTree.SPAN(HtmlStyles.navBarToggleIcon).add(Entity.NO_BREAK_SPACE);
navContent.setStyle(HtmlStyles.navContent).add(HtmlTree.DIV(HtmlStyles.navMenuButton,
new HtmlTree(HtmlTag.BUTTON).setId(HtmlIds.NAVBAR_TOGGLE_BUTTON)
navContent.add(HtmlTree.DIV(HtmlStyles.navMenuButton,
HtmlTree.BUTTON(HtmlIds.NAVBAR_TOGGLE_BUTTON)
.put(HtmlAttr.ARIA_CONTROLS, HtmlIds.NAVBAR_TOP.name())
.put(HtmlAttr.ARIA_EXPANDED, String.valueOf(false))
.put(HtmlAttr.ARIA_LABEL, toggleNavLinks)
Expand All @@ -535,9 +535,7 @@ public Content getContent() {
skipNavLinks.toString())));
Content aboutContent = userHeader;

var navList = new HtmlTree(HtmlTag.UL)
.setId(HtmlIds.NAVBAR_TOP_FIRSTROW)
.setStyle(HtmlStyles.navList)
var navList = HtmlTree.UL(HtmlIds.NAVBAR_TOP_FIRSTROW, HtmlStyles.navList)
.put(HtmlAttr.TITLE, rowListTitle);
addMainNavLinks(navList);
navContent.add(navList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private HtmlTree getBody() {
HtmlTree body = getBody(getWindowTitle(title));
ContentBuilder headingContent = new ContentBuilder();
headingContent.add(contents.getContent("doclet.ClassUse_Title", packageText));
headingContent.add(new HtmlTree(HtmlTag.BR));
headingContent.add(HtmlTree.BR());
headingContent.add(name);
var heading = HtmlTree.HEADING_TITLE(Headings.PAGE_TITLE_HEADING,
HtmlStyles.title, headingContent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected void buildPackageDoc() throws DocletException {
*/
protected void buildContent() {
Content packageContent = getContentHeader();
packageContent.add(new HtmlTree(HtmlTag.HR));
packageContent.add(HtmlTree.HR());
Content div = HtmlTree.DIV(HtmlStyles.horizontalScroll);
addPackageSignature(div);
buildPackageDescription(div);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,22 @@ protected void addSearchFileContents(Content contentTree) {
.add(HtmlTree.P(contents.getContent("doclet.search.browser_info")))
.add(HtmlTree.SPAN(Text.of("link"))
.setId(HtmlId.of("page-search-link")))
.add(new HtmlTree(HtmlTag.BUTTON)
.add(new HtmlTree(HtmlTag.IMG)
.add(HtmlTree.BUTTON(HtmlId.of("page-search-copy"))
.add(HtmlTree.of(HtmlTag.IMG)
.put(HtmlAttr.SRC, pathToRoot.resolve(DocPaths.RESOURCE_FILES)
.resolve(DocPaths.CLIPBOARD_SVG).getPath())
.put(HtmlAttr.ALT, copyUrlText))
.add(HtmlTree.SPAN(Text.of(copyText))
.put(HtmlAttr.DATA_COPIED, copiedText))
.addStyle(HtmlStyles.copy)
.put(HtmlAttr.ARIA_LABEL, copyUrlText)
.setId(HtmlId.of("page-search-copy")))
.put(HtmlAttr.ARIA_LABEL, copyUrlText))
.add(HtmlTree.P(HtmlTree.INPUT(HtmlAttr.InputType.CHECKBOX, HtmlId.of("search-redirect")))
.add(HtmlTree.LABEL("search-redirect",
contents.getContent("doclet.search.redirect")))))
.add(new HtmlTree(HtmlTag.P)
.add(HtmlTree.of(HtmlTag.P)
.setId(HtmlId.of("page-search-notify"))
.add(contents.getContent("doclet.search.loading")))
.add(HtmlTree.DIV(new HtmlTree(HtmlTag.DIV)
.setId(HtmlId.of("result-container"))
.add(HtmlTree.DIV(HtmlTree.DIV(HtmlId.of("result-container"))
.addUnchecked(Text.EMPTY))
.setId(HtmlId.of("result-section"))
.put(HtmlAttr.STYLE, "display: none;")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected Content getSerializableFieldsHeader() {
}

protected Content getFieldsContentHeader() {
return new HtmlTree(HtmlTag.LI).setStyle(HtmlStyles.blockList);
return HtmlTree.LI(HtmlStyles.blockList);
}

protected Content getSerializableFields(String heading, Content source) {
Expand All @@ -76,12 +76,12 @@ protected void addMemberHeader(TypeMirror fieldType, String fieldName, Content c
Content nameContent = Text.of(fieldName);
var heading = HtmlTree.HEADING(Headings.SerializedForm.MEMBER_HEADING, nameContent);
content.add(heading);
var pre = new HtmlTree(HtmlTag.PRE);
Content fieldContent = writer.getLink(new HtmlLinkInfo(
configuration, HtmlLinkInfo.Kind.LINK_TYPE_PARAMS_AND_BOUNDS, fieldType));
pre.add(fieldContent);
pre.add(" ");
pre.add(fieldName);
var pre = HtmlTree.PRE()
.add(fieldContent)
.add(" ")
.add(fieldName);
content.add(pre);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected Content getSerializableMethodsHeader() {
}

protected Content getMethodsContentHeader() {
return new HtmlTree(HtmlTag.LI);
return HtmlTree.LI();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ private void appendParametersAndExceptions(Content target, int lastLineSeparator
// empty parameters are added without packing
target.add(parameters);
} else {
target.add(new HtmlTree(HtmlTag.WBR))
target.add(HtmlTree.WBR())
.add(HtmlTree.SPAN(HtmlStyles.parameters, parameters));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void convertClass(TypeElement te, DocPath outputdir)
.resolve(configuration.docPaths.forPackage(te))
.invert();
Content body = getHeader();
var pre = new HtmlTree(HtmlTag.PRE);
var pre = HtmlTree.PRE();
try (var reader = new LineNumberReader(r)) {
while ((line = reader.readLine()) != null) {
addLineNo(pre, lineno);
Expand Down Expand Up @@ -246,7 +246,7 @@ private void writeToFile(Content body, DocPath path, TypeElement te) throws DocF
* @return the header content for the HTML file
*/
private static Content getHeader() {
return new HtmlTree(HtmlTag.BODY).setStyle(HtmlStyles.sourcePage);
return HtmlTree.BODY(HtmlStyles.sourcePage);
}

/**
Expand Down
Loading

0 comments on commit 2245c72

Please sign in to comment.