src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/MethodBuilder.java

Wed, 31 Oct 2012 13:48:15 -0700

author
jjg
date
Wed, 31 Oct 2012 13:48:15 -0700
changeset 1383
b980e8e6aabf
parent 1359
25e14ad23cef
child 1410
bfec2a1cc869
permissions
-rw-r--r--

8001664: refactor javadoc to use abstraction to handle files
Reviewed-by: darcy

     1 /*
     2  * Copyright (c) 2003, 2012, 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.internal.toolkit.builders;
    28 import java.util.*;
    30 import com.sun.javadoc.*;
    31 import com.sun.tools.doclets.internal.toolkit.*;
    32 import com.sun.tools.doclets.internal.toolkit.util.*;
    34 /**
    35  * Builds documentation for a method.
    36  *
    37  *  <p><b>This is NOT part of any supported API.
    38  *  If you write code that depends on this, you do so at your own risk.
    39  *  This code and its internal interfaces are subject to change or
    40  *  deletion without notice.</b>
    41  *
    42  * @author Jamie Ho
    43  * @author Bhavesh Patel (Modified)
    44  * @since 1.5
    45  */
    46 public class MethodBuilder extends AbstractMemberBuilder {
    48     /**
    49      * The index of the current field that is being documented at this point
    50      * in time.
    51      */
    52     private int currentMethodIndex;
    54     /**
    55      * The class whose methods are being documented.
    56      */
    57     private ClassDoc classDoc;
    59     /**
    60      * The visible methods for the given class.
    61      */
    62     private VisibleMemberMap visibleMemberMap;
    64     /**
    65      * The writer to output the method documentation.
    66      */
    67     private MethodWriter writer;
    69     /**
    70      * The methods being documented.
    71      */
    72     private List<ProgramElementDoc> methods;
    74     private MethodBuilder(Configuration configuration) {
    75         super(configuration);
    76     }
    78     /**
    79      * Construct a new MethodBuilder.
    80      *
    81      * @param configuration the current configuration of the doclet.
    82      * @param classDoc the class whoses members are being documented.
    83      * @param writer the doclet specific writer.
    84      *
    85      * @return an instance of a MethodBuilder.
    86      */
    87     public static MethodBuilder getInstance(
    88             Configuration configuration,
    89             ClassDoc classDoc,
    90             MethodWriter writer) {
    91         MethodBuilder builder = new MethodBuilder(configuration);
    92         builder.classDoc = classDoc;
    93         builder.writer = writer;
    94         builder.visibleMemberMap =
    95                 new VisibleMemberMap(
    96                 classDoc,
    97                 VisibleMemberMap.METHODS,
    98                 configuration.nodeprecated);
    99         builder.methods =
   100                 new ArrayList<ProgramElementDoc>(builder.visibleMemberMap.getLeafClassMembers(
   101                 configuration));
   102         if (configuration.getMemberComparator() != null) {
   103             Collections.sort(
   104                     builder.methods,
   105                     configuration.getMemberComparator());
   106         }
   107         return builder;
   108     }
   110     /**
   111      * {@inheritDoc}
   112      */
   113     public String getName() {
   114         return "MethodDetails";
   115     }
   117     /**
   118      * Returns a list of methods that will be documented for the given class.
   119      * This information can be used for doclet specific documentation
   120      * generation.
   121      *
   122      * @param classDoc the {@link ClassDoc} we want to check.
   123      * @return a list of methods that will be documented.
   124      */
   125     public List<ProgramElementDoc> members(ClassDoc classDoc) {
   126         return visibleMemberMap.getMembersFor(classDoc);
   127     }
   129     /**
   130      * Returns the visible member map for the methods of this class.
   131      *
   132      * @return the visible member map for the methods of this class.
   133      */
   134     public VisibleMemberMap getVisibleMemberMap() {
   135         return visibleMemberMap;
   136     }
   138     /**
   139      * {@inheritDoc}
   140      */
   141     public boolean hasMembersToDocument() {
   142         return methods.size() > 0;
   143     }
   145     /**
   146      * Build the method documentation.
   147      *
   148      * @param node the XML element that specifies which components to document
   149      * @param memberDetailsTree the content tree to which the documentation will be added
   150      */
   151     public void buildMethodDoc(XMLNode node, Content memberDetailsTree) {
   152         if (writer == null) {
   153             return;
   154         }
   155         int size = methods.size();
   156         if (size > 0) {
   157             Content methodDetailsTree = writer.getMethodDetailsTreeHeader(
   158                     classDoc, memberDetailsTree);
   159             for (currentMethodIndex = 0; currentMethodIndex < size;
   160                     currentMethodIndex++) {
   161                 Content methodDocTree = writer.getMethodDocTreeHeader(
   162                         (MethodDoc) methods.get(currentMethodIndex),
   163                         methodDetailsTree);
   164                 buildChildren(node, methodDocTree);
   165                 methodDetailsTree.addContent(writer.getMethodDoc(
   166                         methodDocTree, (currentMethodIndex == size - 1)));
   167             }
   168             memberDetailsTree.addContent(
   169                     writer.getMethodDetails(methodDetailsTree));
   170         }
   171     }
   173     /**
   174      * Build the signature.
   175      *
   176      * @param node the XML element that specifies which components to document
   177      * @param methodDocTree the content tree to which the documentation will be added
   178      */
   179     public void buildSignature(XMLNode node, Content methodDocTree) {
   180         methodDocTree.addContent(
   181                 writer.getSignature((MethodDoc) methods.get(currentMethodIndex)));
   182     }
   184     /**
   185      * Build the deprecation information.
   186      *
   187      * @param node the XML element that specifies which components to document
   188      * @param methodDocTree the content tree to which the documentation will be added
   189      */
   190     public void buildDeprecationInfo(XMLNode node, Content methodDocTree) {
   191         writer.addDeprecated(
   192                 (MethodDoc) methods.get(currentMethodIndex), methodDocTree);
   193     }
   195     /**
   196      * Build the comments for the method.  Do nothing if
   197      * {@link Configuration#nocomment} is set to true.
   198      *
   199      * @param node the XML element that specifies which components to document
   200      * @param methodDocTree the content tree to which the documentation will be added
   201      */
   202     public void buildMethodComments(XMLNode node, Content methodDocTree) {
   203         if (!configuration.nocomment) {
   204             MethodDoc method = (MethodDoc) methods.get(currentMethodIndex);
   206             if (method.inlineTags().length == 0) {
   207                 DocFinder.Output docs = DocFinder.search(
   208                         new DocFinder.Input(method));
   209                 method = docs.inlineTags != null && docs.inlineTags.length > 0 ?
   210                     (MethodDoc) docs.holder : method;
   211             }
   212             //NOTE:  When we fix the bug where ClassDoc.interfaceTypes() does
   213             //       not pass all implemented interfaces, holder will be the
   214             //       interface type.  For now, it is really the erasure.
   215             writer.addComments(method.containingClass(), method, methodDocTree);
   216         }
   217     }
   219     /**
   220      * Build the tag information.
   221      *
   222      * @param node the XML element that specifies which components to document
   223      * @param methodDocTree the content tree to which the documentation will be added
   224      */
   225     public void buildTagInfo(XMLNode node, Content methodDocTree) {
   226         writer.addTags((MethodDoc) methods.get(currentMethodIndex),
   227                 methodDocTree);
   228     }
   230     /**
   231      * Return the method writer for this builder.
   232      *
   233      * @return the method writer for this builder.
   234      */
   235     public MethodWriter getWriter() {
   236         return writer;
   237     }
   238 }

mercurial