src/share/classes/com/sun/tools/doclets/formats/html/MethodWriterImpl.java

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

     1 /*
     2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.doclets.formats.html;
    28 import java.io.*;
    30 import com.sun.javadoc.*;
    31 import com.sun.tools.doclets.formats.html.markup.*;
    32 import com.sun.tools.doclets.internal.toolkit.*;
    33 import com.sun.tools.doclets.internal.toolkit.util.*;
    34 import com.sun.tools.javac.util.StringUtils;
    36 /**
    37  * Writes method documentation in HTML format.
    38  *
    39  *  <p><b>This is NOT part of any supported API.
    40  *  If you write code that depends on this, you do so at your own risk.
    41  *  This code and its internal interfaces are subject to change or
    42  *  deletion without notice.</b>
    43  *
    44  * @author Robert Field
    45  * @author Atul M Dambalkar
    46  * @author Jamie Ho (rewrite)
    47  * @author Bhavesh Patel (Modified)
    48  */
    49 public class MethodWriterImpl extends AbstractExecutableMemberWriter
    50         implements MethodWriter, MemberSummaryWriter {
    52     /**
    53      * Construct a new MethodWriterImpl.
    54      *
    55      * @param writer the writer for the class that the methods belong to.
    56      * @param classDoc the class being documented.
    57      */
    58     public MethodWriterImpl(SubWriterHolderWriter writer, ClassDoc classDoc) {
    59         super(writer, classDoc);
    60     }
    62     /**
    63      * Construct a new MethodWriterImpl.
    64      *
    65      * @param writer The writer for the class that the methods belong to.
    66      */
    67     public MethodWriterImpl(SubWriterHolderWriter writer) {
    68         super(writer);
    69     }
    71     /**
    72      * {@inheritDoc}
    73      */
    74     public Content getMemberSummaryHeader(ClassDoc classDoc,
    75             Content memberSummaryTree) {
    76         memberSummaryTree.addContent(HtmlConstants.START_OF_METHOD_SUMMARY);
    77         Content memberTree = writer.getMemberTreeHeader();
    78         writer.addSummaryHeader(this, classDoc, memberTree);
    79         return memberTree;
    80     }
    82     /**
    83      * {@inheritDoc}
    84      */
    85     public Content getMethodDetailsTreeHeader(ClassDoc classDoc,
    86             Content memberDetailsTree) {
    87         memberDetailsTree.addContent(HtmlConstants.START_OF_METHOD_DETAILS);
    88         Content methodDetailsTree = writer.getMemberTreeHeader();
    89         methodDetailsTree.addContent(writer.getMarkerAnchor(
    90                 SectionName.METHOD_DETAIL));
    91         Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING,
    92                 writer.methodDetailsLabel);
    93         methodDetailsTree.addContent(heading);
    94         return methodDetailsTree;
    95     }
    97     /**
    98      * {@inheritDoc}
    99      */
   100     public Content getMethodDocTreeHeader(MethodDoc method,
   101             Content methodDetailsTree) {
   102         String erasureAnchor;
   103         if ((erasureAnchor = getErasureAnchor(method)) != null) {
   104             methodDetailsTree.addContent(writer.getMarkerAnchor((erasureAnchor)));
   105         }
   106         methodDetailsTree.addContent(
   107                 writer.getMarkerAnchor(writer.getAnchor(method)));
   108         Content methodDocTree = writer.getMemberTreeHeader();
   109         Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING);
   110         heading.addContent(method.name());
   111         methodDocTree.addContent(heading);
   112         return methodDocTree;
   113     }
   115     /**
   116      * Get the signature for the given method.
   117      *
   118      * @param method the method being documented.
   119      * @return a content object for the signature
   120      */
   121     public Content getSignature(MethodDoc method) {
   122         Content pre = new HtmlTree(HtmlTag.PRE);
   123         writer.addAnnotationInfo(method, pre);
   124         addModifiers(method, pre);
   125         addTypeParameters(method, pre);
   126         addReturnType(method, pre);
   127         if (configuration.linksource) {
   128             Content methodName = new StringContent(method.name());
   129             writer.addSrcLink(method, methodName, pre);
   130         } else {
   131             addName(method.name(), pre);
   132         }
   133         int indent = pre.charCount();
   134         addParameters(method, pre, indent);
   135         addExceptions(method, pre, indent);
   136         return pre;
   137     }
   139     /**
   140      * {@inheritDoc}
   141      */
   142     public void addDeprecated(MethodDoc method, Content methodDocTree) {
   143         addDeprecatedInfo(method, methodDocTree);
   144     }
   146     /**
   147      * {@inheritDoc}
   148      */
   149     public void addComments(Type holder, MethodDoc method, Content methodDocTree) {
   150         ClassDoc holderClassDoc = holder.asClassDoc();
   151         if (method.inlineTags().length > 0) {
   152             if (holder.asClassDoc().equals(classdoc) ||
   153                     (! (holderClassDoc.isPublic() ||
   154                     Util.isLinkable(holderClassDoc, configuration)))) {
   155                 writer.addInlineComment(method, methodDocTree);
   156             } else {
   157                 Content link =
   158                         writer.getDocLink(LinkInfoImpl.Kind.METHOD_DOC_COPY,
   159                         holder.asClassDoc(), method,
   160                         holder.asClassDoc().isIncluded() ?
   161                             holder.typeName() : holder.qualifiedTypeName(),
   162                             false);
   163                 Content codelLink = HtmlTree.CODE(link);
   164                 Content descfrmLabel = HtmlTree.SPAN(HtmlStyle.descfrmTypeLabel, holder.asClassDoc().isClass()?
   165                     writer.descfrmClassLabel : writer.descfrmInterfaceLabel);
   166                 descfrmLabel.addContent(writer.getSpace());
   167                 descfrmLabel.addContent(codelLink);
   168                 methodDocTree.addContent(HtmlTree.DIV(HtmlStyle.block, descfrmLabel));
   169                 writer.addInlineComment(method, methodDocTree);
   170             }
   171         }
   172     }
   174     /**
   175      * {@inheritDoc}
   176      */
   177     public void addTags(MethodDoc method, Content methodDocTree) {
   178         writer.addTagsInfo(method, methodDocTree);
   179     }
   181     /**
   182      * {@inheritDoc}
   183      */
   184     public Content getMethodDetails(Content methodDetailsTree) {
   185         return getMemberTree(methodDetailsTree);
   186     }
   188     /**
   189      * {@inheritDoc}
   190      */
   191     public Content getMethodDoc(Content methodDocTree,
   192             boolean isLastContent) {
   193         return getMemberTree(methodDocTree, isLastContent);
   194     }
   196     /**
   197      * Close the writer.
   198      */
   199     public void close() throws IOException {
   200         writer.close();
   201     }
   203     public int getMemberKind() {
   204         return VisibleMemberMap.METHODS;
   205     }
   207     /**
   208      * {@inheritDoc}
   209      */
   210     public void addSummaryLabel(Content memberTree) {
   211         Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING,
   212                 writer.getResource("doclet.Method_Summary"));
   213         memberTree.addContent(label);
   214     }
   216     /**
   217      * {@inheritDoc}
   218      */
   219     public String getTableSummary() {
   220         return configuration.getText("doclet.Member_Table_Summary",
   221                 configuration.getText("doclet.Method_Summary"),
   222                 configuration.getText("doclet.methods"));
   223     }
   225     /**
   226      * {@inheritDoc}
   227      */
   228     public Content getCaption() {
   229         return configuration.getResource("doclet.Methods");
   230     }
   232     /**
   233      * {@inheritDoc}
   234      */
   235     public String[] getSummaryTableHeader(ProgramElementDoc member) {
   236         String[] header = new String[] {
   237             writer.getModifierTypeHeader(),
   238             configuration.getText("doclet.0_and_1",
   239                     configuration.getText("doclet.Method"),
   240                     configuration.getText("doclet.Description"))
   241         };
   242         return header;
   243     }
   245     /**
   246      * {@inheritDoc}
   247      */
   248     public void addSummaryAnchor(ClassDoc cd, Content memberTree) {
   249         memberTree.addContent(writer.getMarkerAnchor(
   250                 SectionName.METHOD_SUMMARY));
   251     }
   253     /**
   254      * {@inheritDoc}
   255      */
   256     public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) {
   257         inheritedTree.addContent(writer.getMarkerAnchor(
   258                 SectionName.METHODS_INHERITANCE, configuration.getClassName(cd)));
   259     }
   261     /**
   262      * {@inheritDoc}
   263      */
   264     public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) {
   265         Content classLink = writer.getPreQualifiedClassLink(
   266                 LinkInfoImpl.Kind.MEMBER, cd, false);
   267         Content label = new StringContent(cd.isClass() ?
   268             configuration.getText("doclet.Methods_Inherited_From_Class") :
   269             configuration.getText("doclet.Methods_Inherited_From_Interface"));
   270         Content labelHeading = HtmlTree.HEADING(HtmlConstants.INHERITED_SUMMARY_HEADING,
   271                 label);
   272         labelHeading.addContent(writer.getSpace());
   273         labelHeading.addContent(classLink);
   274         inheritedTree.addContent(labelHeading);
   275     }
   277     /**
   278      * {@inheritDoc}
   279      */
   280     protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) {
   281         MethodDoc meth = (MethodDoc)member;
   282         addModifierAndType(meth, meth.returnType(), tdSummaryType);
   283     }
   285     /**
   286      * {@inheritDoc}
   287      */
   288     protected static void addOverridden(HtmlDocletWriter writer,
   289             Type overriddenType, MethodDoc method, Content dl) {
   290         if (writer.configuration.nocomment) {
   291             return;
   292         }
   293         ClassDoc holderClassDoc = overriddenType.asClassDoc();
   294         if (! (holderClassDoc.isPublic() ||
   295             Util.isLinkable(holderClassDoc, writer.configuration))) {
   296             //This is an implementation detail that should not be documented.
   297             return;
   298         }
   299         if (overriddenType.asClassDoc().isIncluded() && ! method.isIncluded()) {
   300             //The class is included but the method is not.  That means that it
   301             //is not visible so don't document this.
   302             return;
   303         }
   304         Content label = writer.overridesLabel;
   305         LinkInfoImpl.Kind context = LinkInfoImpl.Kind.METHOD_OVERRIDES;
   307         if (method != null) {
   308             if (overriddenType.asClassDoc().isAbstract() && method.isAbstract()){
   309                 //Abstract method is implemented from abstract class,
   310                 //not overridden
   311                 label = writer.specifiedByLabel;
   312                 context = LinkInfoImpl.Kind.METHOD_SPECIFIED_BY;
   313             }
   314             Content dt = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.overrideSpecifyLabel, label));
   315             dl.addContent(dt);
   316             Content overriddenTypeLink =
   317                     writer.getLink(new LinkInfoImpl(writer.configuration, context, overriddenType));
   318             Content codeOverridenTypeLink = HtmlTree.CODE(overriddenTypeLink);
   319             String name = method.name();
   320             Content methlink = writer.getLink(
   321                     new LinkInfoImpl(writer.configuration, LinkInfoImpl.Kind.MEMBER,
   322                     overriddenType.asClassDoc())
   323                     .where(writer.getName(writer.getAnchor(method))).label(name));
   324             Content codeMethLink = HtmlTree.CODE(methlink);
   325             Content dd = HtmlTree.DD(codeMethLink);
   326             dd.addContent(writer.getSpace());
   327             dd.addContent(writer.getResource("doclet.in_class"));
   328             dd.addContent(writer.getSpace());
   329             dd.addContent(codeOverridenTypeLink);
   330             dl.addContent(dd);
   331         }
   332     }
   334     /**
   335      * {@inheritDoc}
   336      */
   337     protected static void addImplementsInfo(HtmlDocletWriter writer,
   338             MethodDoc method, Content dl) {
   339         if(writer.configuration.nocomment){
   340             return;
   341         }
   342         ImplementedMethods implementedMethodsFinder =
   343                 new ImplementedMethods(method, writer.configuration);
   344         MethodDoc[] implementedMethods = implementedMethodsFinder.build();
   345         for (int i = 0; i < implementedMethods.length; i++) {
   346             MethodDoc implementedMeth = implementedMethods[i];
   347             Type intfac = implementedMethodsFinder.getMethodHolder(implementedMeth);
   348             Content intfaclink = writer.getLink(new LinkInfoImpl(
   349                     writer.configuration, LinkInfoImpl.Kind.METHOD_SPECIFIED_BY, intfac));
   350             Content codeIntfacLink = HtmlTree.CODE(intfaclink);
   351             Content dt = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.overrideSpecifyLabel, writer.specifiedByLabel));
   352             dl.addContent(dt);
   353             Content methlink = writer.getDocLink(
   354                     LinkInfoImpl.Kind.MEMBER, implementedMeth,
   355                     implementedMeth.name(), false);
   356             Content codeMethLink = HtmlTree.CODE(methlink);
   357             Content dd = HtmlTree.DD(codeMethLink);
   358             dd.addContent(writer.getSpace());
   359             dd.addContent(writer.getResource("doclet.in_interface"));
   360             dd.addContent(writer.getSpace());
   361             dd.addContent(codeIntfacLink);
   362             dl.addContent(dd);
   363         }
   364     }
   366     /**
   367      * Add the return type.
   368      *
   369      * @param method the method being documented.
   370      * @param htmltree the content tree to which the return type will be added
   371      */
   372     protected void addReturnType(MethodDoc method, Content htmltree) {
   373         Type type = method.returnType();
   374         if (type != null) {
   375             Content linkContent = writer.getLink(
   376                     new LinkInfoImpl(configuration, LinkInfoImpl.Kind.RETURN_TYPE, type));
   377             htmltree.addContent(linkContent);
   378             htmltree.addContent(writer.getSpace());
   379         }
   380     }
   382     /**
   383      * {@inheritDoc}
   384      */
   385     protected Content getNavSummaryLink(ClassDoc cd, boolean link) {
   386         if (link) {
   387             if (cd == null) {
   388                 return writer.getHyperLink(
   389                         SectionName.METHOD_SUMMARY,
   390                         writer.getResource("doclet.navMethod"));
   391             } else {
   392                 return writer.getHyperLink(
   393                         SectionName.METHODS_INHERITANCE,
   394                         configuration.getClassName(cd), writer.getResource("doclet.navMethod"));
   395             }
   396         } else {
   397             return writer.getResource("doclet.navMethod");
   398         }
   399     }
   401     /**
   402      * {@inheritDoc}
   403      */
   404     protected void addNavDetailLink(boolean link, Content liNav) {
   405         if (link) {
   406             liNav.addContent(writer.getHyperLink(
   407                     SectionName.METHOD_DETAIL, writer.getResource("doclet.navMethod")));
   408         } else {
   409             liNav.addContent(writer.getResource("doclet.navMethod"));
   410         }
   411     }
   412 }

mercurial