aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.tools.doclets.formats.html; aoqi@0: aoqi@0: import java.io.*; aoqi@0: aoqi@0: import com.sun.javadoc.*; aoqi@0: import com.sun.tools.doclets.formats.html.markup.*; aoqi@0: import com.sun.tools.doclets.internal.toolkit.*; aoqi@0: import com.sun.tools.doclets.internal.toolkit.util.*; aoqi@0: import com.sun.tools.javac.util.StringUtils; aoqi@0: aoqi@0: /** aoqi@0: * Writes method documentation in HTML format. aoqi@0: * aoqi@0: *

This is NOT part of any supported API. aoqi@0: * If you write code that depends on this, you do so at your own risk. aoqi@0: * This code and its internal interfaces are subject to change or aoqi@0: * deletion without notice. aoqi@0: * aoqi@0: * @author Robert Field aoqi@0: * @author Atul M Dambalkar aoqi@0: * @author Jamie Ho (rewrite) aoqi@0: * @author Bhavesh Patel (Modified) aoqi@0: */ aoqi@0: public class MethodWriterImpl extends AbstractExecutableMemberWriter aoqi@0: implements MethodWriter, MemberSummaryWriter { aoqi@0: aoqi@0: /** aoqi@0: * Construct a new MethodWriterImpl. aoqi@0: * aoqi@0: * @param writer the writer for the class that the methods belong to. aoqi@0: * @param classDoc the class being documented. aoqi@0: */ aoqi@0: public MethodWriterImpl(SubWriterHolderWriter writer, ClassDoc classDoc) { aoqi@0: super(writer, classDoc); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Construct a new MethodWriterImpl. aoqi@0: * aoqi@0: * @param writer The writer for the class that the methods belong to. aoqi@0: */ aoqi@0: public MethodWriterImpl(SubWriterHolderWriter writer) { aoqi@0: super(writer); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public Content getMemberSummaryHeader(ClassDoc classDoc, aoqi@0: Content memberSummaryTree) { aoqi@0: memberSummaryTree.addContent(HtmlConstants.START_OF_METHOD_SUMMARY); aoqi@0: Content memberTree = writer.getMemberTreeHeader(); aoqi@0: writer.addSummaryHeader(this, classDoc, memberTree); aoqi@0: return memberTree; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public Content getMethodDetailsTreeHeader(ClassDoc classDoc, aoqi@0: Content memberDetailsTree) { aoqi@0: memberDetailsTree.addContent(HtmlConstants.START_OF_METHOD_DETAILS); aoqi@0: Content methodDetailsTree = writer.getMemberTreeHeader(); aoqi@0: methodDetailsTree.addContent(writer.getMarkerAnchor( aoqi@0: SectionName.METHOD_DETAIL)); aoqi@0: Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING, aoqi@0: writer.methodDetailsLabel); aoqi@0: methodDetailsTree.addContent(heading); aoqi@0: return methodDetailsTree; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public Content getMethodDocTreeHeader(MethodDoc method, aoqi@0: Content methodDetailsTree) { aoqi@0: String erasureAnchor; aoqi@0: if ((erasureAnchor = getErasureAnchor(method)) != null) { aoqi@0: methodDetailsTree.addContent(writer.getMarkerAnchor((erasureAnchor))); aoqi@0: } aoqi@0: methodDetailsTree.addContent( aoqi@0: writer.getMarkerAnchor(writer.getAnchor(method))); aoqi@0: Content methodDocTree = writer.getMemberTreeHeader(); aoqi@0: Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING); aoqi@0: heading.addContent(method.name()); aoqi@0: methodDocTree.addContent(heading); aoqi@0: return methodDocTree; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Get the signature for the given method. aoqi@0: * aoqi@0: * @param method the method being documented. aoqi@0: * @return a content object for the signature aoqi@0: */ aoqi@0: public Content getSignature(MethodDoc method) { aoqi@0: Content pre = new HtmlTree(HtmlTag.PRE); aoqi@0: writer.addAnnotationInfo(method, pre); aoqi@0: addModifiers(method, pre); aoqi@0: addTypeParameters(method, pre); aoqi@0: addReturnType(method, pre); aoqi@0: if (configuration.linksource) { aoqi@0: Content methodName = new StringContent(method.name()); aoqi@0: writer.addSrcLink(method, methodName, pre); aoqi@0: } else { aoqi@0: addName(method.name(), pre); aoqi@0: } aoqi@0: int indent = pre.charCount(); aoqi@0: addParameters(method, pre, indent); aoqi@0: addExceptions(method, pre, indent); aoqi@0: return pre; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public void addDeprecated(MethodDoc method, Content methodDocTree) { aoqi@0: addDeprecatedInfo(method, methodDocTree); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public void addComments(Type holder, MethodDoc method, Content methodDocTree) { aoqi@0: ClassDoc holderClassDoc = holder.asClassDoc(); aoqi@0: if (method.inlineTags().length > 0) { aoqi@0: if (holder.asClassDoc().equals(classdoc) || aoqi@0: (! (holderClassDoc.isPublic() || aoqi@0: Util.isLinkable(holderClassDoc, configuration)))) { aoqi@0: writer.addInlineComment(method, methodDocTree); aoqi@0: } else { aoqi@0: Content link = aoqi@0: writer.getDocLink(LinkInfoImpl.Kind.METHOD_DOC_COPY, aoqi@0: holder.asClassDoc(), method, aoqi@0: holder.asClassDoc().isIncluded() ? aoqi@0: holder.typeName() : holder.qualifiedTypeName(), aoqi@0: false); aoqi@0: Content codelLink = HtmlTree.CODE(link); aoqi@0: Content descfrmLabel = HtmlTree.SPAN(HtmlStyle.descfrmTypeLabel, holder.asClassDoc().isClass()? aoqi@0: writer.descfrmClassLabel : writer.descfrmInterfaceLabel); aoqi@0: descfrmLabel.addContent(writer.getSpace()); aoqi@0: descfrmLabel.addContent(codelLink); aoqi@0: methodDocTree.addContent(HtmlTree.DIV(HtmlStyle.block, descfrmLabel)); aoqi@0: writer.addInlineComment(method, methodDocTree); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public void addTags(MethodDoc method, Content methodDocTree) { aoqi@0: writer.addTagsInfo(method, methodDocTree); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public Content getMethodDetails(Content methodDetailsTree) { aoqi@0: return getMemberTree(methodDetailsTree); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public Content getMethodDoc(Content methodDocTree, aoqi@0: boolean isLastContent) { aoqi@0: return getMemberTree(methodDocTree, isLastContent); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Close the writer. aoqi@0: */ aoqi@0: public void close() throws IOException { aoqi@0: writer.close(); aoqi@0: } aoqi@0: aoqi@0: public int getMemberKind() { aoqi@0: return VisibleMemberMap.METHODS; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public void addSummaryLabel(Content memberTree) { aoqi@0: Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING, aoqi@0: writer.getResource("doclet.Method_Summary")); aoqi@0: memberTree.addContent(label); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public String getTableSummary() { aoqi@0: return configuration.getText("doclet.Member_Table_Summary", aoqi@0: configuration.getText("doclet.Method_Summary"), aoqi@0: configuration.getText("doclet.methods")); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public Content getCaption() { aoqi@0: return configuration.getResource("doclet.Methods"); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public String[] getSummaryTableHeader(ProgramElementDoc member) { aoqi@0: String[] header = new String[] { aoqi@0: writer.getModifierTypeHeader(), aoqi@0: configuration.getText("doclet.0_and_1", aoqi@0: configuration.getText("doclet.Method"), aoqi@0: configuration.getText("doclet.Description")) aoqi@0: }; aoqi@0: return header; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public void addSummaryAnchor(ClassDoc cd, Content memberTree) { aoqi@0: memberTree.addContent(writer.getMarkerAnchor( aoqi@0: SectionName.METHOD_SUMMARY)); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) { aoqi@0: inheritedTree.addContent(writer.getMarkerAnchor( aoqi@0: SectionName.METHODS_INHERITANCE, configuration.getClassName(cd))); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) { aoqi@0: Content classLink = writer.getPreQualifiedClassLink( aoqi@0: LinkInfoImpl.Kind.MEMBER, cd, false); aoqi@0: Content label = new StringContent(cd.isClass() ? aoqi@0: configuration.getText("doclet.Methods_Inherited_From_Class") : aoqi@0: configuration.getText("doclet.Methods_Inherited_From_Interface")); aoqi@0: Content labelHeading = HtmlTree.HEADING(HtmlConstants.INHERITED_SUMMARY_HEADING, aoqi@0: label); aoqi@0: labelHeading.addContent(writer.getSpace()); aoqi@0: labelHeading.addContent(classLink); aoqi@0: inheritedTree.addContent(labelHeading); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) { aoqi@0: MethodDoc meth = (MethodDoc)member; aoqi@0: addModifierAndType(meth, meth.returnType(), tdSummaryType); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: protected static void addOverridden(HtmlDocletWriter writer, aoqi@0: Type overriddenType, MethodDoc method, Content dl) { aoqi@0: if (writer.configuration.nocomment) { aoqi@0: return; aoqi@0: } aoqi@0: ClassDoc holderClassDoc = overriddenType.asClassDoc(); aoqi@0: if (! (holderClassDoc.isPublic() || aoqi@0: Util.isLinkable(holderClassDoc, writer.configuration))) { aoqi@0: //This is an implementation detail that should not be documented. aoqi@0: return; aoqi@0: } aoqi@0: if (overriddenType.asClassDoc().isIncluded() && ! method.isIncluded()) { aoqi@0: //The class is included but the method is not. That means that it aoqi@0: //is not visible so don't document this. aoqi@0: return; aoqi@0: } aoqi@0: Content label = writer.overridesLabel; aoqi@0: LinkInfoImpl.Kind context = LinkInfoImpl.Kind.METHOD_OVERRIDES; aoqi@0: aoqi@0: if (method != null) { aoqi@0: if (overriddenType.asClassDoc().isAbstract() && method.isAbstract()){ aoqi@0: //Abstract method is implemented from abstract class, aoqi@0: //not overridden aoqi@0: label = writer.specifiedByLabel; aoqi@0: context = LinkInfoImpl.Kind.METHOD_SPECIFIED_BY; aoqi@0: } aoqi@0: Content dt = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.overrideSpecifyLabel, label)); aoqi@0: dl.addContent(dt); aoqi@0: Content overriddenTypeLink = aoqi@0: writer.getLink(new LinkInfoImpl(writer.configuration, context, overriddenType)); aoqi@0: Content codeOverridenTypeLink = HtmlTree.CODE(overriddenTypeLink); aoqi@0: String name = method.name(); aoqi@0: Content methlink = writer.getLink( aoqi@0: new LinkInfoImpl(writer.configuration, LinkInfoImpl.Kind.MEMBER, aoqi@0: overriddenType.asClassDoc()) aoqi@0: .where(writer.getName(writer.getAnchor(method))).label(name)); aoqi@0: Content codeMethLink = HtmlTree.CODE(methlink); aoqi@0: Content dd = HtmlTree.DD(codeMethLink); aoqi@0: dd.addContent(writer.getSpace()); aoqi@0: dd.addContent(writer.getResource("doclet.in_class")); aoqi@0: dd.addContent(writer.getSpace()); aoqi@0: dd.addContent(codeOverridenTypeLink); aoqi@0: dl.addContent(dd); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: protected static void addImplementsInfo(HtmlDocletWriter writer, aoqi@0: MethodDoc method, Content dl) { aoqi@0: if(writer.configuration.nocomment){ aoqi@0: return; aoqi@0: } aoqi@0: ImplementedMethods implementedMethodsFinder = aoqi@0: new ImplementedMethods(method, writer.configuration); aoqi@0: MethodDoc[] implementedMethods = implementedMethodsFinder.build(); aoqi@0: for (int i = 0; i < implementedMethods.length; i++) { aoqi@0: MethodDoc implementedMeth = implementedMethods[i]; aoqi@0: Type intfac = implementedMethodsFinder.getMethodHolder(implementedMeth); aoqi@0: Content intfaclink = writer.getLink(new LinkInfoImpl( aoqi@0: writer.configuration, LinkInfoImpl.Kind.METHOD_SPECIFIED_BY, intfac)); aoqi@0: Content codeIntfacLink = HtmlTree.CODE(intfaclink); aoqi@0: Content dt = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.overrideSpecifyLabel, writer.specifiedByLabel)); aoqi@0: dl.addContent(dt); aoqi@0: Content methlink = writer.getDocLink( aoqi@0: LinkInfoImpl.Kind.MEMBER, implementedMeth, aoqi@0: implementedMeth.name(), false); aoqi@0: Content codeMethLink = HtmlTree.CODE(methlink); aoqi@0: Content dd = HtmlTree.DD(codeMethLink); aoqi@0: dd.addContent(writer.getSpace()); aoqi@0: dd.addContent(writer.getResource("doclet.in_interface")); aoqi@0: dd.addContent(writer.getSpace()); aoqi@0: dd.addContent(codeIntfacLink); aoqi@0: dl.addContent(dd); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Add the return type. aoqi@0: * aoqi@0: * @param method the method being documented. aoqi@0: * @param htmltree the content tree to which the return type will be added aoqi@0: */ aoqi@0: protected void addReturnType(MethodDoc method, Content htmltree) { aoqi@0: Type type = method.returnType(); aoqi@0: if (type != null) { aoqi@0: Content linkContent = writer.getLink( aoqi@0: new LinkInfoImpl(configuration, LinkInfoImpl.Kind.RETURN_TYPE, type)); aoqi@0: htmltree.addContent(linkContent); aoqi@0: htmltree.addContent(writer.getSpace()); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: protected Content getNavSummaryLink(ClassDoc cd, boolean link) { aoqi@0: if (link) { aoqi@0: if (cd == null) { aoqi@0: return writer.getHyperLink( aoqi@0: SectionName.METHOD_SUMMARY, aoqi@0: writer.getResource("doclet.navMethod")); aoqi@0: } else { aoqi@0: return writer.getHyperLink( aoqi@0: SectionName.METHODS_INHERITANCE, aoqi@0: configuration.getClassName(cd), writer.getResource("doclet.navMethod")); aoqi@0: } aoqi@0: } else { aoqi@0: return writer.getResource("doclet.navMethod"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: protected void addNavDetailLink(boolean link, Content liNav) { aoqi@0: if (link) { aoqi@0: liNav.addContent(writer.getHyperLink( aoqi@0: SectionName.METHOD_DETAIL, writer.getResource("doclet.navMethod"))); aoqi@0: } else { aoqi@0: liNav.addContent(writer.getResource("doclet.navMethod")); aoqi@0: } aoqi@0: } aoqi@0: }