src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/ConstructorBuilder.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 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  * @author Bhavesh Patel (Modified)
    43  * @since 1.5
    44  */
    45 public class ConstructorBuilder extends AbstractMemberBuilder {
    47     /**
    48      * The name of this builder.
    49      */
    50     public static final String NAME = "ConstructorDetails";
    52     /**
    53      * The index of the current field that is being documented at this point
    54      * in time.
    55      */
    56     private int currentConstructorIndex;
    58     /**
    59      * The class whose constructors are being documented.
    60      */
    61     private ClassDoc classDoc;
    63     /**
    64      * The visible constructors for the given class.
    65      */
    66     private VisibleMemberMap visibleMemberMap;
    68     /**
    69      * The writer to output the constructor documentation.
    70      */
    71     private ConstructorWriter writer;
    73     /**
    74      * The constructors being documented.
    75      */
    76     private List<ProgramElementDoc> constructors;
    78     /**
    79      * Construct a new ConstructorBuilder.
    80      *
    81      * @param configuration the current configuration of the
    82      *                      doclet.
    83      */
    84     private ConstructorBuilder(Configuration configuration) {
    85         super(configuration);
    86     }
    88     /**
    89      * Construct a new ConstructorBuilder.
    90      *
    91      * @param configuration the current configuration of the doclet.
    92      * @param classDoc the class whoses members are being documented.
    93      * @param writer the doclet specific writer.
    94      */
    95     public static ConstructorBuilder getInstance(
    96             Configuration configuration,
    97             ClassDoc classDoc,
    98             ConstructorWriter writer) {
    99         ConstructorBuilder builder = new ConstructorBuilder(configuration);
   100         builder.classDoc = classDoc;
   101         builder.writer = writer;
   102         builder.visibleMemberMap =
   103                 new VisibleMemberMap(
   104                 classDoc,
   105                 VisibleMemberMap.CONSTRUCTORS,
   106                 configuration.nodeprecated);
   107         builder.constructors =
   108                 new ArrayList<ProgramElementDoc>(builder.visibleMemberMap.getMembersFor(classDoc));
   109         for (int i = 0; i < builder.constructors.size(); i++) {
   110             if (builder.constructors.get(i).isProtected()
   111                     || builder.constructors.get(i).isPrivate()) {
   112                 writer.setFoundNonPubConstructor(true);
   113             }
   114         }
   115         if (configuration.getMemberComparator() != null) {
   116             Collections.sort(
   117                     builder.constructors,
   118                     configuration.getMemberComparator());
   119         }
   120         return builder;
   121     }
   123     /**
   124      * {@inheritDoc}
   125      */
   126     public String getName() {
   127         return NAME;
   128     }
   130     /**
   131      * {@inheritDoc}
   132      */
   133     public boolean hasMembersToDocument() {
   134         return constructors.size() > 0;
   135     }
   137     /**
   138      * Returns a list of constructors that will be documented for the given class.
   139      * This information can be used for doclet specific documentation
   140      * generation.
   141      *
   142      * @return a list of constructors that will be documented.
   143      */
   144     public List<ProgramElementDoc> members(ClassDoc classDoc) {
   145         return visibleMemberMap.getMembersFor(classDoc);
   146     }
   148     /**
   149      * Return the constructor writer for this builder.
   150      *
   151      * @return the constructor writer for this builder.
   152      */
   153     public ConstructorWriter getWriter() {
   154         return writer;
   155     }
   157     /**
   158      * Build the constructor documentation.
   159      *
   160      * @param node the XML element that specifies which components to document
   161      * @param memberDetailsTree the content tree to which the documentation will be added
   162      */
   163     public void buildConstructorDoc(XMLNode node, Content memberDetailsTree) {
   164         if (writer == null) {
   165             return;
   166         }
   167         int size = constructors.size();
   168         if (size > 0) {
   169             Content constructorDetailsTree = writer.getConstructorDetailsTreeHeader(
   170                     classDoc, memberDetailsTree);
   171             for (currentConstructorIndex = 0; currentConstructorIndex < size;
   172                     currentConstructorIndex++) {
   173                 Content constructorDocTree = writer.getConstructorDocTreeHeader(
   174                         (ConstructorDoc) constructors.get(currentConstructorIndex),
   175                         constructorDetailsTree);
   176                 buildChildren(node, constructorDocTree);
   177                 constructorDetailsTree.addContent(writer.getConstructorDoc(
   178                         constructorDocTree, (currentConstructorIndex == size - 1)));
   179             }
   180             memberDetailsTree.addContent(
   181                     writer.getConstructorDetails(constructorDetailsTree));
   182         }
   183     }
   185     /**
   186      * Build the signature.
   187      *
   188      * @param node the XML element that specifies which components to document
   189      * @param constructorDocTree the content tree to which the documentation will be added
   190      */
   191     public void buildSignature(XMLNode node, Content constructorDocTree) {
   192         constructorDocTree.addContent(
   193                 writer.getSignature(
   194                 (ConstructorDoc) constructors.get(currentConstructorIndex)));
   195     }
   197     /**
   198      * Build the deprecation information.
   199      *
   200      * @param node the XML element that specifies which components to document
   201      * @param constructorDocTree the content tree to which the documentation will be added
   202      */
   203     public void buildDeprecationInfo(XMLNode node, Content constructorDocTree) {
   204         writer.addDeprecated(
   205                 (ConstructorDoc) constructors.get(currentConstructorIndex), constructorDocTree);
   206     }
   208     /**
   209      * Build the comments for the constructor.  Do nothing if
   210      * {@link Configuration#nocomment} is set to true.
   211      *
   212      * @param node the XML element that specifies which components to document
   213      * @param constructorDocTree the content tree to which the documentation will be added
   214      */
   215     public void buildConstructorComments(XMLNode node, Content constructorDocTree) {
   216         if (!configuration.nocomment) {
   217             writer.addComments(
   218                     (ConstructorDoc) constructors.get(currentConstructorIndex),
   219                     constructorDocTree);
   220         }
   221     }
   223     /**
   224      * Build the tag information.
   225      *
   226      * @param node the XML element that specifies which components to document
   227      * @param constructorDocTree the content tree to which the documentation will be added
   228      */
   229     public void buildTagInfo(XMLNode node, Content constructorDocTree) {
   230         writer.addTags((ConstructorDoc) constructors.get(currentConstructorIndex),
   231                 constructorDocTree);
   232     }
   233 }

mercurial