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

Fri, 04 Mar 2011 19:53:03 -0800

author
jjg
date
Fri, 04 Mar 2011 19:53:03 -0800
changeset 910
ebf7c13df6c0
parent 798
4868a36f6fd8
child 1359
25e14ad23cef
permissions
-rw-r--r--

6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
Reviewed-by: bpatel

     1 /*
     2  * Copyright (c) 1997, 2010, 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.*;
    35 /**
    36  * Writes method documentation in HTML format.
    37  *
    38  * @author Robert Field
    39  * @author Atul M Dambalkar
    40  * @author Jamie Ho (rewrite)
    41  * @author Bhavesh Patel (Modified)
    42  */
    43 public class MethodWriterImpl extends AbstractExecutableMemberWriter
    44         implements MethodWriter, MemberSummaryWriter {
    46     /**
    47      * Construct a new MethodWriterImpl.
    48      *
    49      * @param writer the writer for the class that the methods belong to.
    50      * @param classDoc the class being documented.
    51      */
    52     public MethodWriterImpl(SubWriterHolderWriter writer, ClassDoc classDoc) {
    53         super(writer, classDoc);
    54     }
    56     /**
    57      * Construct a new MethodWriterImpl.
    58      *
    59      * @param writer The writer for the class that the methods belong to.
    60      */
    61     public MethodWriterImpl(SubWriterHolderWriter writer) {
    62         super(writer);
    63     }
    65     /**
    66      * {@inheritDoc}
    67      */
    68     public Content getMemberSummaryHeader(ClassDoc classDoc,
    69             Content memberSummaryTree) {
    70         memberSummaryTree.addContent(HtmlConstants.START_OF_METHOD_SUMMARY);
    71         Content memberTree = writer.getMemberTreeHeader();
    72         writer.addSummaryHeader(this, classDoc, memberTree);
    73         return memberTree;
    74     }
    76     /**
    77      * {@inheritDoc}
    78      */
    79     public Content getMethodDetailsTreeHeader(ClassDoc classDoc,
    80             Content memberDetailsTree) {
    81         memberDetailsTree.addContent(HtmlConstants.START_OF_METHOD_DETAILS);
    82         Content methodDetailsTree = writer.getMemberTreeHeader();
    83         methodDetailsTree.addContent(writer.getMarkerAnchor("method_detail"));
    84         Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING,
    85                 writer.methodDetailsLabel);
    86         methodDetailsTree.addContent(heading);
    87         return methodDetailsTree;
    88     }
    90     /**
    91      * {@inheritDoc}
    92      */
    93     public Content getMethodDocTreeHeader(MethodDoc method,
    94             Content methodDetailsTree) {
    95         String erasureAnchor;
    96         if ((erasureAnchor = getErasureAnchor(method)) != null) {
    97             methodDetailsTree.addContent(writer.getMarkerAnchor((erasureAnchor)));
    98         }
    99         methodDetailsTree.addContent(
   100                 writer.getMarkerAnchor(writer.getAnchor(method)));
   101         Content methodDocTree = writer.getMemberTreeHeader();
   102         Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING);
   103         heading.addContent(method.name());
   104         methodDocTree.addContent(heading);
   105         return methodDocTree;
   106     }
   108     /**
   109      * Get the signature for the given method.
   110      *
   111      * @param method the method being documented.
   112      * @return a content object for the signature
   113      */
   114     public Content getSignature(MethodDoc method) {
   115         writer.displayLength = 0;
   116         Content pre = new HtmlTree(HtmlTag.PRE);
   117         writer.addAnnotationInfo(method, pre);
   118         addModifiers(method, pre);
   119         addTypeParameters(method, pre);
   120         addReturnType(method, pre);
   121         if (configuration().linksource) {
   122             Content methodName = new StringContent(method.name());
   123             writer.addSrcLink(method, methodName, pre);
   124         } else {
   125             addName(method.name(), pre);
   126         }
   127         addParameters(method, pre);
   128         addExceptions(method, pre);
   129         return pre;
   130     }
   132     /**
   133      * {@inheritDoc}
   134      */
   135     public void addDeprecated(MethodDoc method, Content methodDocTree) {
   136         addDeprecatedInfo(method, methodDocTree);
   137     }
   139     /**
   140      * {@inheritDoc}
   141      */
   142     public void addComments(Type holder, MethodDoc method, Content methodDocTree) {
   143         ClassDoc holderClassDoc = holder.asClassDoc();
   144         if (method.inlineTags().length > 0) {
   145             if (holder.asClassDoc().equals(classdoc) ||
   146                     (! (holderClassDoc.isPublic() ||
   147                     Util.isLinkable(holderClassDoc, configuration())))) {
   148                 writer.addInlineComment(method, methodDocTree);
   149             } else {
   150                 Content link = new RawHtml(
   151                         writer.getDocLink(LinkInfoImpl.CONTEXT_METHOD_DOC_COPY,
   152                         holder.asClassDoc(), method,
   153                         holder.asClassDoc().isIncluded() ?
   154                             holder.typeName() : holder.qualifiedTypeName(),
   155                             false));
   156                 Content codelLink = HtmlTree.CODE(link);
   157                 Content strong = HtmlTree.STRONG(holder.asClassDoc().isClass()?
   158                     writer.descfrmClassLabel : writer.descfrmInterfaceLabel);
   159                 strong.addContent(writer.getSpace());
   160                 strong.addContent(codelLink);
   161                 methodDocTree.addContent(HtmlTree.DIV(HtmlStyle.block, strong));
   162                 writer.addInlineComment(method, methodDocTree);
   163             }
   164         }
   165     }
   167     /**
   168      * {@inheritDoc}
   169      */
   170     public void addTags(MethodDoc method, Content methodDocTree) {
   171         writer.addTagsInfo(method, methodDocTree);
   172     }
   174     /**
   175      * {@inheritDoc}
   176      */
   177     public Content getMethodDetails(Content methodDetailsTree) {
   178         return getMemberTree(methodDetailsTree);
   179     }
   181     /**
   182      * {@inheritDoc}
   183      */
   184     public Content getMethodDoc(Content methodDocTree,
   185             boolean isLastContent) {
   186         return getMemberTree(methodDocTree, isLastContent);
   187     }
   189     /**
   190      * Close the writer.
   191      */
   192     public void close() throws IOException {
   193         writer.close();
   194     }
   196     public int getMemberKind() {
   197         return VisibleMemberMap.METHODS;
   198     }
   200     /**
   201      * {@inheritDoc}
   202      */
   203     public void addSummaryLabel(Content memberTree) {
   204         Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING,
   205                 writer.getResource("doclet.Method_Summary"));
   206         memberTree.addContent(label);
   207     }
   209     /**
   210      * {@inheritDoc}
   211      */
   212     public String getTableSummary() {
   213         return configuration().getText("doclet.Member_Table_Summary",
   214                 configuration().getText("doclet.Method_Summary"),
   215                 configuration().getText("doclet.methods"));
   216     }
   218     /**
   219      * {@inheritDoc}
   220      */
   221     public String getCaption() {
   222         return configuration().getText("doclet.Methods");
   223     }
   225     /**
   226      * {@inheritDoc}
   227      */
   228     public String[] getSummaryTableHeader(ProgramElementDoc member) {
   229         String[] header = new String[] {
   230             writer.getModifierTypeHeader(),
   231             configuration().getText("doclet.0_and_1",
   232                     configuration().getText("doclet.Method"),
   233                     configuration().getText("doclet.Description"))
   234         };
   235         return header;
   236     }
   238     /**
   239      * {@inheritDoc}
   240      */
   241     public void addSummaryAnchor(ClassDoc cd, Content memberTree) {
   242         memberTree.addContent(writer.getMarkerAnchor("method_summary"));
   243     }
   245     /**
   246      * {@inheritDoc}
   247      */
   248     public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) {
   249         inheritedTree.addContent(writer.getMarkerAnchor(
   250                 "methods_inherited_from_class_" +
   251                 configuration().getClassName(cd)));
   252     }
   254     /**
   255      * {@inheritDoc}
   256      */
   257     public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) {
   258         Content classLink = new RawHtml(writer.getPreQualifiedClassLink(
   259                 LinkInfoImpl.CONTEXT_MEMBER, cd, false));
   260         Content label = new StringContent(cd.isClass() ?
   261             configuration().getText("doclet.Methods_Inherited_From_Class") :
   262             configuration().getText("doclet.Methods_Inherited_From_Interface"));
   263         Content labelHeading = HtmlTree.HEADING(HtmlConstants.INHERITED_SUMMARY_HEADING,
   264                 label);
   265         labelHeading.addContent(writer.getSpace());
   266         labelHeading.addContent(classLink);
   267         inheritedTree.addContent(labelHeading);
   268     }
   270     /**
   271      * {@inheritDoc}
   272      */
   273     protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) {
   274         MethodDoc meth = (MethodDoc)member;
   275         addModifierAndType(meth, meth.returnType(), tdSummaryType);
   276     }
   278     /**
   279      * {@inheritDoc}
   280      */
   281     protected static void addOverridden(HtmlDocletWriter writer,
   282             Type overriddenType, MethodDoc method, Content dl) {
   283         if(writer.configuration.nocomment){
   284             return;
   285         }
   286         ClassDoc holderClassDoc = overriddenType.asClassDoc();
   287         if (! (holderClassDoc.isPublic() ||
   288             Util.isLinkable(holderClassDoc, writer.configuration()))) {
   289             //This is an implementation detail that should not be documented.
   290             return;
   291         }
   292         if (overriddenType.asClassDoc().isIncluded() && ! method.isIncluded()) {
   293             //The class is included but the method is not.  That means that it
   294             //is not visible so don't document this.
   295             return;
   296         }
   297         Content label = writer.overridesLabel;
   298         int context = LinkInfoImpl.CONTEXT_METHOD_OVERRIDES;
   300         if (method != null) {
   301             if(overriddenType.asClassDoc().isAbstract() && method.isAbstract()){
   302                 //Abstract method is implemented from abstract class,
   303                 //not overridden
   304                 label = writer.specifiedByLabel;
   305                 context = LinkInfoImpl.CONTEXT_METHOD_SPECIFIED_BY;
   306             }
   307             Content dt = HtmlTree.DT(HtmlTree.STRONG(label));
   308             dl.addContent(dt);
   309             Content overriddenTypeLink = new RawHtml(
   310                     writer.getLink(new LinkInfoImpl(context, overriddenType)));
   311             Content codeOverridenTypeLink = HtmlTree.CODE(overriddenTypeLink);
   312             String name = method.name();
   313             Content methlink = new RawHtml(writer.getLink(
   314                     new LinkInfoImpl(LinkInfoImpl.CONTEXT_MEMBER,
   315                     overriddenType.asClassDoc(),
   316                     writer.getAnchor(method), name, false)));
   317             Content codeMethLink = HtmlTree.CODE(methlink);
   318             Content dd = HtmlTree.DD(codeMethLink);
   319             dd.addContent(writer.getSpace());
   320             dd.addContent(writer.getResource("doclet.in_class"));
   321             dd.addContent(writer.getSpace());
   322             dd.addContent(codeOverridenTypeLink);
   323             dl.addContent(dd);
   324         }
   325     }
   327     /**
   328      * Parse the <Code> tag and return the text.
   329      */
   330     protected String parseCodeTag(String tag){
   331         if(tag == null){
   332             return "";
   333         }
   335         String lc = tag.toLowerCase();
   336         int begin = lc.indexOf("<code>");
   337         int end = lc.indexOf("</code>");
   338         if(begin == -1 || end == -1 || end <= begin){
   339             return tag;
   340         } else {
   341             return tag.substring(begin + 6, end);
   342         }
   343     }
   345     /**
   346      * {@inheritDoc}
   347      */
   348     protected static void addImplementsInfo(HtmlDocletWriter writer,
   349             MethodDoc method, Content dl) {
   350         if(writer.configuration.nocomment){
   351             return;
   352         }
   353         ImplementedMethods implementedMethodsFinder =
   354                 new ImplementedMethods(method, writer.configuration);
   355         MethodDoc[] implementedMethods = implementedMethodsFinder.build();
   356         for (int i = 0; i < implementedMethods.length; i++) {
   357             MethodDoc implementedMeth = implementedMethods[i];
   358             Type intfac = implementedMethodsFinder.getMethodHolder(implementedMeth);
   359             Content intfaclink = new RawHtml(writer.getLink(new LinkInfoImpl(
   360                     LinkInfoImpl.CONTEXT_METHOD_SPECIFIED_BY, intfac)));
   361             Content codeIntfacLink = HtmlTree.CODE(intfaclink);
   362             Content dt = HtmlTree.DT(HtmlTree.STRONG(writer.specifiedByLabel));
   363             dl.addContent(dt);
   364             Content methlink = new RawHtml(writer.getDocLink(
   365                     LinkInfoImpl.CONTEXT_MEMBER, implementedMeth,
   366                     implementedMeth.name(), false));
   367             Content codeMethLink = HtmlTree.CODE(methlink);
   368             Content dd = HtmlTree.DD(codeMethLink);
   369             dd.addContent(writer.getSpace());
   370             dd.addContent(writer.getResource("doclet.in_interface"));
   371             dd.addContent(writer.getSpace());
   372             dd.addContent(codeIntfacLink);
   373             dl.addContent(dd);
   374         }
   375     }
   377     /**
   378      * Add the return type.
   379      *
   380      * @param method the method being documented.
   381      * @param htmltree the content tree to which the return type will be added
   382      */
   383     protected void addReturnType(MethodDoc method, Content htmltree) {
   384         Type type = method.returnType();
   385         if (type != null) {
   386             Content linkContent = new RawHtml(writer.getLink(
   387                     new LinkInfoImpl(LinkInfoImpl.CONTEXT_RETURN_TYPE, type)));
   388             htmltree.addContent(linkContent);
   389             htmltree.addContent(writer.getSpace());
   390         }
   391     }
   393     /**
   394      * {@inheritDoc}
   395      */
   396     protected Content getNavSummaryLink(ClassDoc cd, boolean link) {
   397         if (link) {
   398             return writer.getHyperLink("", (cd == null)?
   399                 "method_summary":
   400                 "methods_inherited_from_class_" +
   401                 configuration().getClassName(cd),
   402                 writer.getResource("doclet.navMethod"));
   403         } else {
   404             return writer.getResource("doclet.navMethod");
   405         }
   406     }
   408     /**
   409      * {@inheritDoc}
   410      */
   411     protected void addNavDetailLink(boolean link, Content liNav) {
   412         if (link) {
   413             liNav.addContent(writer.getHyperLink("", "method_detail",
   414                     writer.getResource("doclet.navMethod")));
   415         } else {
   416             liNav.addContent(writer.getResource("doclet.navMethod"));
   417         }
   418     }
   419 }

mercurial