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

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/EnumConstantBuilder.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,231 @@
     1.4 +/*
     1.5 + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.doclets.internal.toolkit.builders;
    1.30 +
    1.31 +import java.util.*;
    1.32 +
    1.33 +import com.sun.javadoc.*;
    1.34 +import com.sun.tools.doclets.internal.toolkit.*;
    1.35 +import com.sun.tools.doclets.internal.toolkit.util.*;
    1.36 +
    1.37 +/**
    1.38 + * Builds documentation for a enum constants.
    1.39 + *
    1.40 + *  <p><b>This is NOT part of any supported API.
    1.41 + *  If you write code that depends on this, you do so at your own risk.
    1.42 + *  This code and its internal interfaces are subject to change or
    1.43 + *  deletion without notice.</b>
    1.44 + *
    1.45 + * @author Jamie Ho
    1.46 + * @author Bhavesh Patel (Modified)
    1.47 + * @since 1.5
    1.48 + */
    1.49 +public class EnumConstantBuilder extends AbstractMemberBuilder {
    1.50 +
    1.51 +    /**
    1.52 +     * The class whose enum constants are being documented.
    1.53 +     */
    1.54 +    private final ClassDoc classDoc;
    1.55 +
    1.56 +    /**
    1.57 +     * The visible enum constantss for the given class.
    1.58 +     */
    1.59 +    private final VisibleMemberMap visibleMemberMap;
    1.60 +
    1.61 +    /**
    1.62 +     * The writer to output the enum constants documentation.
    1.63 +     */
    1.64 +    private final EnumConstantWriter writer;
    1.65 +
    1.66 +    /**
    1.67 +     * The list of enum constants being documented.
    1.68 +     */
    1.69 +    private final List<ProgramElementDoc> enumConstants;
    1.70 +
    1.71 +    /**
    1.72 +     * The index of the current enum constant that is being documented at this point
    1.73 +     * in time.
    1.74 +     */
    1.75 +    private int currentEnumConstantsIndex;
    1.76 +
    1.77 +    /**
    1.78 +     * Construct a new EnumConstantsBuilder.
    1.79 +     *
    1.80 +     * @param context  the build context.
    1.81 +     * @param classDoc the class whoses members are being documented.
    1.82 +     * @param writer the doclet specific writer.
    1.83 +     */
    1.84 +    private EnumConstantBuilder(Context context,
    1.85 +            ClassDoc classDoc, EnumConstantWriter writer) {
    1.86 +        super(context);
    1.87 +        this.classDoc = classDoc;
    1.88 +        this.writer = writer;
    1.89 +        visibleMemberMap =
    1.90 +                new VisibleMemberMap(
    1.91 +                classDoc,
    1.92 +                VisibleMemberMap.ENUM_CONSTANTS,
    1.93 +                configuration);
    1.94 +        enumConstants =
    1.95 +                new ArrayList<ProgramElementDoc>(visibleMemberMap.getMembersFor(classDoc));
    1.96 +        if (configuration.getMemberComparator() != null) {
    1.97 +            Collections.sort(enumConstants, configuration.getMemberComparator());
    1.98 +        }
    1.99 +    }
   1.100 +
   1.101 +    /**
   1.102 +     * Construct a new EnumConstantsBuilder.
   1.103 +     *
   1.104 +     * @param context  the build context.
   1.105 +     * @param classDoc the class whoses members are being documented.
   1.106 +     * @param writer the doclet specific writer.
   1.107 +     */
   1.108 +    public static EnumConstantBuilder getInstance(Context context,
   1.109 +            ClassDoc classDoc, EnumConstantWriter writer) {
   1.110 +        return new EnumConstantBuilder(context, classDoc, writer);
   1.111 +    }
   1.112 +
   1.113 +    /**
   1.114 +     * {@inheritDoc}
   1.115 +     */
   1.116 +    public String getName() {
   1.117 +        return "EnumConstantDetails";
   1.118 +    }
   1.119 +
   1.120 +    /**
   1.121 +     * Returns a list of enum constants that will be documented for the given class.
   1.122 +     * This information can be used for doclet specific documentation
   1.123 +     * generation.
   1.124 +     *
   1.125 +     * @param classDoc the {@link ClassDoc} we want to check.
   1.126 +     * @return a list of enum constants that will be documented.
   1.127 +     */
   1.128 +    public List<ProgramElementDoc> members(ClassDoc classDoc) {
   1.129 +        return visibleMemberMap.getMembersFor(classDoc);
   1.130 +    }
   1.131 +
   1.132 +    /**
   1.133 +     * Returns the visible member map for the enum constants of this class.
   1.134 +     *
   1.135 +     * @return the visible member map for the enum constants of this class.
   1.136 +     */
   1.137 +    public VisibleMemberMap getVisibleMemberMap() {
   1.138 +        return visibleMemberMap;
   1.139 +    }
   1.140 +
   1.141 +    /**
   1.142 +     * summaryOrder.size()
   1.143 +     */
   1.144 +    public boolean hasMembersToDocument() {
   1.145 +        return enumConstants.size() > 0;
   1.146 +    }
   1.147 +
   1.148 +    /**
   1.149 +     * Build the enum constant documentation.
   1.150 +     *
   1.151 +     * @param node the XML element that specifies which components to document
   1.152 +     * @param memberDetailsTree the content tree to which the documentation will be added
   1.153 +     */
   1.154 +    public void buildEnumConstant(XMLNode node, Content memberDetailsTree) {
   1.155 +        if (writer == null) {
   1.156 +            return;
   1.157 +        }
   1.158 +        int size = enumConstants.size();
   1.159 +        if (size > 0) {
   1.160 +            Content enumConstantsDetailsTree = writer.getEnumConstantsDetailsTreeHeader(
   1.161 +                    classDoc, memberDetailsTree);
   1.162 +            for (currentEnumConstantsIndex = 0; currentEnumConstantsIndex < size;
   1.163 +                    currentEnumConstantsIndex++) {
   1.164 +                Content enumConstantsTree = writer.getEnumConstantsTreeHeader(
   1.165 +                        (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
   1.166 +                        enumConstantsDetailsTree);
   1.167 +                buildChildren(node, enumConstantsTree);
   1.168 +                enumConstantsDetailsTree.addContent(writer.getEnumConstants(
   1.169 +                        enumConstantsTree, (currentEnumConstantsIndex == size - 1)));
   1.170 +            }
   1.171 +            memberDetailsTree.addContent(
   1.172 +                    writer.getEnumConstantsDetails(enumConstantsDetailsTree));
   1.173 +        }
   1.174 +    }
   1.175 +
   1.176 +    /**
   1.177 +     * Build the signature.
   1.178 +     *
   1.179 +     * @param node the XML element that specifies which components to document
   1.180 +     * @param enumConstantsTree the content tree to which the documentation will be added
   1.181 +     */
   1.182 +    public void buildSignature(XMLNode node, Content enumConstantsTree) {
   1.183 +        enumConstantsTree.addContent(writer.getSignature(
   1.184 +                (FieldDoc) enumConstants.get(currentEnumConstantsIndex)));
   1.185 +    }
   1.186 +
   1.187 +    /**
   1.188 +     * Build the deprecation information.
   1.189 +     *
   1.190 +     * @param node the XML element that specifies which components to document
   1.191 +     * @param enumConstantsTree the content tree to which the documentation will be added
   1.192 +     */
   1.193 +    public void buildDeprecationInfo(XMLNode node, Content enumConstantsTree) {
   1.194 +        writer.addDeprecated(
   1.195 +                (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
   1.196 +                enumConstantsTree);
   1.197 +    }
   1.198 +
   1.199 +    /**
   1.200 +     * Build the comments for the enum constant.  Do nothing if
   1.201 +     * {@link Configuration#nocomment} is set to true.
   1.202 +     *
   1.203 +     * @param node the XML element that specifies which components to document
   1.204 +     * @param enumConstantsTree the content tree to which the documentation will be added
   1.205 +     */
   1.206 +    public void buildEnumConstantComments(XMLNode node, Content enumConstantsTree) {
   1.207 +        if (!configuration.nocomment) {
   1.208 +            writer.addComments(
   1.209 +                    (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
   1.210 +                    enumConstantsTree);
   1.211 +        }
   1.212 +    }
   1.213 +
   1.214 +    /**
   1.215 +     * Build the tag information.
   1.216 +     *
   1.217 +     * @param node the XML element that specifies which components to document
   1.218 +     * @param enumConstantsTree the content tree to which the documentation will be added
   1.219 +     */
   1.220 +    public void buildTagInfo(XMLNode node, Content enumConstantsTree) {
   1.221 +        writer.addTags(
   1.222 +                (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
   1.223 +                enumConstantsTree);
   1.224 +    }
   1.225 +
   1.226 +    /**
   1.227 +     * Return the enum constant writer for this builder.
   1.228 +     *
   1.229 +     * @return the enum constant writer for this builder.
   1.230 +     */
   1.231 +    public EnumConstantWriter getWriter() {
   1.232 +        return writer;
   1.233 +    }
   1.234 +}

mercurial