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

Tue, 09 Oct 2012 19:10:00 -0700

author
jjg
date
Tue, 09 Oct 2012 19:10:00 -0700
changeset 1357
c75be5bc5283
parent 798
4868a36f6fd8
child 1359
25e14ad23cef
permissions
-rw-r--r--

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

mercurial