duke@1: /* duke@1: * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as duke@1: * published by the Free Software Foundation. Sun designates this duke@1: * particular file as subject to the "Classpath" exception as provided duke@1: * by Sun in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * duke@1: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@1: * CA 95054 USA or visit www.sun.com if you need additional information or duke@1: * have any questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.internal.toolkit.builders; duke@1: duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; duke@1: import com.sun.tools.doclets.internal.toolkit.*; duke@1: import com.sun.javadoc.*; duke@1: import java.util.*; duke@1: import java.lang.reflect.*; duke@1: duke@1: /** duke@1: * Builds documentation for a enum constants. duke@1: * duke@1: * This code is not part of an API. duke@1: * It is implementation that is subject to change. duke@1: * Do not use it as an API duke@1: * duke@1: * @author Jamie Ho duke@1: * @since 1.5 duke@1: */ duke@1: public class EnumConstantBuilder extends AbstractMemberBuilder { duke@1: duke@1: /** duke@1: * The class whose enum constants are being documented. duke@1: */ duke@1: private ClassDoc classDoc; duke@1: duke@1: /** duke@1: * The visible enum constantss for the given class. duke@1: */ duke@1: private VisibleMemberMap visibleMemberMap; duke@1: duke@1: /** duke@1: * The writer to output the enum constants documentation. duke@1: */ duke@1: private EnumConstantWriter writer; duke@1: duke@1: /** duke@1: * The list of enum constants being documented. duke@1: */ duke@1: private List enumConstants; duke@1: duke@1: /** duke@1: * The index of the current enum constant that is being documented at this point duke@1: * in time. duke@1: */ duke@1: private int currentEnumConstantsIndex; duke@1: duke@1: /** duke@1: * Construct a new EnumConstantsBuilder. duke@1: * duke@1: * @param configuration the current configuration of the duke@1: * doclet. duke@1: */ duke@1: private EnumConstantBuilder(Configuration configuration) { duke@1: super(configuration); duke@1: } duke@1: duke@1: /** duke@1: * Construct a new EnumConstantsBuilder. duke@1: * duke@1: * @param configuration the current configuration of the doclet. duke@1: * @param classDoc the class whoses members are being documented. duke@1: * @param writer the doclet specific writer. duke@1: */ duke@1: public static EnumConstantBuilder getInstance( duke@1: Configuration configuration, duke@1: ClassDoc classDoc, duke@1: EnumConstantWriter writer) { duke@1: EnumConstantBuilder builder = new EnumConstantBuilder(configuration); duke@1: builder.classDoc = classDoc; duke@1: builder.writer = writer; duke@1: builder.visibleMemberMap = duke@1: new VisibleMemberMap( duke@1: classDoc, duke@1: VisibleMemberMap.ENUM_CONSTANTS, duke@1: configuration.nodeprecated); duke@1: builder.enumConstants = duke@1: new ArrayList(builder.visibleMemberMap.getMembersFor(classDoc)); duke@1: if (configuration.getMemberComparator() != null) { duke@1: Collections.sort( duke@1: builder.enumConstants, duke@1: configuration.getMemberComparator()); duke@1: } duke@1: return builder; duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public String getName() { duke@1: return "EnumConstantDetails"; duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public void invokeMethod( duke@1: String methodName, duke@1: Class[] paramClasses, duke@1: Object[] params) duke@1: throws Exception { duke@1: if (DEBUG) { duke@1: configuration.root.printError( duke@1: "DEBUG: " + this.getClass().getName() + "." + methodName); duke@1: } duke@1: Method method = this.getClass().getMethod(methodName, paramClasses); duke@1: method.invoke(this, params); duke@1: } duke@1: duke@1: /** duke@1: * Returns a list of enum constants that will be documented for the given class. duke@1: * This information can be used for doclet specific documentation duke@1: * generation. duke@1: * duke@1: * @param classDoc the {@link ClassDoc} we want to check. duke@1: * @return a list of enum constants that will be documented. duke@1: */ duke@1: public List members(ClassDoc classDoc) { duke@1: return visibleMemberMap.getMembersFor(classDoc); duke@1: } duke@1: duke@1: /** duke@1: * Returns the visible member map for the enum constants of this class. duke@1: * duke@1: * @return the visible member map for the enum constants of this class. duke@1: */ duke@1: public VisibleMemberMap getVisibleMemberMap() { duke@1: return visibleMemberMap; duke@1: } duke@1: duke@1: /** duke@1: * summaryOrder.size() duke@1: */ duke@1: public boolean hasMembersToDocument() { duke@1: return enumConstants.size() > 0; duke@1: } duke@1: duke@1: /** duke@1: * Build the enum constant documentation. duke@1: * duke@1: * @param elements the XML elements that specify how to construct this duke@1: * documentation. duke@1: */ duke@1: public void buildEnumConstant(List elements) { duke@1: if (writer == null) { duke@1: return; duke@1: } duke@1: for (currentEnumConstantsIndex = 0; duke@1: currentEnumConstantsIndex < enumConstants.size(); duke@1: currentEnumConstantsIndex++) { duke@1: build(elements); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Build the overall header. duke@1: */ duke@1: public void buildHeader() { duke@1: writer.writeHeader( duke@1: classDoc, duke@1: configuration.getText("doclet.Enum_Constant_Detail")); duke@1: } duke@1: duke@1: /** duke@1: * Build the header for the individual enum constants. duke@1: */ duke@1: public void buildEnumConstantHeader() { duke@1: writer.writeEnumConstantHeader( duke@1: (FieldDoc) enumConstants.get(currentEnumConstantsIndex), duke@1: currentEnumConstantsIndex == 0); duke@1: } duke@1: duke@1: /** duke@1: * Build the signature. duke@1: */ duke@1: public void buildSignature() { duke@1: writer.writeSignature( duke@1: (FieldDoc) enumConstants.get(currentEnumConstantsIndex)); duke@1: } duke@1: duke@1: /** duke@1: * Build the deprecation information. duke@1: */ duke@1: public void buildDeprecationInfo() { duke@1: writer.writeDeprecated( duke@1: (FieldDoc) enumConstants.get(currentEnumConstantsIndex)); duke@1: } duke@1: duke@1: /** duke@1: * Build the comments for the enum constant. Do nothing if duke@1: * {@link Configuration#nocomment} is set to true. duke@1: */ duke@1: public void buildEnumConstantComments() { duke@1: if (!configuration.nocomment) { duke@1: writer.writeComments( duke@1: (FieldDoc) enumConstants.get(currentEnumConstantsIndex)); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Build the tag information. duke@1: */ duke@1: public void buildTagInfo() { duke@1: writer.writeTags( duke@1: (FieldDoc) enumConstants.get(currentEnumConstantsIndex)); duke@1: } duke@1: duke@1: /** duke@1: * Build the footer for the individual enum constants. duke@1: */ duke@1: public void buildEnumConstantFooter() { duke@1: writer.writeEnumConstantFooter(); duke@1: } duke@1: duke@1: /** duke@1: * Build the overall footer. duke@1: */ duke@1: public void buildFooter() { duke@1: writer.writeFooter(classDoc); duke@1: } duke@1: duke@1: /** duke@1: * Return the enum constant writer for this builder. duke@1: * duke@1: * @return the enum constant writer for this builder. duke@1: */ duke@1: public EnumConstantWriter getWriter() { duke@1: return writer; duke@1: } duke@1: }