src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/EnumConstantBuilder.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 enum constants.
    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 EnumConstantBuilder extends AbstractMemberBuilder {
    47     /**
    48      * The class whose enum constants are being documented.
    49      */
    50     private ClassDoc classDoc;
    52     /**
    53      * The visible enum constantss for the given class.
    54      */
    55     private VisibleMemberMap visibleMemberMap;
    57     /**
    58      * The writer to output the enum constants documentation.
    59      */
    60     private EnumConstantWriter writer;
    62     /**
    63      * The list of enum constants being documented.
    64      */
    65     private List<ProgramElementDoc> enumConstants;
    67     /**
    68      * The index of the current enum constant that is being documented at this point
    69      * in time.
    70      */
    71     private int currentEnumConstantsIndex;
    73     /**
    74      * Construct a new EnumConstantsBuilder.
    75      *
    76      * @param configuration the current configuration of the
    77      *                      doclet.
    78      */
    79     private EnumConstantBuilder(Configuration configuration) {
    80         super(configuration);
    81     }
    83     /**
    84      * Construct a new EnumConstantsBuilder.
    85      *
    86      * @param configuration the current configuration of the doclet.
    87      * @param classDoc the class whoses members are being documented.
    88      * @param writer the doclet specific writer.
    89      */
    90     public static EnumConstantBuilder getInstance(
    91             Configuration configuration,
    92             ClassDoc classDoc,
    93             EnumConstantWriter writer) {
    94         EnumConstantBuilder builder = new EnumConstantBuilder(configuration);
    95         builder.classDoc = classDoc;
    96         builder.writer = writer;
    97         builder.visibleMemberMap =
    98                 new VisibleMemberMap(
    99                 classDoc,
   100                 VisibleMemberMap.ENUM_CONSTANTS,
   101                 configuration.nodeprecated);
   102         builder.enumConstants =
   103                 new ArrayList<ProgramElementDoc>(builder.visibleMemberMap.getMembersFor(classDoc));
   104         if (configuration.getMemberComparator() != null) {
   105             Collections.sort(
   106                     builder.enumConstants,
   107                     configuration.getMemberComparator());
   108         }
   109         return builder;
   110     }
   112     /**
   113      * {@inheritDoc}
   114      */
   115     public String getName() {
   116         return "EnumConstantDetails";
   117     }
   119     /**
   120      * Returns a list of enum constants that will be documented for the given class.
   121      * This information can be used for doclet specific documentation
   122      * generation.
   123      *
   124      * @param classDoc the {@link ClassDoc} we want to check.
   125      * @return a list of enum constants that will be documented.
   126      */
   127     public List<ProgramElementDoc> members(ClassDoc classDoc) {
   128         return visibleMemberMap.getMembersFor(classDoc);
   129     }
   131     /**
   132      * Returns the visible member map for the enum constants of this class.
   133      *
   134      * @return the visible member map for the enum constants of this class.
   135      */
   136     public VisibleMemberMap getVisibleMemberMap() {
   137         return visibleMemberMap;
   138     }
   140     /**
   141      * summaryOrder.size()
   142      */
   143     public boolean hasMembersToDocument() {
   144         return enumConstants.size() > 0;
   145     }
   147     /**
   148      * Build the enum constant documentation.
   149      *
   150      * @param node the XML element that specifies which components to document
   151      * @param memberDetailsTree the content tree to which the documentation will be added
   152      */
   153     public void buildEnumConstant(XMLNode node, Content memberDetailsTree) {
   154         if (writer == null) {
   155             return;
   156         }
   157         int size = enumConstants.size();
   158         if (size > 0) {
   159             Content enumConstantsDetailsTree = writer.getEnumConstantsDetailsTreeHeader(
   160                     classDoc, memberDetailsTree);
   161             for (currentEnumConstantsIndex = 0; currentEnumConstantsIndex < size;
   162                     currentEnumConstantsIndex++) {
   163                 Content enumConstantsTree = writer.getEnumConstantsTreeHeader(
   164                         (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
   165                         enumConstantsDetailsTree);
   166                 buildChildren(node, enumConstantsTree);
   167                 enumConstantsDetailsTree.addContent(writer.getEnumConstants(
   168                         enumConstantsTree, (currentEnumConstantsIndex == size - 1)));
   169             }
   170             memberDetailsTree.addContent(
   171                     writer.getEnumConstantsDetails(enumConstantsDetailsTree));
   172         }
   173     }
   175     /**
   176      * Build the signature.
   177      *
   178      * @param node the XML element that specifies which components to document
   179      * @param enumConstantsTree the content tree to which the documentation will be added
   180      */
   181     public void buildSignature(XMLNode node, Content enumConstantsTree) {
   182         enumConstantsTree.addContent(writer.getSignature(
   183                 (FieldDoc) enumConstants.get(currentEnumConstantsIndex)));
   184     }
   186     /**
   187      * Build the deprecation information.
   188      *
   189      * @param node the XML element that specifies which components to document
   190      * @param enumConstantsTree the content tree to which the documentation will be added
   191      */
   192     public void buildDeprecationInfo(XMLNode node, Content enumConstantsTree) {
   193         writer.addDeprecated(
   194                 (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
   195                 enumConstantsTree);
   196     }
   198     /**
   199      * Build the comments for the enum constant.  Do nothing if
   200      * {@link Configuration#nocomment} is set to true.
   201      *
   202      * @param node the XML element that specifies which components to document
   203      * @param enumConstantsTree the content tree to which the documentation will be added
   204      */
   205     public void buildEnumConstantComments(XMLNode node, Content enumConstantsTree) {
   206         if (!configuration.nocomment) {
   207             writer.addComments(
   208                     (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
   209                     enumConstantsTree);
   210         }
   211     }
   213     /**
   214      * Build the tag information.
   215      *
   216      * @param node the XML element that specifies which components to document
   217      * @param enumConstantsTree the content tree to which the documentation will be added
   218      */
   219     public void buildTagInfo(XMLNode node, Content enumConstantsTree) {
   220         writer.addTags(
   221                 (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
   222                 enumConstantsTree);
   223     }
   225     /**
   226      * Return the enum constant writer for this builder.
   227      *
   228      * @return the enum constant writer for this builder.
   229      */
   230     public EnumConstantWriter getWriter() {
   231         return writer;
   232     }
   233 }

mercurial