package jdk.javadoc.internal.doclets.formats.html;
import java.util.List;
import java.util.SortedSet;
import javax.lang.model.element.ModuleElement;
import javax.lang.model.element.PackageElement;
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.Entity;
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.StringContent;
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.PackageSummaryWriter;
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.DocPaths;
public class PackageWriterImpl extends HtmlDocletWriter
implements PackageSummaryWriter {
protected PackageElement packageElement;
protected HtmlTree mainTree = HtmlTree.MAIN();
protected HtmlTree sectionTree = HtmlTree.SECTION(HtmlStyle.packageDescription, new ContentBuilder());
private final Navigation navBar;
public PackageWriterImpl(HtmlConfiguration configuration, PackageElement packageElement) {
super(configuration,
configuration.docPaths.forPackage(packageElement)
.resolve(DocPaths.PACKAGE_SUMMARY));
this.packageElement = packageElement;
this.navBar = new Navigation(packageElement, configuration, fixedNavDiv, PageMode.PACKAGE, path);
}
@Override
public Content (String heading) {
HtmlTree bodyTree = getBody(getWindowTitle(utils.getPackageName(packageElement)));
HtmlTree htmlTree = HtmlTree.HEADER();
addTop(htmlTree);
Content linkContent = getModuleLink(utils.elementUtils.getModuleOf(packageElement),
contents.moduleLabel);
navBar.setNavLinkModule(linkContent);
navBar.setUserHeader(getUserHeaderFooter(true));
htmlTree.add(navBar.getContent(true));
bodyTree.add(htmlTree);
HtmlTree div = new HtmlTree(HtmlTag.DIV);
div.setStyle(HtmlStyle.header);
if (configuration.showModules) {
ModuleElement mdle = configuration.docEnv.getElementUtils().getModuleOf(packageElement);
Content classModuleLabel = HtmlTree.SPAN(HtmlStyle.moduleLabelInPackage, contents.moduleLabel);
Content moduleNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, classModuleLabel);
moduleNameDiv.add(Entity.NO_BREAK_SPACE);
moduleNameDiv.add(getModuleLink(mdle,
new StringContent(mdle.getQualifiedName().toString())));
div.add(moduleNameDiv);
}
Content annotationContent = new HtmlTree(HtmlTag.P);
addAnnotationInfo(packageElement, annotationContent);
div.add(annotationContent);
Content tHeading = HtmlTree.HEADING(Headings.PAGE_TITLE_HEADING, true,
HtmlStyle.title, contents.packageLabel);
tHeading.add(Entity.NO_BREAK_SPACE);
Content packageHead = new StringContent(heading);
tHeading.add(packageHead);
div.add(tHeading);
mainTree.add(div);
return bodyTree;
}
@Override
public Content () {
HtmlTree div = new HtmlTree(HtmlTag.DIV);
div.setStyle(HtmlStyle.contentContainer);
return div;
}
public void addDeprecationInfo(Content div) {
List<? extends DocTree> deprs = utils.getBlockTags(packageElement, DocTree.Kind.DEPRECATED);
if (utils.isDeprecated(packageElement)) {
CommentHelper ch = utils.getCommentHelper(packageElement);
HtmlTree deprDiv = new HtmlTree(HtmlTag.DIV);
deprDiv.setStyle(HtmlStyle.deprecationBlock);
Content deprPhrase = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, getDeprecatedPhrase(packageElement));
deprDiv.add(deprPhrase);
if (!deprs.isEmpty()) {
List<? extends DocTree> commentTags = ch.getDescription(configuration, deprs.get(0));
if (!commentTags.isEmpty()) {
addInlineDeprecatedComment(packageElement, deprs.get(0), deprDiv);
}
}
div.add(deprDiv);
}
}
@Override
public Content () {
HtmlTree ul = new HtmlTree(HtmlTag.UL);
ul.setStyle(HtmlStyle.blockList);
return ul;
}
@Override
public void addInterfaceSummary(SortedSet<TypeElement> interfaces, Content summaryContentTree) {
TableHeader tableHeader= new TableHeader(contents.interfaceLabel, contents.descriptionLabel);
addClassesSummary(interfaces, resources.interfaceSummary, tableHeader, summaryContentTree);
}
@Override
public void addClassSummary(SortedSet<TypeElement> classes, Content summaryContentTree) {
TableHeader tableHeader= new TableHeader(contents.classLabel, contents.descriptionLabel);
addClassesSummary(classes, resources.classSummary, tableHeader, summaryContentTree);
}
@Override
public void addEnumSummary(SortedSet<TypeElement> enums, Content summaryContentTree) {
TableHeader tableHeader= new TableHeader(contents.enum_, contents.descriptionLabel);
addClassesSummary(enums, resources.enumSummary, tableHeader, summaryContentTree);
}
@Override
public void addExceptionSummary(SortedSet<TypeElement> exceptions, Content summaryContentTree) {
TableHeader tableHeader= new TableHeader(contents.exception, contents.descriptionLabel);
addClassesSummary(exceptions, resources.exceptionSummary, tableHeader, summaryContentTree);
}
@Override
public void addErrorSummary(SortedSet<TypeElement> errors, Content summaryContentTree) {
TableHeader tableHeader= new TableHeader(contents.error, contents.descriptionLabel);
addClassesSummary(errors, resources.errorSummary, tableHeader, summaryContentTree);
}
@Override
public void addAnnotationTypeSummary(SortedSet<TypeElement> annoTypes, Content summaryContentTree) {
TableHeader tableHeader= new TableHeader(contents.annotationType, contents.descriptionLabel);
addClassesSummary(annoTypes, resources.annotationTypeSummary, tableHeader, summaryContentTree);
}
public void (SortedSet<TypeElement> classes, String label,
TableHeader tableHeader, Content summaryContentTree) {
if(!classes.isEmpty()) {
Table table = new Table(HtmlStyle.typeSummary)
.setCaption(getTableCaption(new StringContent(label)))
.setHeader(tableHeader)
.setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colLast);
for (TypeElement klass : classes) {
if (!utils.isCoreClass(klass) || !configuration.isGeneratedDoc(klass)) {
continue;
}
Content classLink = getLink(new LinkInfoImpl(
configuration, LinkInfoImpl.Kind.PACKAGE, 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);
}
table.addRow(classLink, description);
}
Content li = HtmlTree.LI(HtmlStyle.blockList, table.toContent());
summaryContentTree.add(li);
}
}
@Override
public void addPackageDescription(Content packageContentTree) {
if (!utils.getBody(packageElement).isEmpty()) {
Content tree = sectionTree;
tree.add(links.createAnchor(SectionName.PACKAGE_DESCRIPTION));
addDeprecationInfo(tree);
addInlineComment(packageElement, tree);
}
}
@Override
public void addPackageTags(Content packageContentTree) {
Content htmlTree = sectionTree;
addTagsInfo(packageElement, htmlTree);
packageContentTree.add(sectionTree);
}
@Override
public void addPackageContent(Content contentTree, Content packageContentTree) {
mainTree.add(packageContentTree);
contentTree.add(mainTree);
}
@Override
public void (Content contentTree) {
Content htmlTree = HtmlTree.FOOTER();
navBar.setUserFooter(getUserHeaderFooter(false));
htmlTree.add(navBar.getContent(false));
addBottom(htmlTree);
contentTree.add(htmlTree);
}
@Override
public void printDocument(Content contentTree) throws DocFileIOException {
String description = getDescription("declaration", packageElement);
List<DocPath> localStylesheets = getLocalStylesheets(packageElement);
printHtmlDocument(configuration.metakeywords.getMetaKeywords(packageElement),
description, localStylesheets, contentTree);
}
@Override
public Content getPackageSummary(Content summaryContentTree) {
return HtmlTree.SECTION(HtmlStyle.summary, summaryContentTree);
}
}