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

Wed, 01 Dec 2010 11:02:38 -0800

author
bpatel
date
Wed, 01 Dec 2010 11:02:38 -0800
changeset 766
90af8d87741f
parent 589
4177f5bdd189
child 798
4868a36f6fd8
permissions
-rw-r--r--

6851834: Javadoc doclet needs a structured approach to generate the output HTML.
Reviewed-by: jjg

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

mercurial