package jdk.javadoc.internal.doclets.formats.html;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeMirror;
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.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.Content;
import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter;
import jdk.javadoc.internal.doclets.toolkit.MethodWriter;
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable;
public class MethodWriterImpl extends AbstractExecutableMemberWriter
implements MethodWriter, MemberSummaryWriter {
public MethodWriterImpl(SubWriterHolderWriter writer, TypeElement typeElement) {
super(writer, typeElement);
}
public MethodWriterImpl(SubWriterHolderWriter writer) {
super(writer);
}
@Override
public Content (TypeElement typeElement, Content memberSummaryTree) {
memberSummaryTree.add(MarkerComments.START_OF_METHOD_SUMMARY);
Content memberTree = new ContentBuilder();
writer.addSummaryHeader(this, typeElement, memberTree);
return memberTree;
}
@Override
public void addMemberTree(Content memberSummaryTree, Content memberTree) {
writer.addMemberTree(HtmlStyle.methodSummary, memberSummaryTree, memberTree);
}
@Override
public Content (TypeElement typeElement, Content memberDetailsTree) {
memberDetailsTree.add(MarkerComments.START_OF_METHOD_DETAILS);
Content methodDetailsTree = new ContentBuilder();
Content heading = HtmlTree.HEADING(Headings.TypeDeclaration.DETAILS_HEADING,
contents.methodDetailLabel);
methodDetailsTree.add(links.createAnchor(SectionName.METHOD_DETAIL));
methodDetailsTree.add(heading);
return methodDetailsTree;
}
@Override
public Content (ExecutableElement method, Content methodDetailsTree) {
String erasureAnchor;
Content methodDocTree = new ContentBuilder();
Content heading = new HtmlTree(Headings.TypeDeclaration.MEMBER_HEADING);
if ((erasureAnchor = getErasureAnchor(method)) != null) {
heading.add(links.createAnchor((erasureAnchor)));
}
heading.add(links.createAnchor(writer.getAnchor(method), new StringContent(name(method))));
methodDocTree.add(heading);
return HtmlTree.SECTION(HtmlStyle.detail, methodDocTree);
}
@Override
public Content getSignature(ExecutableElement method) {
return new MemberSignature(method)
.addTypeParameters(getTypeParameters(method))
.addReturnType(getReturnType(method))
.addParameters(getParameters(method, true))
.addExceptions(getExceptions(method))
.toContent();
}
@Override
public void addDeprecated(ExecutableElement method, Content methodDocTree) {
addDeprecatedInfo(method, methodDocTree);
}
@Override
public void (TypeMirror holderType, ExecutableElement method, Content methodDocTree) {
TypeElement holder = utils.asTypeElement(holderType);
if (!utils.getFullBody(method).isEmpty()) {
if (holder.equals(typeElement) ||
!(utils.isPublic(holder) ||
utils.isLinkable(holder))) {
writer.addInlineComment(method, methodDocTree);
} else {
Content link =
writer.getDocLink(LinkInfoImpl.Kind.EXECUTABLE_ELEMENT_COPY,
holder, method,
utils.isIncluded(holder)
? utils.getSimpleName(holder)
: utils.getFullyQualifiedName(holder),
false);
Content codelLink = HtmlTree.CODE(link);
Content descfrmLabel = HtmlTree.SPAN(HtmlStyle.descfrmTypeLabel,
utils.isClass(holder)
? contents.descfrmClassLabel
: contents.descfrmInterfaceLabel);
descfrmLabel.add(Entity.NO_BREAK_SPACE);
descfrmLabel.add(codelLink);
methodDocTree.add(HtmlTree.DIV(HtmlStyle.block, descfrmLabel));
writer.addInlineComment(method, methodDocTree);
}
}
}
@Override
public void addTags(ExecutableElement method, Content methodDocTree) {
writer.addTagsInfo(method, methodDocTree);
}
@Override
public Content getMethodDetails(Content methodDetailsTreeHeader, Content methodDetailsTree) {
Content methodDetails = new ContentBuilder(methodDetailsTreeHeader, methodDetailsTree);
return getMemberTree(HtmlTree.SECTION(HtmlStyle.methodDetails, methodDetails));
}
@Override
public Content getMethodDoc(Content methodDocTree) {
return getMemberTree(methodDocTree);
}
@Override
public void addSummaryLabel(Content memberTree) {
Content label = HtmlTree.HEADING(Headings.TypeDeclaration.SUMMARY_HEADING,
contents.methodSummary);
memberTree.add(label);
}
@Override
public TableHeader (Element member) {
return new TableHeader(contents.modifierAndTypeLabel, contents.methodLabel,
contents.descriptionLabel);
}
@Override
protected Table createSummaryTable() {
return new Table(HtmlStyle.memberSummary)
.setHeader(getSummaryTableHeader(typeElement))
.setRowScopeColumn(1)
.setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colSecond, HtmlStyle.colLast)
.setDefaultTab(resources.getText("doclet.All_Methods"))
.addTab(resources.getText("doclet.Static_Methods"), utils::isStatic)
.addTab(resources.getText("doclet.Instance_Methods"), e -> !utils.isStatic(e))
.addTab(resources.getText("doclet.Abstract_Methods"), utils::isAbstract)
.addTab(resources.getText("doclet.Concrete_Methods"),
e -> !utils.isAbstract(e) && !utils.isInterface(e.getEnclosingElement()))
.addTab(resources.getText("doclet.Default_Methods"), utils::isDefault)
.addTab(resources.getText("doclet.Deprecated_Methods"),
e -> utils.isDeprecated(e) || utils.isDeprecated(typeElement))
.setTabScript(i -> "show(" + i + ");");
}
@Override
public void addSummaryAnchor(TypeElement typeElement, Content memberTree) {
memberTree.add(links.createAnchor(SectionName.METHOD_SUMMARY));
}
@Override
public void addInheritedSummaryAnchor(TypeElement typeElement, Content inheritedTree) {
inheritedTree.add(links.createAnchor(
SectionName.METHODS_INHERITANCE, configuration.getClassName(typeElement)));
}
@Override
public void addInheritedSummaryLabel(TypeElement typeElement, Content inheritedTree) {
Content classLink = writer.getPreQualifiedClassLink(
LinkInfoImpl.Kind.MEMBER, typeElement, false);
Content label;
if (configuration.summarizeOverriddenMethods) {
label = new StringContent(utils.isClass(typeElement)
? resources.getText("doclet.Methods_Declared_In_Class")
: resources.getText("doclet.Methods_Declared_In_Interface"));
} else {
label = new StringContent(utils.isClass(typeElement)
? resources.getText("doclet.Methods_Inherited_From_Class")
: resources.getText("doclet.Methods_Inherited_From_Interface"));
}
Content labelHeading = HtmlTree.HEADING(Headings.TypeDeclaration.INHERITED_SUMMARY_HEADING,
label);
labelHeading.add(Entity.NO_BREAK_SPACE);
labelHeading.add(classLink);
inheritedTree.add(labelHeading);
}
@Override
protected void addSummaryType(Element member, Content tdSummaryType) {
ExecutableElement meth = (ExecutableElement)member;
addModifierAndType(meth, utils.getReturnType(typeElement, meth), tdSummaryType);
}
protected static void addOverridden(HtmlDocletWriter writer,
TypeMirror overriddenType, ExecutableElement method, Content dl) {
if (writer.configuration.nocomment) {
return;
}
Utils utils = writer.utils;
Contents contents = writer.contents;
TypeElement holder = utils.getEnclosingTypeElement(method);
if (!(utils.isPublic(holder) ||
utils.isLinkable(holder))) {
return;
}
if (utils.isIncluded(holder) && ! utils.isIncluded(method)) {
return;
}
Content label = contents.overridesLabel;
LinkInfoImpl.Kind context = LinkInfoImpl.Kind.METHOD_OVERRIDES;
if (method != null) {
if (utils.isAbstract(holder) && utils.isAbstract(method)){
label = contents.specifiedByLabel;
context = LinkInfoImpl.Kind.METHOD_SPECIFIED_BY;
}
Content dt = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.overrideSpecifyLabel, label));
dl.add(dt);
Content overriddenTypeLink =
writer.getLink(new LinkInfoImpl(writer.configuration, context, overriddenType));
Content codeOverridenTypeLink = HtmlTree.CODE(overriddenTypeLink);
Content methlink = writer.getLink(
new LinkInfoImpl(writer.configuration, LinkInfoImpl.Kind.MEMBER,
holder)
.where(writer.links.getName(writer.getAnchor(method))).label(method.getSimpleName()));
Content codeMethLink = HtmlTree.CODE(methlink);
Content dd = HtmlTree.DD(codeMethLink);
dd.add(Entity.NO_BREAK_SPACE);
dd.add(writer.contents.inClass);
dd.add(Entity.NO_BREAK_SPACE);
dd.add(codeOverridenTypeLink);
dl.add(dd);
}
}
protected static void addImplementsInfo(HtmlDocletWriter writer,
ExecutableElement method, Content dl) {
Utils utils = writer.utils;
if (utils.isStatic(method) || writer.configuration.nocomment) {
return;
}
Contents contents = writer.contents;
VisibleMemberTable vmt = writer.configuration
.getVisibleMemberTable(utils.getEnclosingTypeElement(method));
SortedSet<ExecutableElement> implementedMethods =
new TreeSet<>(utils.makeOverrideUseComparator());
implementedMethods.addAll(vmt.getImplementedMethods(method));
for (ExecutableElement implementedMeth : implementedMethods) {
TypeMirror intfac = vmt.getImplementedMethodHolder(method, implementedMeth);
intfac = utils.getDeclaredType(utils.getEnclosingTypeElement(method), intfac);
Content intfaclink = writer.getLink(new LinkInfoImpl(
writer.configuration, LinkInfoImpl.Kind.METHOD_SPECIFIED_BY, intfac));
Content codeIntfacLink = HtmlTree.CODE(intfaclink);
Content dt = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.overrideSpecifyLabel, contents.specifiedByLabel));
dl.add(dt);
Content methlink = writer.getDocLink(
LinkInfoImpl.Kind.MEMBER, implementedMeth,
implementedMeth.getSimpleName(), false);
Content codeMethLink = HtmlTree.CODE(methlink);
Content dd = HtmlTree.DD(codeMethLink);
dd.add(Entity.NO_BREAK_SPACE);
dd.add(contents.inInterface);
dd.add(Entity.NO_BREAK_SPACE);
dd.add(codeIntfacLink);
dl.add(dd);
}
}
protected Content getReturnType(ExecutableElement method) {
TypeMirror type = utils.getReturnType(typeElement, method);
if (type != null) {
return writer.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.RETURN_TYPE, type));
}
return new ContentBuilder();
}
@Override
public Content (){
return writer.getMemberTreeHeader();
}
}