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 Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,254 @@ 1.4 +/* 1.5 + * Copyright 2003 Sun Microsystems, Inc. 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. Sun designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.26 + * have any questions. 1.27 + */ 1.28 + 1.29 +package com.sun.tools.doclets.internal.toolkit.builders; 1.30 + 1.31 +import com.sun.tools.doclets.internal.toolkit.util.*; 1.32 +import com.sun.tools.doclets.internal.toolkit.*; 1.33 +import com.sun.javadoc.*; 1.34 +import java.util.*; 1.35 +import java.lang.reflect.*; 1.36 + 1.37 +/** 1.38 + * Builds documentation for a enum constants. 1.39 + * 1.40 + * This code is not part of an API. 1.41 + * It is implementation that is subject to change. 1.42 + * Do not use it as an API 1.43 + * 1.44 + * @author Jamie Ho 1.45 + * @since 1.5 1.46 + */ 1.47 +public class EnumConstantBuilder extends AbstractMemberBuilder { 1.48 + 1.49 + /** 1.50 + * The class whose enum constants are being documented. 1.51 + */ 1.52 + private ClassDoc classDoc; 1.53 + 1.54 + /** 1.55 + * The visible enum constantss for the given class. 1.56 + */ 1.57 + private VisibleMemberMap visibleMemberMap; 1.58 + 1.59 + /** 1.60 + * The writer to output the enum constants documentation. 1.61 + */ 1.62 + private EnumConstantWriter writer; 1.63 + 1.64 + /** 1.65 + * The list of enum constants being documented. 1.66 + */ 1.67 + private List enumConstants; 1.68 + 1.69 + /** 1.70 + * The index of the current enum constant that is being documented at this point 1.71 + * in time. 1.72 + */ 1.73 + private int currentEnumConstantsIndex; 1.74 + 1.75 + /** 1.76 + * Construct a new EnumConstantsBuilder. 1.77 + * 1.78 + * @param configuration the current configuration of the 1.79 + * doclet. 1.80 + */ 1.81 + private EnumConstantBuilder(Configuration configuration) { 1.82 + super(configuration); 1.83 + } 1.84 + 1.85 + /** 1.86 + * Construct a new EnumConstantsBuilder. 1.87 + * 1.88 + * @param configuration the current configuration of the doclet. 1.89 + * @param classDoc the class whoses members are being documented. 1.90 + * @param writer the doclet specific writer. 1.91 + */ 1.92 + public static EnumConstantBuilder getInstance( 1.93 + Configuration configuration, 1.94 + ClassDoc classDoc, 1.95 + EnumConstantWriter writer) { 1.96 + EnumConstantBuilder builder = new EnumConstantBuilder(configuration); 1.97 + builder.classDoc = classDoc; 1.98 + builder.writer = writer; 1.99 + builder.visibleMemberMap = 1.100 + new VisibleMemberMap( 1.101 + classDoc, 1.102 + VisibleMemberMap.ENUM_CONSTANTS, 1.103 + configuration.nodeprecated); 1.104 + builder.enumConstants = 1.105 + new ArrayList(builder.visibleMemberMap.getMembersFor(classDoc)); 1.106 + if (configuration.getMemberComparator() != null) { 1.107 + Collections.sort( 1.108 + builder.enumConstants, 1.109 + configuration.getMemberComparator()); 1.110 + } 1.111 + return builder; 1.112 + } 1.113 + 1.114 + /** 1.115 + * {@inheritDoc} 1.116 + */ 1.117 + public String getName() { 1.118 + return "EnumConstantDetails"; 1.119 + } 1.120 + 1.121 + /** 1.122 + * {@inheritDoc} 1.123 + */ 1.124 + public void invokeMethod( 1.125 + String methodName, 1.126 + Class[] paramClasses, 1.127 + Object[] params) 1.128 + throws Exception { 1.129 + if (DEBUG) { 1.130 + configuration.root.printError( 1.131 + "DEBUG: " + this.getClass().getName() + "." + methodName); 1.132 + } 1.133 + Method method = this.getClass().getMethod(methodName, paramClasses); 1.134 + method.invoke(this, params); 1.135 + } 1.136 + 1.137 + /** 1.138 + * Returns a list of enum constants that will be documented for the given class. 1.139 + * This information can be used for doclet specific documentation 1.140 + * generation. 1.141 + * 1.142 + * @param classDoc the {@link ClassDoc} we want to check. 1.143 + * @return a list of enum constants that will be documented. 1.144 + */ 1.145 + public List members(ClassDoc classDoc) { 1.146 + return visibleMemberMap.getMembersFor(classDoc); 1.147 + } 1.148 + 1.149 + /** 1.150 + * Returns the visible member map for the enum constants of this class. 1.151 + * 1.152 + * @return the visible member map for the enum constants of this class. 1.153 + */ 1.154 + public VisibleMemberMap getVisibleMemberMap() { 1.155 + return visibleMemberMap; 1.156 + } 1.157 + 1.158 + /** 1.159 + * summaryOrder.size() 1.160 + */ 1.161 + public boolean hasMembersToDocument() { 1.162 + return enumConstants.size() > 0; 1.163 + } 1.164 + 1.165 + /** 1.166 + * Build the enum constant documentation. 1.167 + * 1.168 + * @param elements the XML elements that specify how to construct this 1.169 + * documentation. 1.170 + */ 1.171 + public void buildEnumConstant(List elements) { 1.172 + if (writer == null) { 1.173 + return; 1.174 + } 1.175 + for (currentEnumConstantsIndex = 0; 1.176 + currentEnumConstantsIndex < enumConstants.size(); 1.177 + currentEnumConstantsIndex++) { 1.178 + build(elements); 1.179 + } 1.180 + } 1.181 + 1.182 + /** 1.183 + * Build the overall header. 1.184 + */ 1.185 + public void buildHeader() { 1.186 + writer.writeHeader( 1.187 + classDoc, 1.188 + configuration.getText("doclet.Enum_Constant_Detail")); 1.189 + } 1.190 + 1.191 + /** 1.192 + * Build the header for the individual enum constants. 1.193 + */ 1.194 + public void buildEnumConstantHeader() { 1.195 + writer.writeEnumConstantHeader( 1.196 + (FieldDoc) enumConstants.get(currentEnumConstantsIndex), 1.197 + currentEnumConstantsIndex == 0); 1.198 + } 1.199 + 1.200 + /** 1.201 + * Build the signature. 1.202 + */ 1.203 + public void buildSignature() { 1.204 + writer.writeSignature( 1.205 + (FieldDoc) enumConstants.get(currentEnumConstantsIndex)); 1.206 + } 1.207 + 1.208 + /** 1.209 + * Build the deprecation information. 1.210 + */ 1.211 + public void buildDeprecationInfo() { 1.212 + writer.writeDeprecated( 1.213 + (FieldDoc) enumConstants.get(currentEnumConstantsIndex)); 1.214 + } 1.215 + 1.216 + /** 1.217 + * Build the comments for the enum constant. Do nothing if 1.218 + * {@link Configuration#nocomment} is set to true. 1.219 + */ 1.220 + public void buildEnumConstantComments() { 1.221 + if (!configuration.nocomment) { 1.222 + writer.writeComments( 1.223 + (FieldDoc) enumConstants.get(currentEnumConstantsIndex)); 1.224 + } 1.225 + } 1.226 + 1.227 + /** 1.228 + * Build the tag information. 1.229 + */ 1.230 + public void buildTagInfo() { 1.231 + writer.writeTags( 1.232 + (FieldDoc) enumConstants.get(currentEnumConstantsIndex)); 1.233 + } 1.234 + 1.235 + /** 1.236 + * Build the footer for the individual enum constants. 1.237 + */ 1.238 + public void buildEnumConstantFooter() { 1.239 + writer.writeEnumConstantFooter(); 1.240 + } 1.241 + 1.242 + /** 1.243 + * Build the overall footer. 1.244 + */ 1.245 + public void buildFooter() { 1.246 + writer.writeFooter(classDoc); 1.247 + } 1.248 + 1.249 + /** 1.250 + * Return the enum constant writer for this builder. 1.251 + * 1.252 + * @return the enum constant writer for this builder. 1.253 + */ 1.254 + public EnumConstantWriter getWriter() { 1.255 + return writer; 1.256 + } 1.257 +}