aoqi@0: /* aoqi@0: * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.tools.doclets.internal.toolkit.builders; aoqi@0: aoqi@0: import java.util.*; aoqi@0: aoqi@0: import com.sun.javadoc.*; aoqi@0: import com.sun.tools.doclets.internal.toolkit.*; aoqi@0: import com.sun.tools.doclets.internal.toolkit.util.*; aoqi@0: aoqi@0: /** aoqi@0: * Builds documentation for a enum constants. aoqi@0: * aoqi@0: *

This is NOT part of any supported API. aoqi@0: * If you write code that depends on this, you do so at your own risk. aoqi@0: * This code and its internal interfaces are subject to change or aoqi@0: * deletion without notice. aoqi@0: * aoqi@0: * @author Jamie Ho aoqi@0: * @author Bhavesh Patel (Modified) aoqi@0: * @since 1.5 aoqi@0: */ aoqi@0: public class EnumConstantBuilder extends AbstractMemberBuilder { aoqi@0: aoqi@0: /** aoqi@0: * The class whose enum constants are being documented. aoqi@0: */ aoqi@0: private final ClassDoc classDoc; aoqi@0: aoqi@0: /** aoqi@0: * The visible enum constantss for the given class. aoqi@0: */ aoqi@0: private final VisibleMemberMap visibleMemberMap; aoqi@0: aoqi@0: /** aoqi@0: * The writer to output the enum constants documentation. aoqi@0: */ aoqi@0: private final EnumConstantWriter writer; aoqi@0: aoqi@0: /** aoqi@0: * The list of enum constants being documented. aoqi@0: */ aoqi@0: private final List enumConstants; aoqi@0: aoqi@0: /** aoqi@0: * The index of the current enum constant that is being documented at this point aoqi@0: * in time. aoqi@0: */ aoqi@0: private int currentEnumConstantsIndex; aoqi@0: aoqi@0: /** aoqi@0: * Construct a new EnumConstantsBuilder. aoqi@0: * aoqi@0: * @param context the build context. aoqi@0: * @param classDoc the class whoses members are being documented. aoqi@0: * @param writer the doclet specific writer. aoqi@0: */ aoqi@0: private EnumConstantBuilder(Context context, aoqi@0: ClassDoc classDoc, EnumConstantWriter writer) { aoqi@0: super(context); aoqi@0: this.classDoc = classDoc; aoqi@0: this.writer = writer; aoqi@0: visibleMemberMap = aoqi@0: new VisibleMemberMap( aoqi@0: classDoc, aoqi@0: VisibleMemberMap.ENUM_CONSTANTS, aoqi@0: configuration); aoqi@0: enumConstants = aoqi@0: new ArrayList(visibleMemberMap.getMembersFor(classDoc)); aoqi@0: if (configuration.getMemberComparator() != null) { aoqi@0: Collections.sort(enumConstants, configuration.getMemberComparator()); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Construct a new EnumConstantsBuilder. aoqi@0: * aoqi@0: * @param context the build context. aoqi@0: * @param classDoc the class whoses members are being documented. aoqi@0: * @param writer the doclet specific writer. aoqi@0: */ aoqi@0: public static EnumConstantBuilder getInstance(Context context, aoqi@0: ClassDoc classDoc, EnumConstantWriter writer) { aoqi@0: return new EnumConstantBuilder(context, classDoc, writer); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public String getName() { aoqi@0: return "EnumConstantDetails"; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Returns a list of enum constants that will be documented for the given class. aoqi@0: * This information can be used for doclet specific documentation aoqi@0: * generation. aoqi@0: * aoqi@0: * @param classDoc the {@link ClassDoc} we want to check. aoqi@0: * @return a list of enum constants that will be documented. aoqi@0: */ aoqi@0: public List members(ClassDoc classDoc) { aoqi@0: return visibleMemberMap.getMembersFor(classDoc); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Returns the visible member map for the enum constants of this class. aoqi@0: * aoqi@0: * @return the visible member map for the enum constants of this class. aoqi@0: */ aoqi@0: public VisibleMemberMap getVisibleMemberMap() { aoqi@0: return visibleMemberMap; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * summaryOrder.size() aoqi@0: */ aoqi@0: public boolean hasMembersToDocument() { aoqi@0: return enumConstants.size() > 0; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the enum constant documentation. aoqi@0: * aoqi@0: * @param node the XML element that specifies which components to document aoqi@0: * @param memberDetailsTree the content tree to which the documentation will be added aoqi@0: */ aoqi@0: public void buildEnumConstant(XMLNode node, Content memberDetailsTree) { aoqi@0: if (writer == null) { aoqi@0: return; aoqi@0: } aoqi@0: int size = enumConstants.size(); aoqi@0: if (size > 0) { aoqi@0: Content enumConstantsDetailsTree = writer.getEnumConstantsDetailsTreeHeader( aoqi@0: classDoc, memberDetailsTree); aoqi@0: for (currentEnumConstantsIndex = 0; currentEnumConstantsIndex < size; aoqi@0: currentEnumConstantsIndex++) { aoqi@0: Content enumConstantsTree = writer.getEnumConstantsTreeHeader( aoqi@0: (FieldDoc) enumConstants.get(currentEnumConstantsIndex), aoqi@0: enumConstantsDetailsTree); aoqi@0: buildChildren(node, enumConstantsTree); aoqi@0: enumConstantsDetailsTree.addContent(writer.getEnumConstants( aoqi@0: enumConstantsTree, (currentEnumConstantsIndex == size - 1))); aoqi@0: } aoqi@0: memberDetailsTree.addContent( aoqi@0: writer.getEnumConstantsDetails(enumConstantsDetailsTree)); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the signature. aoqi@0: * aoqi@0: * @param node the XML element that specifies which components to document aoqi@0: * @param enumConstantsTree the content tree to which the documentation will be added aoqi@0: */ aoqi@0: public void buildSignature(XMLNode node, Content enumConstantsTree) { aoqi@0: enumConstantsTree.addContent(writer.getSignature( aoqi@0: (FieldDoc) enumConstants.get(currentEnumConstantsIndex))); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the deprecation information. aoqi@0: * aoqi@0: * @param node the XML element that specifies which components to document aoqi@0: * @param enumConstantsTree the content tree to which the documentation will be added aoqi@0: */ aoqi@0: public void buildDeprecationInfo(XMLNode node, Content enumConstantsTree) { aoqi@0: writer.addDeprecated( aoqi@0: (FieldDoc) enumConstants.get(currentEnumConstantsIndex), aoqi@0: enumConstantsTree); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the comments for the enum constant. Do nothing if aoqi@0: * {@link Configuration#nocomment} is set to true. aoqi@0: * aoqi@0: * @param node the XML element that specifies which components to document aoqi@0: * @param enumConstantsTree the content tree to which the documentation will be added aoqi@0: */ aoqi@0: public void buildEnumConstantComments(XMLNode node, Content enumConstantsTree) { aoqi@0: if (!configuration.nocomment) { aoqi@0: writer.addComments( aoqi@0: (FieldDoc) enumConstants.get(currentEnumConstantsIndex), aoqi@0: enumConstantsTree); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the tag information. aoqi@0: * aoqi@0: * @param node the XML element that specifies which components to document aoqi@0: * @param enumConstantsTree the content tree to which the documentation will be added aoqi@0: */ aoqi@0: public void buildTagInfo(XMLNode node, Content enumConstantsTree) { aoqi@0: writer.addTags( aoqi@0: (FieldDoc) enumConstants.get(currentEnumConstantsIndex), aoqi@0: enumConstantsTree); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return the enum constant writer for this builder. aoqi@0: * aoqi@0: * @return the enum constant writer for this builder. aoqi@0: */ aoqi@0: public EnumConstantWriter getWriter() { aoqi@0: return writer; aoqi@0: } aoqi@0: }