package jdk.javadoc.internal.doclets.formats.html;
import java.util.ArrayList;
import java.util.List;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import com.sun.source.doctree.DocTree;
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.HtmlTag;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.markup.Navigation;
import jdk.javadoc.internal.doclets.formats.html.markup.Navigation.PageMode;
import jdk.javadoc.internal.doclets.formats.html.markup.Table;
import jdk.javadoc.internal.doclets.formats.html.markup.TableHeader;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
import jdk.javadoc.internal.doclets.toolkit.util.IndexBuilder;
public class AllClassesIndexWriter extends HtmlDocletWriter {
protected IndexBuilder indexbuilder;
protected HtmlTree mainTree = HtmlTree.MAIN();
private final Navigation navBar;
public AllClassesIndexWriter(HtmlConfiguration configuration,
DocPath filename, IndexBuilder indexbuilder) {
super(configuration, filename);
this.indexbuilder = indexbuilder;
this.navBar = new Navigation(null, configuration, fixedNavDiv, PageMode.ALLCLASSES, path);
}
public static void generate(HtmlConfiguration configuration,
IndexBuilder indexBuilder) throws DocFileIOException {
generate(configuration, indexBuilder, DocPaths.ALLCLASSES_INDEX);
}
private static void generate(HtmlConfiguration configuration, IndexBuilder indexBuilder,
DocPath fileName) throws DocFileIOException {
AllClassesIndexWriter allClassGen = new AllClassesIndexWriter(configuration,
fileName, indexBuilder);
allClassGen.buildAllClassesFile();
}
protected void buildAllClassesFile() throws DocFileIOException {
String label = resources.getText("doclet.All_Classes");
HtmlTree bodyTree = getBody(getWindowTitle(label));
HtmlTree header = HtmlTree.HEADER();
addTop(header);
navBar.setUserHeader(getUserHeaderFooter(true));
header.add(navBar.getContent(true));
bodyTree.add(header);
Content allClassesContent = new ContentBuilder();
addContents(allClassesContent);
mainTree.add(allClassesContent);
bodyTree.add(mainTree);
Content footer = HtmlTree.FOOTER();
navBar.setUserFooter(getUserHeaderFooter(false));
footer.add(navBar.getContent(false));
addBottom(footer);
bodyTree.add(footer);
printHtmlDocument(null, "class index", bodyTree);
}
protected void addContents(Content content) {
Table table = new Table(HtmlStyle.typeSummary)
.setHeader(new TableHeader(contents.classLabel, contents.descriptionLabel))
.setRowScopeColumn(1)
.setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colLast)
.setDefaultTab(resources.getText("doclet.All_Classes"))
.addTab(resources.interfaceSummary, utils::isInterface)
.addTab(resources.classSummary, e -> utils.isOrdinaryClass((TypeElement)e))
.addTab(resources.enumSummary, utils::isEnum)
.addTab(resources.exceptionSummary, e -> utils.isException((TypeElement)e))
.addTab(resources.errorSummary, e -> utils.isError((TypeElement)e))
.addTab(resources.annotationTypeSummary, utils::isAnnotationType)
.setTabScript(i -> "show(" + i + ");");
for (Character unicode : indexbuilder.index()) {
for (Element element : indexbuilder.getMemberList(unicode)) {
TypeElement typeElement = (TypeElement) element;
if (!utils.isCoreClass(typeElement)) {
continue;
}
addTableRow(table, typeElement);
}
}
Content titleContent = contents.allClassesLabel;
Content pHeading = HtmlTree.HEADING(Headings.PAGE_TITLE_HEADING, true,
HtmlStyle.title, titleContent);
Content headerDiv = HtmlTree.DIV(HtmlStyle.header, pHeading);
content.add(headerDiv);
if (!table.isEmpty()) {
HtmlTree div = new HtmlTree(HtmlTag.DIV, table.toContent());
div.setStyle(HtmlStyle.allClassesContainer);
content.add(div);
if (table.needsScript()) {
getMainBodyScript().append(table.getScript());
}
}
}
protected void addTableRow(Table table, TypeElement klass) {
List<Content> rowContents = new ArrayList<>();
Content classLink = getLink(new LinkInfoImpl(
configuration, LinkInfoImpl.Kind.INDEX, klass));
ContentBuilder description = new ContentBuilder();
if (utils.isDeprecated(klass)) {
description.add(getDeprecatedPhrase(klass));
List<? extends DocTree> tags = utils.getDeprecatedTrees(klass);
if (!tags.isEmpty()) {
addSummaryDeprecatedComment(klass, tags.get(0), description);
}
} else {
addSummaryComment(klass, description);
}
rowContents.add(classLink);
rowContents.add(description);
table.addRow(klass, rowContents);
}
}