package jdk.javadoc.internal.doclets.formats.html;
import java.util.Arrays;
import java.util.List;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
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.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.ConstructorWriter;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter;
import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable;
import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.CONSTRUCTORS;
public class ConstructorWriterImpl extends AbstractExecutableMemberWriter
implements ConstructorWriter, MemberSummaryWriter {
private boolean foundNonPubConstructor = false;
public ConstructorWriterImpl(SubWriterHolderWriter writer, TypeElement typeElement) {
super(writer, typeElement);
VisibleMemberTable vmt = configuration.getVisibleMemberTable(typeElement);
List<? extends Element> constructors = vmt.getVisibleMembers(CONSTRUCTORS);
for (Element constructor : constructors) {
if (utils.isProtected(constructor) || utils.isPrivate(constructor)) {
setFoundNonPubConstructor(true);
}
}
}
public ConstructorWriterImpl(SubWriterHolderWriter writer) {
super(writer);
}
@Override
public Content (TypeElement typeElement,
Content memberSummaryTree) {
memberSummaryTree.add(MarkerComments.START_OF_CONSTRUCTOR_SUMMARY);
Content memberTree = new ContentBuilder();
writer.addSummaryHeader(this, typeElement, memberTree);
return memberTree;
}
@Override
public void addMemberTree(Content memberSummaryTree, Content memberTree) {
writer.addMemberTree(HtmlStyle.constructorSummary, memberSummaryTree, memberTree);
}
@Override
public Content (TypeElement typeElement,
Content memberDetailsTree) {
memberDetailsTree.add(MarkerComments.START_OF_CONSTRUCTOR_DETAILS);
Content constructorDetailsTree = new ContentBuilder();
Content heading = HtmlTree.HEADING(Headings.TypeDeclaration.DETAILS_HEADING,
contents.constructorDetailsLabel);
constructorDetailsTree.add(links.createAnchor(
SectionName.CONSTRUCTOR_DETAIL));
constructorDetailsTree.add(heading);
return constructorDetailsTree;
}
@Override
public Content (ExecutableElement constructor,
Content constructorDetailsTree) {
String erasureAnchor;
Content constructorDocTree = new ContentBuilder();
Content heading = new HtmlTree(Headings.TypeDeclaration.MEMBER_HEADING);
if ((erasureAnchor = getErasureAnchor(constructor)) != null) {
heading.add(links.createAnchor((erasureAnchor)));
}
heading.add(links.createAnchor(writer.getAnchor(constructor), new StringContent(name(constructor))));
constructorDocTree.add(heading);
return HtmlTree.SECTION(HtmlStyle.detail, constructorDocTree);
}
@Override
public Content getSignature(ExecutableElement constructor) {
return new MemberSignature(constructor)
.addParameters(getParameters(constructor, true))
.addExceptions(getExceptions(constructor))
.toContent();
}
@Override
public void addDeprecated(ExecutableElement constructor, Content constructorDocTree) {
addDeprecatedInfo(constructor, constructorDocTree);
}
@Override
public void (ExecutableElement constructor, Content constructorDocTree) {
addComment(constructor, constructorDocTree);
}
@Override
public void addTags(ExecutableElement constructor, Content constructorDocTree) {
writer.addTagsInfo(constructor, constructorDocTree);
}
@Override
public Content getConstructorDetails(Content constructorDetailsTreeHeader, Content constructorDetailsTree) {
Content constructorDetails = new ContentBuilder(constructorDetailsTreeHeader, constructorDetailsTree);
return getMemberTree(HtmlTree.SECTION(HtmlStyle.constructorDetails, constructorDetails));
}
@Override
public Content getConstructorDoc(Content constructorDocTree) {
return getMemberTree(constructorDocTree);
}
@Override
public void setFoundNonPubConstructor(boolean foundNonPubConstructor) {
this.foundNonPubConstructor = foundNonPubConstructor;
}
@Override
public void addSummaryLabel(Content memberTree) {
Content label = HtmlTree.HEADING(Headings.TypeDeclaration.SUMMARY_HEADING,
contents.constructorSummaryLabel);
memberTree.add(label);
}
@Override
public TableHeader (Element member) {
if (foundNonPubConstructor) {
return new TableHeader(contents.modifierLabel, contents.constructorLabel,
contents.descriptionLabel);
} else {
return new TableHeader(contents.constructorLabel, contents.descriptionLabel);
}
}
@Override
protected Table createSummaryTable() {
List<HtmlStyle> bodyRowStyles;
int rowScopeColumn;
if (foundNonPubConstructor) {
bodyRowStyles = Arrays.asList(HtmlStyle.colFirst, HtmlStyle.colConstructorName,
HtmlStyle.colLast);
rowScopeColumn = 1;
} else {
bodyRowStyles = Arrays.asList(HtmlStyle.colConstructorName, HtmlStyle.colLast);
rowScopeColumn = 0;
}
return new Table(HtmlStyle.memberSummary)
.setCaption(contents.constructors)
.setHeader(getSummaryTableHeader(typeElement))
.setRowScopeColumn(rowScopeColumn)
.setColumnStyles(bodyRowStyles);
}
@Override
public void addSummaryAnchor(TypeElement typeElement, Content memberTree) {
memberTree.add(links.createAnchor(SectionName.CONSTRUCTOR_SUMMARY));
}
@Override
public void addInheritedSummaryAnchor(TypeElement typeElement, Content inheritedTree) {
}
@Override
public void addInheritedSummaryLabel(TypeElement typeElement, Content inheritedTree) {
}
@Override
protected void addSummaryType(Element member, Content tdSummaryType) {
if (foundNonPubConstructor) {
Content code = new HtmlTree(HtmlTag.CODE);
if (utils.isProtected(member)) {
code.add("protected ");
} else if (utils.isPrivate(member)) {
code.add("private ");
} else if (utils.isPublic(member)) {
code.add(Entity.NO_BREAK_SPACE);
} else {
code.add(
resources.getText("doclet.Package_private"));
}
tdSummaryType.add(code);
}
}
@Override
public Content (){
return writer.getMemberTreeHeader();
}
}