langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/ConstructorBuilder.java
changeset 10 06bc494ca11e
child 868 d0f233085cbb
equal deleted inserted replaced
0:fd16c54261b3 10:06bc494ca11e
       
     1 /*
       
     2  * Copyright 2003 Sun Microsystems, Inc.  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.  Sun designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    23  * have any questions.
       
    24  */
       
    25 
       
    26 package com.sun.tools.doclets.internal.toolkit.builders;
       
    27 
       
    28 import com.sun.tools.doclets.internal.toolkit.util.*;
       
    29 import com.sun.tools.doclets.internal.toolkit.*;
       
    30 import com.sun.javadoc.*;
       
    31 import java.lang.reflect.*;
       
    32 import java.util.*;
       
    33 
       
    34 /**
       
    35  * Builds documentation for a constructor.
       
    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  * @since 1.5
       
    43  */
       
    44 public class ConstructorBuilder extends AbstractMemberBuilder {
       
    45 
       
    46         /**
       
    47          * The name of this builder.
       
    48          */
       
    49         public static final String NAME = "ConstructorDetails";
       
    50 
       
    51         /**
       
    52          * The index of the current field that is being documented at this point
       
    53          * in time.
       
    54          */
       
    55         private int currentMethodIndex;
       
    56 
       
    57         /**
       
    58          * The class whose constructors are being documented.
       
    59          */
       
    60         private ClassDoc classDoc;
       
    61 
       
    62         /**
       
    63          * The visible constructors for the given class.
       
    64          */
       
    65         private VisibleMemberMap visibleMemberMap;
       
    66 
       
    67         /**
       
    68          * The writer to output the constructor documentation.
       
    69          */
       
    70         private ConstructorWriter writer;
       
    71 
       
    72         /**
       
    73          * The constructors being documented.
       
    74          */
       
    75         private List constructors;
       
    76 
       
    77         /**
       
    78          * Construct a new ConstructorBuilder.
       
    79          *
       
    80          * @param configuration the current configuration of the
       
    81          *                      doclet.
       
    82          */
       
    83         private ConstructorBuilder(Configuration configuration) {
       
    84                 super(configuration);
       
    85         }
       
    86 
       
    87         /**
       
    88          * Construct a new ConstructorBuilder.
       
    89          *
       
    90          * @param configuration the current configuration of the doclet.
       
    91          * @param classDoc the class whoses members are being documented.
       
    92          * @param writer the doclet specific writer.
       
    93          */
       
    94         public static ConstructorBuilder getInstance(
       
    95                 Configuration configuration,
       
    96                 ClassDoc classDoc,
       
    97                 ConstructorWriter writer) {
       
    98                 ConstructorBuilder builder = new ConstructorBuilder(configuration);
       
    99                 builder.classDoc = classDoc;
       
   100                 builder.writer = writer;
       
   101                 builder.visibleMemberMap =
       
   102                         new VisibleMemberMap(
       
   103                                 classDoc,
       
   104                                 VisibleMemberMap.CONSTRUCTORS,
       
   105                                 configuration.nodeprecated);
       
   106                 builder.constructors =
       
   107                         new ArrayList(builder.visibleMemberMap.getMembersFor(classDoc));
       
   108                 for (int i = 0; i < builder.constructors.size(); i++) {
       
   109                         if (((ProgramElementDoc) (builder.constructors.get(i)))
       
   110                                 .isProtected()
       
   111                                 || ((ProgramElementDoc) (builder.constructors.get(i)))
       
   112                                         .isPrivate()) {
       
   113                                 writer.setFoundNonPubConstructor(true);
       
   114                         }
       
   115                 }
       
   116                 if (configuration.getMemberComparator() != null) {
       
   117                         Collections.sort(
       
   118                                 builder.constructors,
       
   119                                 configuration.getMemberComparator());
       
   120                 }
       
   121                 return builder;
       
   122         }
       
   123 
       
   124         /**
       
   125          * {@inheritDoc}
       
   126          */
       
   127         public String getName() {
       
   128                 return NAME;
       
   129         }
       
   130 
       
   131         /**
       
   132          * {@inheritDoc}
       
   133          */
       
   134         public boolean hasMembersToDocument() {
       
   135                 return constructors.size() > 0;
       
   136         }
       
   137 
       
   138         /**
       
   139          * {@inheritDoc}
       
   140          */
       
   141         public void invokeMethod(
       
   142                 String methodName,
       
   143                 Class[] paramClasses,
       
   144                 Object[] params)
       
   145                 throws Exception {
       
   146                 if (DEBUG) {
       
   147                         configuration.root.printError(
       
   148                                 "DEBUG: " + this.getClass().getName() + "." + methodName);
       
   149                 }
       
   150                 Method method = this.getClass().getMethod(methodName, paramClasses);
       
   151                 method.invoke(this, params);
       
   152         }
       
   153 
       
   154         /**
       
   155          * Returns a list of constructors that will be documented for the given class.
       
   156          * This information can be used for doclet specific documentation
       
   157          * generation.
       
   158          *
       
   159          * @return a list of constructors that will be documented.
       
   160          */
       
   161         public List members(ClassDoc classDoc) {
       
   162                 return visibleMemberMap.getMembersFor(classDoc);
       
   163         }
       
   164 
       
   165         /**
       
   166          * Return the constructor writer for this builder.
       
   167          *
       
   168          * @return the constructor writer for this builder.
       
   169          */
       
   170         public ConstructorWriter getWriter() {
       
   171                 return writer;
       
   172         }
       
   173 
       
   174         /**
       
   175          * Build the constructor documentation.
       
   176          *
       
   177          * @param elements the XML elements that specify how to construct this
       
   178          *                documentation.
       
   179          */
       
   180         public void buildConstructorDoc(List elements) {
       
   181                 if (writer == null) {
       
   182                         return;
       
   183                 }
       
   184                 for (currentMethodIndex = 0;
       
   185                         currentMethodIndex < constructors.size();
       
   186                         currentMethodIndex++) {
       
   187                         build(elements);
       
   188                 }
       
   189         }
       
   190 
       
   191         /**
       
   192          * Build the overall header.
       
   193          */
       
   194         public void buildHeader() {
       
   195                 writer.writeHeader(
       
   196                         classDoc,
       
   197                         configuration.getText("doclet.Constructor_Detail"));
       
   198         }
       
   199 
       
   200         /**
       
   201          * Build the header for the individual constructor.
       
   202          */
       
   203         public void buildConstructorHeader() {
       
   204                 writer.writeConstructorHeader(
       
   205                         (ConstructorDoc) constructors.get(currentMethodIndex),
       
   206                         currentMethodIndex == 0);
       
   207         }
       
   208 
       
   209         /**
       
   210          * Build the signature.
       
   211          */
       
   212         public void buildSignature() {
       
   213                 writer.writeSignature(
       
   214                         (ConstructorDoc) constructors.get(currentMethodIndex));
       
   215         }
       
   216 
       
   217         /**
       
   218          * Build the deprecation information.
       
   219          */
       
   220         public void buildDeprecationInfo() {
       
   221                 writer.writeDeprecated(
       
   222                         (ConstructorDoc) constructors.get(currentMethodIndex));
       
   223         }
       
   224 
       
   225         /**
       
   226          * Build the comments for the constructor.  Do nothing if
       
   227          * {@link Configuration#nocomment} is set to true.
       
   228          */
       
   229         public void buildConstructorComments() {
       
   230                 if (!configuration.nocomment) {
       
   231                         writer.writeComments(
       
   232                                 (ConstructorDoc) constructors.get(currentMethodIndex));
       
   233                 }
       
   234         }
       
   235 
       
   236         /**
       
   237          * Build the tag information.
       
   238          */
       
   239         public void buildTagInfo() {
       
   240                 writer.writeTags((ConstructorDoc) constructors.get(currentMethodIndex));
       
   241         }
       
   242 
       
   243         /**
       
   244          * Build the footer for the individual constructor.
       
   245          */
       
   246         public void buildConstructorFooter() {
       
   247                 writer.writeConstructorFooter();
       
   248         }
       
   249 
       
   250         /**
       
   251          * Build the overall footer.
       
   252          */
       
   253         public void buildFooter() {
       
   254                 writer.writeFooter(classDoc);
       
   255         }
       
   256 }