src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/EnumConstantBuilder.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 enum constants.
    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 EnumConstantBuilder extends AbstractMemberBuilder {
    45         /**
    46          * The class whose enum constants are being documented.
    47          */
    48         private ClassDoc classDoc;
    50         /**
    51          * The visible enum constantss for the given class.
    52          */
    53         private VisibleMemberMap visibleMemberMap;
    55         /**
    56          * The writer to output the enum constants documentation.
    57          */
    58         private EnumConstantWriter writer;
    60         /**
    61          * The list of enum constants being documented.
    62          */
    63         private List<ProgramElementDoc> enumConstants;
    65         /**
    66          * The index of the current enum constant that is being documented at this point
    67          * in time.
    68          */
    69         private int currentEnumConstantsIndex;
    71         /**
    72          * Construct a new EnumConstantsBuilder.
    73          *
    74          * @param configuration the current configuration of the
    75          *                      doclet.
    76          */
    77         private EnumConstantBuilder(Configuration configuration) {
    78                 super(configuration);
    79         }
    81         /**
    82          * Construct a new EnumConstantsBuilder.
    83          *
    84          * @param configuration the current configuration of the doclet.
    85          * @param classDoc the class whoses members are being documented.
    86          * @param writer the doclet specific writer.
    87          */
    88         public static EnumConstantBuilder getInstance(
    89                 Configuration configuration,
    90                 ClassDoc classDoc,
    91                 EnumConstantWriter writer) {
    92                 EnumConstantBuilder builder = new EnumConstantBuilder(configuration);
    93                 builder.classDoc = classDoc;
    94                 builder.writer = writer;
    95                 builder.visibleMemberMap =
    96                         new VisibleMemberMap(
    97                                 classDoc,
    98                                 VisibleMemberMap.ENUM_CONSTANTS,
    99                                 configuration.nodeprecated);
   100                 builder.enumConstants =
   101                         new ArrayList<ProgramElementDoc>(builder.visibleMemberMap.getMembersFor(classDoc));
   102                 if (configuration.getMemberComparator() != null) {
   103                         Collections.sort(
   104                                 builder.enumConstants,
   105                                 configuration.getMemberComparator());
   106                 }
   107                 return builder;
   108         }
   110         /**
   111          * {@inheritDoc}
   112          */
   113         public String getName() {
   114                 return "EnumConstantDetails";
   115         }
   117         /**
   118          * Returns a list of enum constants that will be documented for the given class.
   119          * This information can be used for doclet specific documentation
   120          * generation.
   121          *
   122          * @param classDoc the {@link ClassDoc} we want to check.
   123          * @return a list of enum constants that will be documented.
   124          */
   125         public List<ProgramElementDoc> members(ClassDoc classDoc) {
   126                 return visibleMemberMap.getMembersFor(classDoc);
   127         }
   129         /**
   130          * Returns the visible member map for the enum constants of this class.
   131          *
   132          * @return the visible member map for the enum constants of this class.
   133          */
   134         public VisibleMemberMap getVisibleMemberMap() {
   135                 return visibleMemberMap;
   136         }
   138         /**
   139          * summaryOrder.size()
   140          */
   141         public boolean hasMembersToDocument() {
   142                 return enumConstants.size() > 0;
   143         }
   145         /**
   146          * Build the enum constant documentation.
   147          *
   148          * @param elements the XML elements that specify how to construct this
   149          *                documentation.
   150          */
   151         public void buildEnumConstant(XMLNode node) {
   152                 if (writer == null) {
   153                         return;
   154                 }
   155                 for (currentEnumConstantsIndex = 0;
   156                         currentEnumConstantsIndex < enumConstants.size();
   157                         currentEnumConstantsIndex++) {
   158                         buildChildren(node);
   159                 }
   160         }
   162         /**
   163          * Build the overall header.
   164          */
   165         public void buildHeader(XMLNode node) {
   166                 writer.writeHeader(
   167                         classDoc,
   168                         configuration.getText("doclet.Enum_Constant_Detail"));
   169         }
   171         /**
   172          * Build the header for the individual enum constants.
   173          */
   174         public void buildEnumConstantHeader(XMLNode node) {
   175                 writer.writeEnumConstantHeader(
   176                         (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
   177                         currentEnumConstantsIndex == 0);
   178         }
   180         /**
   181          * Build the signature.
   182          */
   183         public void buildSignature(XMLNode node) {
   184                 writer.writeSignature(
   185                         (FieldDoc) enumConstants.get(currentEnumConstantsIndex));
   186         }
   188         /**
   189          * Build the deprecation information.
   190          */
   191         public void buildDeprecationInfo(XMLNode node) {
   192                 writer.writeDeprecated(
   193                         (FieldDoc) enumConstants.get(currentEnumConstantsIndex));
   194         }
   196         /**
   197          * Build the comments for the enum constant.  Do nothing if
   198          * {@link Configuration#nocomment} is set to true.
   199          */
   200         public void buildEnumConstantComments(XMLNode node) {
   201                 if (!configuration.nocomment) {
   202                         writer.writeComments(
   203                                 (FieldDoc) enumConstants.get(currentEnumConstantsIndex));
   204                 }
   205         }
   207         /**
   208          * Build the tag information.
   209          */
   210         public void buildTagInfo(XMLNode node) {
   211                 writer.writeTags(
   212                         (FieldDoc) enumConstants.get(currentEnumConstantsIndex));
   213         }
   215         /**
   216          * Build the footer for the individual enum constants.
   217          */
   218         public void buildEnumConstantFooter(XMLNode node) {
   219                 writer.writeEnumConstantFooter();
   220         }
   222         /**
   223          * Build the overall footer.
   224          */
   225         public void buildFooter(XMLNode node) {
   226                 writer.writeFooter(classDoc);
   227         }
   229         /**
   230          * Return the enum constant writer for this builder.
   231          *
   232          * @return the enum constant writer for this builder.
   233          */
   234         public EnumConstantWriter getWriter() {
   235                 return writer;
   236         }
   237 }

mercurial