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

Thu, 02 Oct 2008 19:58:40 -0700

author
xdono
date
Thu, 02 Oct 2008 19:58:40 -0700
changeset 117
24a47c3062fe
parent 74
5a9172b251dd
child 184
905e151a185a
permissions
-rw-r--r--

6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell

     1 /*
     2  * Copyright 2003-2008 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  */
    26 package com.sun.tools.doclets.internal.toolkit.builders;
    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.*;
    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 {
    46         /**
    47          * The name of this builder.
    48          */
    49         public static final String NAME = "ConstructorDetails";
    51         /**
    52          * The index of the current field that is being documented at this point
    53          * in time.
    54          */
    55         private int currentMethodIndex;
    57         /**
    58          * The class whose constructors are being documented.
    59          */
    60         private ClassDoc classDoc;
    62         /**
    63          * The visible constructors for the given class.
    64          */
    65         private VisibleMemberMap visibleMemberMap;
    67         /**
    68          * The writer to output the constructor documentation.
    69          */
    70         private ConstructorWriter writer;
    72         /**
    73          * The constructors being documented.
    74          */
    75         private List<ProgramElementDoc> constructors;
    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         }
    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<ProgramElementDoc>(builder.visibleMemberMap.getMembersFor(classDoc));
   108                 for (int i = 0; i < builder.constructors.size(); i++) {
   109                         if (builder.constructors.get(i).isProtected()
   110                                 || builder.constructors.get(i).isPrivate()) {
   111                                 writer.setFoundNonPubConstructor(true);
   112                         }
   113                 }
   114                 if (configuration.getMemberComparator() != null) {
   115                         Collections.sort(
   116                                 builder.constructors,
   117                                 configuration.getMemberComparator());
   118                 }
   119                 return builder;
   120         }
   122         /**
   123          * {@inheritDoc}
   124          */
   125         public String getName() {
   126                 return NAME;
   127         }
   129         /**
   130          * {@inheritDoc}
   131          */
   132         public boolean hasMembersToDocument() {
   133                 return constructors.size() > 0;
   134         }
   136         /**
   137          * {@inheritDoc}
   138          */
   139         public void invokeMethod(
   140                 String methodName,
   141                 Class[] paramClasses,
   142                 Object[] params)
   143                 throws Exception {
   144                 if (DEBUG) {
   145                         configuration.root.printError(
   146                                 "DEBUG: " + this.getClass().getName() + "." + methodName);
   147                 }
   148                 Method method = this.getClass().getMethod(methodName, paramClasses);
   149                 method.invoke(this, params);
   150         }
   152         /**
   153          * Returns a list of constructors that will be documented for the given class.
   154          * This information can be used for doclet specific documentation
   155          * generation.
   156          *
   157          * @return a list of constructors that will be documented.
   158          */
   159         public List members(ClassDoc classDoc) {
   160                 return visibleMemberMap.getMembersFor(classDoc);
   161         }
   163         /**
   164          * Return the constructor writer for this builder.
   165          *
   166          * @return the constructor writer for this builder.
   167          */
   168         public ConstructorWriter getWriter() {
   169                 return writer;
   170         }
   172         /**
   173          * Build the constructor documentation.
   174          *
   175          * @param elements the XML elements that specify how to construct this
   176          *                documentation.
   177          */
   178         public void buildConstructorDoc(List elements) {
   179                 if (writer == null) {
   180                         return;
   181                 }
   182                 for (currentMethodIndex = 0;
   183                         currentMethodIndex < constructors.size();
   184                         currentMethodIndex++) {
   185                         build(elements);
   186                 }
   187         }
   189         /**
   190          * Build the overall header.
   191          */
   192         public void buildHeader() {
   193                 writer.writeHeader(
   194                         classDoc,
   195                         configuration.getText("doclet.Constructor_Detail"));
   196         }
   198         /**
   199          * Build the header for the individual constructor.
   200          */
   201         public void buildConstructorHeader() {
   202                 writer.writeConstructorHeader(
   203                         (ConstructorDoc) constructors.get(currentMethodIndex),
   204                         currentMethodIndex == 0);
   205         }
   207         /**
   208          * Build the signature.
   209          */
   210         public void buildSignature() {
   211                 writer.writeSignature(
   212                         (ConstructorDoc) constructors.get(currentMethodIndex));
   213         }
   215         /**
   216          * Build the deprecation information.
   217          */
   218         public void buildDeprecationInfo() {
   219                 writer.writeDeprecated(
   220                         (ConstructorDoc) constructors.get(currentMethodIndex));
   221         }
   223         /**
   224          * Build the comments for the constructor.  Do nothing if
   225          * {@link Configuration#nocomment} is set to true.
   226          */
   227         public void buildConstructorComments() {
   228                 if (!configuration.nocomment) {
   229                         writer.writeComments(
   230                                 (ConstructorDoc) constructors.get(currentMethodIndex));
   231                 }
   232         }
   234         /**
   235          * Build the tag information.
   236          */
   237         public void buildTagInfo() {
   238                 writer.writeTags((ConstructorDoc) constructors.get(currentMethodIndex));
   239         }
   241         /**
   242          * Build the footer for the individual constructor.
   243          */
   244         public void buildConstructorFooter() {
   245                 writer.writeConstructorFooter();
   246         }
   248         /**
   249          * Build the overall footer.
   250          */
   251         public void buildFooter() {
   252                 writer.writeFooter(classDoc);
   253         }
   254 }

mercurial