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

Sun, 24 Feb 2013 11:36:58 -0800

author
jjg
date
Sun, 24 Feb 2013 11:36:58 -0800
changeset 1606
ccbe7ffdd867
parent 1410
bfec2a1cc869
child 2525
2eb010b6cb22
permissions
-rw-r--r--

7112427: The doclet needs to be able to generate JavaFX documentation.
Reviewed-by: jjg
Contributed-by: jan.valenta@oracle.com

     1 /*
     2  * Copyright (c) 2003, 2013, 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  *  <p><b>This is NOT part of any supported API.
    38  *  If you write code that depends on this, you do so at your own risk.
    39  *  This code and its internal interfaces are subject to change or
    40  *  deletion without notice.</b>
    41  *
    42  * @author Jamie Ho
    43  * @author Bhavesh Patel (Modified)
    44  * @since 1.5
    45  */
    46 public class EnumConstantBuilder extends AbstractMemberBuilder {
    48     /**
    49      * The class whose enum constants are being documented.
    50      */
    51     private final ClassDoc classDoc;
    53     /**
    54      * The visible enum constantss for the given class.
    55      */
    56     private final VisibleMemberMap visibleMemberMap;
    58     /**
    59      * The writer to output the enum constants documentation.
    60      */
    61     private final EnumConstantWriter writer;
    63     /**
    64      * The list of enum constants being documented.
    65      */
    66     private final List<ProgramElementDoc> enumConstants;
    68     /**
    69      * The index of the current enum constant that is being documented at this point
    70      * in time.
    71      */
    72     private int currentEnumConstantsIndex;
    74     /**
    75      * Construct a new EnumConstantsBuilder.
    76      *
    77      * @param context  the build context.
    78      * @param classDoc the class whoses members are being documented.
    79      * @param writer the doclet specific writer.
    80      */
    81     private EnumConstantBuilder(Context context,
    82             ClassDoc classDoc, EnumConstantWriter writer) {
    83         super(context);
    84         this.classDoc = classDoc;
    85         this.writer = writer;
    86         visibleMemberMap =
    87                 new VisibleMemberMap(
    88                 classDoc,
    89                 VisibleMemberMap.ENUM_CONSTANTS,
    90                 configuration);
    91         enumConstants =
    92                 new ArrayList<ProgramElementDoc>(visibleMemberMap.getMembersFor(classDoc));
    93         if (configuration.getMemberComparator() != null) {
    94             Collections.sort(enumConstants, configuration.getMemberComparator());
    95         }
    96     }
    98     /**
    99      * Construct a new EnumConstantsBuilder.
   100      *
   101      * @param context  the build context.
   102      * @param classDoc the class whoses members are being documented.
   103      * @param writer the doclet specific writer.
   104      */
   105     public static EnumConstantBuilder getInstance(Context context,
   106             ClassDoc classDoc, EnumConstantWriter writer) {
   107         return new EnumConstantBuilder(context, classDoc, writer);
   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 node the XML element that specifies which components to document
   149      * @param memberDetailsTree the content tree to which the documentation will be added
   150      */
   151     public void buildEnumConstant(XMLNode node, Content memberDetailsTree) {
   152         if (writer == null) {
   153             return;
   154         }
   155         int size = enumConstants.size();
   156         if (size > 0) {
   157             Content enumConstantsDetailsTree = writer.getEnumConstantsDetailsTreeHeader(
   158                     classDoc, memberDetailsTree);
   159             for (currentEnumConstantsIndex = 0; currentEnumConstantsIndex < size;
   160                     currentEnumConstantsIndex++) {
   161                 Content enumConstantsTree = writer.getEnumConstantsTreeHeader(
   162                         (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
   163                         enumConstantsDetailsTree);
   164                 buildChildren(node, enumConstantsTree);
   165                 enumConstantsDetailsTree.addContent(writer.getEnumConstants(
   166                         enumConstantsTree, (currentEnumConstantsIndex == size - 1)));
   167             }
   168             memberDetailsTree.addContent(
   169                     writer.getEnumConstantsDetails(enumConstantsDetailsTree));
   170         }
   171     }
   173     /**
   174      * Build the signature.
   175      *
   176      * @param node the XML element that specifies which components to document
   177      * @param enumConstantsTree the content tree to which the documentation will be added
   178      */
   179     public void buildSignature(XMLNode node, Content enumConstantsTree) {
   180         enumConstantsTree.addContent(writer.getSignature(
   181                 (FieldDoc) enumConstants.get(currentEnumConstantsIndex)));
   182     }
   184     /**
   185      * Build the deprecation information.
   186      *
   187      * @param node the XML element that specifies which components to document
   188      * @param enumConstantsTree the content tree to which the documentation will be added
   189      */
   190     public void buildDeprecationInfo(XMLNode node, Content enumConstantsTree) {
   191         writer.addDeprecated(
   192                 (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
   193                 enumConstantsTree);
   194     }
   196     /**
   197      * Build the comments for the enum constant.  Do nothing if
   198      * {@link Configuration#nocomment} is set to true.
   199      *
   200      * @param node the XML element that specifies which components to document
   201      * @param enumConstantsTree the content tree to which the documentation will be added
   202      */
   203     public void buildEnumConstantComments(XMLNode node, Content enumConstantsTree) {
   204         if (!configuration.nocomment) {
   205             writer.addComments(
   206                     (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
   207                     enumConstantsTree);
   208         }
   209     }
   211     /**
   212      * Build the tag information.
   213      *
   214      * @param node the XML element that specifies which components to document
   215      * @param enumConstantsTree the content tree to which the documentation will be added
   216      */
   217     public void buildTagInfo(XMLNode node, Content enumConstantsTree) {
   218         writer.addTags(
   219                 (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
   220                 enumConstantsTree);
   221     }
   223     /**
   224      * Return the enum constant writer for this builder.
   225      *
   226      * @return the enum constant writer for this builder.
   227      */
   228     public EnumConstantWriter getWriter() {
   229         return writer;
   230     }
   231 }

mercurial