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

Fri, 18 Jun 2010 21:13:56 -0700

author
jjg
date
Fri, 18 Jun 2010 21:13:56 -0700
changeset 589
4177f5bdd189
parent 554
9d9f26857129
child 766
90af8d87741f
permissions
-rw-r--r--

6961178: Allow doclet.xml to contain XML attributes
Reviewed-by: bpatel

     1 /*
     2  * Copyright (c) 2003, 2008, 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 com.sun.tools.doclets.internal.toolkit.util.*;
    29 import com.sun.tools.doclets.internal.toolkit.*;
    30 import com.sun.javadoc.*;
    31 import java.util.*;
    33 /**
    34  * Builds documentation for a constructor.
    35  *
    36  * This code is not part of an API.
    37  * It is implementation that is subject to change.
    38  * Do not use it as an API
    39  *
    40  * @author Jamie Ho
    41  * @since 1.5
    42  */
    43 public class ConstructorBuilder extends AbstractMemberBuilder {
    45         /**
    46          * The name of this builder.
    47          */
    48         public static final String NAME = "ConstructorDetails";
    50         /**
    51          * The index of the current field that is being documented at this point
    52          * in time.
    53          */
    54         private int currentMethodIndex;
    56         /**
    57          * The class whose constructors are being documented.
    58          */
    59         private ClassDoc classDoc;
    61         /**
    62          * The visible constructors for the given class.
    63          */
    64         private VisibleMemberMap visibleMemberMap;
    66         /**
    67          * The writer to output the constructor documentation.
    68          */
    69         private ConstructorWriter writer;
    71         /**
    72          * The constructors being documented.
    73          */
    74         private List<ProgramElementDoc> constructors;
    76         /**
    77          * Construct a new ConstructorBuilder.
    78          *
    79          * @param configuration the current configuration of the
    80          *                      doclet.
    81          */
    82         private ConstructorBuilder(Configuration configuration) {
    83                 super(configuration);
    84         }
    86         /**
    87          * Construct a new ConstructorBuilder.
    88          *
    89          * @param configuration the current configuration of the doclet.
    90          * @param classDoc the class whoses members are being documented.
    91          * @param writer the doclet specific writer.
    92          */
    93         public static ConstructorBuilder getInstance(
    94                 Configuration configuration,
    95                 ClassDoc classDoc,
    96                 ConstructorWriter writer) {
    97                 ConstructorBuilder builder = new ConstructorBuilder(configuration);
    98                 builder.classDoc = classDoc;
    99                 builder.writer = writer;
   100                 builder.visibleMemberMap =
   101                         new VisibleMemberMap(
   102                                 classDoc,
   103                                 VisibleMemberMap.CONSTRUCTORS,
   104                                 configuration.nodeprecated);
   105                 builder.constructors =
   106                         new ArrayList<ProgramElementDoc>(builder.visibleMemberMap.getMembersFor(classDoc));
   107                 for (int i = 0; i < builder.constructors.size(); i++) {
   108                         if (builder.constructors.get(i).isProtected()
   109                                 || builder.constructors.get(i).isPrivate()) {
   110                                 writer.setFoundNonPubConstructor(true);
   111                         }
   112                 }
   113                 if (configuration.getMemberComparator() != null) {
   114                         Collections.sort(
   115                                 builder.constructors,
   116                                 configuration.getMemberComparator());
   117                 }
   118                 return builder;
   119         }
   121         /**
   122          * {@inheritDoc}
   123          */
   124         public String getName() {
   125                 return NAME;
   126         }
   128         /**
   129          * {@inheritDoc}
   130          */
   131         public boolean hasMembersToDocument() {
   132                 return constructors.size() > 0;
   133         }
   135         /**
   136          * Returns a list of constructors that will be documented for the given class.
   137          * This information can be used for doclet specific documentation
   138          * generation.
   139          *
   140          * @return a list of constructors that will be documented.
   141          */
   142         public List<ProgramElementDoc> members(ClassDoc classDoc) {
   143                 return visibleMemberMap.getMembersFor(classDoc);
   144         }
   146         /**
   147          * Return the constructor writer for this builder.
   148          *
   149          * @return the constructor writer for this builder.
   150          */
   151         public ConstructorWriter getWriter() {
   152                 return writer;
   153         }
   155         /**
   156          * Build the constructor documentation.
   157          *
   158          * @param elements the XML elements that specify how to construct this
   159          *                documentation.
   160          */
   161         public void buildConstructorDoc(XMLNode node) {
   162                 if (writer == null) {
   163                         return;
   164                 }
   165                 for (currentMethodIndex = 0;
   166                         currentMethodIndex < constructors.size();
   167                         currentMethodIndex++) {
   168                         buildChildren(node);
   169                 }
   170         }
   172         /**
   173          * Build the overall header.
   174          */
   175         public void buildHeader(XMLNode node) {
   176                 writer.writeHeader(
   177                         classDoc,
   178                         configuration.getText("doclet.Constructor_Detail"));
   179         }
   181         /**
   182          * Build the header for the individual constructor.
   183          */
   184         public void buildConstructorHeader(XMLNode node) {
   185                 writer.writeConstructorHeader(
   186                         (ConstructorDoc) constructors.get(currentMethodIndex),
   187                         currentMethodIndex == 0);
   188         }
   190         /**
   191          * Build the signature.
   192          */
   193         public void buildSignature(XMLNode node) {
   194                 writer.writeSignature(
   195                         (ConstructorDoc) constructors.get(currentMethodIndex));
   196         }
   198         /**
   199          * Build the deprecation information.
   200          */
   201         public void buildDeprecationInfo(XMLNode node) {
   202                 writer.writeDeprecated(
   203                         (ConstructorDoc) constructors.get(currentMethodIndex));
   204         }
   206         /**
   207          * Build the comments for the constructor.  Do nothing if
   208          * {@link Configuration#nocomment} is set to true.
   209          */
   210         public void buildConstructorComments(XMLNode node) {
   211                 if (!configuration.nocomment) {
   212                         writer.writeComments(
   213                                 (ConstructorDoc) constructors.get(currentMethodIndex));
   214                 }
   215         }
   217         /**
   218          * Build the tag information.
   219          */
   220         public void buildTagInfo(XMLNode node) {
   221                 writer.writeTags((ConstructorDoc) constructors.get(currentMethodIndex));
   222         }
   224         /**
   225          * Build the footer for the individual constructor.
   226          */
   227         public void buildConstructorFooter(XMLNode node) {
   228                 writer.writeConstructorFooter();
   229         }
   231         /**
   232          * Build the overall footer.
   233          */
   234         public void buildFooter(XMLNode node) {
   235                 writer.writeFooter(classDoc);
   236         }
   237 }

mercurial