package jdk.javadoc.internal.doclets.formats.html;
import jdk.javadoc.internal.doclets.formats.html.markup.Table;
import jdk.javadoc.internal.doclets.formats.html.markup.TableHeader;
import java.util.*;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.markup.Links;
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
import jdk.javadoc.internal.doclets.toolkit.ConstantsSummaryWriter;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
import jdk.javadoc.internal.doclets.toolkit.util.DocLink;
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
public class ConstantsSummaryWriterImpl extends HtmlDocletWriter implements ConstantsSummaryWriter {
HtmlConfiguration configuration;
private TypeElement currentTypeElement;
private final String constantsTableSummary;
private final TableHeader ;
private final HtmlTree mainTree = HtmlTree.MAIN();
private HtmlTree summaryTree;
public ConstantsSummaryWriterImpl(HtmlConfiguration configuration) {
super(configuration, DocPaths.CONSTANT_VALUES);
this.configuration = configuration;
constantsTableSummary = configuration.getText("doclet.Constants_Table_Summary",
configuration.getText("doclet.Constants_Summary"));
constantsTableHeader = new TableHeader(
contents.modifierAndTypeLabel, contents.constantFieldLabel, contents.valueLabel);
}
@Override
public Content () {
String label = configuration.getText("doclet.Constants_Summary");
HtmlTree bodyTree = getBody(true, getWindowTitle(label));
HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER))
? HtmlTree.HEADER()
: bodyTree;
addTop(htmlTree);
addNavLinks(true, htmlTree);
if (configuration.allowTag(HtmlTag.HEADER)) {
bodyTree.addContent(htmlTree);
}
return bodyTree;
}
@Override
public Content () {
return new HtmlTree(HtmlTag.UL);
}
@Override
public void addLinkToPackageContent(PackageElement pkg,
Set<PackageElement> printedPackageHeaders, Content contentListTree) {
Content link;
if (pkg.isUnnamed()) {
link = Links.createLink(SectionName.UNNAMED_PACKAGE_ANCHOR,
contents.defaultPackageLabel, "", "");
} else {
String parsedPackageName = utils.parsePackageName(pkg);
Content packageNameContent = getPackageLabel(parsedPackageName);
packageNameContent.addContent(".*");
link = Links.createLink(DocLink.fragment(parsedPackageName),
packageNameContent, "", "");
PackageElement abbrevPkg = configuration.workArounds.getAbbreviatedPackageElement(pkg);
printedPackageHeaders.add(abbrevPkg);
}
contentListTree.addContent(HtmlTree.LI(link));
}
@Override
public void addContentsList(Content contentTree, Content contentListTree) {
Content titleContent = contents.constantsSummaryTitle;
Content pHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
HtmlStyle.title, titleContent);
Content div = HtmlTree.DIV(HtmlStyle.header, pHeading);
Content headingContent = contents.contentsHeading;
Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true,
headingContent);
if (configuration.allowTag(HtmlTag.SECTION)) {
HtmlTree section = HtmlTree.SECTION(heading);
section.addContent(contentListTree);
div.addContent(section);
mainTree.addContent(div);
} else {
div.addContent(heading);
div.addContent(contentListTree);
contentTree.addContent(div);
}
}
@Override
public Content getConstantSummaries() {
HtmlTree summariesDiv = new HtmlTree(HtmlTag.DIV);
summariesDiv.setStyle(HtmlStyle.constantValuesContainer);
return summariesDiv;
}
@Override
public void addPackageName(PackageElement pkg, Content summariesTree, boolean first) {
Content pkgNameContent;
if (!first && configuration.allowTag(HtmlTag.SECTION)) {
summariesTree.addContent(summaryTree);
}
if (pkg.isUnnamed()) {
summariesTree.addContent(links.createAnchor(SectionName.UNNAMED_PACKAGE_ANCHOR));
pkgNameContent = contents.defaultPackageLabel;
} else {
String parsedPackageName = utils.parsePackageName(pkg);
summariesTree.addContent(links.createAnchor(parsedPackageName));
pkgNameContent = getPackageLabel(parsedPackageName);
}
Content headingContent = new StringContent(".*");
Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true,
pkgNameContent);
heading.addContent(headingContent);
if (configuration.allowTag(HtmlTag.SECTION)) {
summaryTree = HtmlTree.SECTION(heading);
} else {
summariesTree.addContent(heading);
}
}
@Override
public Content () {
HtmlTree ul = new HtmlTree(HtmlTag.UL);
ul.setStyle(HtmlStyle.blockList);
return ul;
}
@Override
public void addClassConstant(Content summariesTree, Content classConstantTree) {
if (configuration.allowTag(HtmlTag.SECTION)) {
summaryTree.addContent(classConstantTree);
} else {
summariesTree.addContent(classConstantTree);
}
}
@Override
public void addConstantMembers(TypeElement typeElement, Collection<VariableElement> fields,
Content classConstantTree) {
currentTypeElement = typeElement;
Content classlink = (utils.isPublic(typeElement) || utils.isProtected(typeElement)) ?
getLink(new LinkInfoImpl(configuration,
LinkInfoImpl.Kind.CONSTANT_SUMMARY, typeElement)) :
new StringContent(utils.getFullyQualifiedName(typeElement));
PackageElement enclosingPackage = utils.containingPackage(typeElement);
Content caption = new ContentBuilder();
if (!enclosingPackage.isUnnamed()) {
caption.addContent(enclosingPackage.getQualifiedName());
caption.addContent(".");
}
caption.addContent(classlink);
Table table = new Table(configuration.htmlVersion, HtmlStyle.constantsSummary)
.setSummary(constantsTableSummary)
.setCaption(caption)
.setHeader(constantsTableHeader)
.setRowScopeColumn(1)
.setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colSecond, HtmlStyle.colLast);
for (VariableElement field : fields) {
table.addRow(getTypeColumn(field), getNameColumn(field), getValue(field));
}
Content li = HtmlTree.LI(HtmlStyle.blockList, table.toContent());
classConstantTree.addContent(li);
}
private Content getTypeColumn(VariableElement member) {
Content anchor = links.createAnchor(
currentTypeElement.getQualifiedName() + "." + member.getSimpleName());
Content typeContent = new ContentBuilder();
typeContent.addContent(anchor);
Content code = new HtmlTree(HtmlTag.CODE);
for (Modifier mod : member.getModifiers()) {
Content modifier = new StringContent(mod.toString());
code.addContent(modifier);
code.addContent(Contents.SPACE);
}
Content type = getLink(new LinkInfoImpl(configuration,
LinkInfoImpl.Kind.CONSTANT_SUMMARY, member.asType()));
code.addContent(type);
typeContent.addContent(code);
return typeContent;
}
private Content getNameColumn(VariableElement member) {
Content nameContent = getDocLink(LinkInfoImpl.Kind.CONSTANT_SUMMARY,
member, member.getSimpleName(), false);
return HtmlTree.CODE(nameContent);
}
private Content getValue(VariableElement member) {
String value = utils.constantValueExpresion(member);
Content valueContent = new StringContent(value);
return HtmlTree.CODE(valueContent);
}
@Override
public void addConstantSummaries(Content contentTree, Content summariesTree) {
if (configuration.allowTag(HtmlTag.SECTION) && summaryTree != null) {
summariesTree.addContent(summaryTree);
}
if (configuration.allowTag(HtmlTag.MAIN)) {
mainTree.addContent(summariesTree);
contentTree.addContent(mainTree);
} else {
contentTree.addContent(summariesTree);
}
}
@Override
public void (Content contentTree) {
Content htmlTree = (configuration.allowTag(HtmlTag.FOOTER))
? HtmlTree.FOOTER()
: contentTree;
addNavLinks(false, htmlTree);
addBottom(htmlTree);
if (configuration.allowTag(HtmlTag.FOOTER)) {
contentTree.addContent(htmlTree);
}
}
@Override
public void printDocument(Content contentTree) throws DocFileIOException {
printHtmlDocument(null, true, contentTree);
}
}