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

Thu, 02 Oct 2008 19:58:40 -0700

author
xdono
date
Thu, 02 Oct 2008 19:58:40 -0700
changeset 117
24a47c3062fe
parent 74
5a9172b251dd
child 184
905e151a185a
permissions
-rw-r--r--

6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell

duke@1 1 /*
xdono@117 2 * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation. Sun designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
duke@1 9 * by Sun in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
duke@1 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@1 22 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@1 23 * have any questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.doclets.internal.toolkit.builders;
duke@1 27
duke@1 28 import com.sun.tools.doclets.internal.toolkit.util.*;
duke@1 29 import com.sun.tools.doclets.internal.toolkit.*;
duke@1 30 import com.sun.javadoc.*;
duke@1 31 import java.util.*;
duke@1 32 import java.lang.reflect.*;
duke@1 33
duke@1 34 /**
duke@1 35 * Builds documentation for a enum constants.
duke@1 36 *
duke@1 37 * This code is not part of an API.
duke@1 38 * It is implementation that is subject to change.
duke@1 39 * Do not use it as an API
duke@1 40 *
duke@1 41 * @author Jamie Ho
duke@1 42 * @since 1.5
duke@1 43 */
duke@1 44 public class EnumConstantBuilder extends AbstractMemberBuilder {
duke@1 45
duke@1 46 /**
duke@1 47 * The class whose enum constants are being documented.
duke@1 48 */
duke@1 49 private ClassDoc classDoc;
duke@1 50
duke@1 51 /**
duke@1 52 * The visible enum constantss for the given class.
duke@1 53 */
duke@1 54 private VisibleMemberMap visibleMemberMap;
duke@1 55
duke@1 56 /**
duke@1 57 * The writer to output the enum constants documentation.
duke@1 58 */
duke@1 59 private EnumConstantWriter writer;
duke@1 60
duke@1 61 /**
duke@1 62 * The list of enum constants being documented.
duke@1 63 */
jjg@74 64 private List<ProgramElementDoc> enumConstants;
duke@1 65
duke@1 66 /**
duke@1 67 * The index of the current enum constant that is being documented at this point
duke@1 68 * in time.
duke@1 69 */
duke@1 70 private int currentEnumConstantsIndex;
duke@1 71
duke@1 72 /**
duke@1 73 * Construct a new EnumConstantsBuilder.
duke@1 74 *
duke@1 75 * @param configuration the current configuration of the
duke@1 76 * doclet.
duke@1 77 */
duke@1 78 private EnumConstantBuilder(Configuration configuration) {
duke@1 79 super(configuration);
duke@1 80 }
duke@1 81
duke@1 82 /**
duke@1 83 * Construct a new EnumConstantsBuilder.
duke@1 84 *
duke@1 85 * @param configuration the current configuration of the doclet.
duke@1 86 * @param classDoc the class whoses members are being documented.
duke@1 87 * @param writer the doclet specific writer.
duke@1 88 */
duke@1 89 public static EnumConstantBuilder getInstance(
duke@1 90 Configuration configuration,
duke@1 91 ClassDoc classDoc,
duke@1 92 EnumConstantWriter writer) {
duke@1 93 EnumConstantBuilder builder = new EnumConstantBuilder(configuration);
duke@1 94 builder.classDoc = classDoc;
duke@1 95 builder.writer = writer;
duke@1 96 builder.visibleMemberMap =
duke@1 97 new VisibleMemberMap(
duke@1 98 classDoc,
duke@1 99 VisibleMemberMap.ENUM_CONSTANTS,
duke@1 100 configuration.nodeprecated);
duke@1 101 builder.enumConstants =
jjg@74 102 new ArrayList<ProgramElementDoc>(builder.visibleMemberMap.getMembersFor(classDoc));
duke@1 103 if (configuration.getMemberComparator() != null) {
duke@1 104 Collections.sort(
duke@1 105 builder.enumConstants,
duke@1 106 configuration.getMemberComparator());
duke@1 107 }
duke@1 108 return builder;
duke@1 109 }
duke@1 110
duke@1 111 /**
duke@1 112 * {@inheritDoc}
duke@1 113 */
duke@1 114 public String getName() {
duke@1 115 return "EnumConstantDetails";
duke@1 116 }
duke@1 117
duke@1 118 /**
duke@1 119 * {@inheritDoc}
duke@1 120 */
duke@1 121 public void invokeMethod(
duke@1 122 String methodName,
duke@1 123 Class[] paramClasses,
duke@1 124 Object[] params)
duke@1 125 throws Exception {
duke@1 126 if (DEBUG) {
duke@1 127 configuration.root.printError(
duke@1 128 "DEBUG: " + this.getClass().getName() + "." + methodName);
duke@1 129 }
duke@1 130 Method method = this.getClass().getMethod(methodName, paramClasses);
duke@1 131 method.invoke(this, params);
duke@1 132 }
duke@1 133
duke@1 134 /**
duke@1 135 * Returns a list of enum constants that will be documented for the given class.
duke@1 136 * This information can be used for doclet specific documentation
duke@1 137 * generation.
duke@1 138 *
duke@1 139 * @param classDoc the {@link ClassDoc} we want to check.
duke@1 140 * @return a list of enum constants that will be documented.
duke@1 141 */
duke@1 142 public List members(ClassDoc classDoc) {
duke@1 143 return visibleMemberMap.getMembersFor(classDoc);
duke@1 144 }
duke@1 145
duke@1 146 /**
duke@1 147 * Returns the visible member map for the enum constants of this class.
duke@1 148 *
duke@1 149 * @return the visible member map for the enum constants of this class.
duke@1 150 */
duke@1 151 public VisibleMemberMap getVisibleMemberMap() {
duke@1 152 return visibleMemberMap;
duke@1 153 }
duke@1 154
duke@1 155 /**
duke@1 156 * summaryOrder.size()
duke@1 157 */
duke@1 158 public boolean hasMembersToDocument() {
duke@1 159 return enumConstants.size() > 0;
duke@1 160 }
duke@1 161
duke@1 162 /**
duke@1 163 * Build the enum constant documentation.
duke@1 164 *
duke@1 165 * @param elements the XML elements that specify how to construct this
duke@1 166 * documentation.
duke@1 167 */
duke@1 168 public void buildEnumConstant(List elements) {
duke@1 169 if (writer == null) {
duke@1 170 return;
duke@1 171 }
duke@1 172 for (currentEnumConstantsIndex = 0;
duke@1 173 currentEnumConstantsIndex < enumConstants.size();
duke@1 174 currentEnumConstantsIndex++) {
duke@1 175 build(elements);
duke@1 176 }
duke@1 177 }
duke@1 178
duke@1 179 /**
duke@1 180 * Build the overall header.
duke@1 181 */
duke@1 182 public void buildHeader() {
duke@1 183 writer.writeHeader(
duke@1 184 classDoc,
duke@1 185 configuration.getText("doclet.Enum_Constant_Detail"));
duke@1 186 }
duke@1 187
duke@1 188 /**
duke@1 189 * Build the header for the individual enum constants.
duke@1 190 */
duke@1 191 public void buildEnumConstantHeader() {
duke@1 192 writer.writeEnumConstantHeader(
duke@1 193 (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
duke@1 194 currentEnumConstantsIndex == 0);
duke@1 195 }
duke@1 196
duke@1 197 /**
duke@1 198 * Build the signature.
duke@1 199 */
duke@1 200 public void buildSignature() {
duke@1 201 writer.writeSignature(
duke@1 202 (FieldDoc) enumConstants.get(currentEnumConstantsIndex));
duke@1 203 }
duke@1 204
duke@1 205 /**
duke@1 206 * Build the deprecation information.
duke@1 207 */
duke@1 208 public void buildDeprecationInfo() {
duke@1 209 writer.writeDeprecated(
duke@1 210 (FieldDoc) enumConstants.get(currentEnumConstantsIndex));
duke@1 211 }
duke@1 212
duke@1 213 /**
duke@1 214 * Build the comments for the enum constant. Do nothing if
duke@1 215 * {@link Configuration#nocomment} is set to true.
duke@1 216 */
duke@1 217 public void buildEnumConstantComments() {
duke@1 218 if (!configuration.nocomment) {
duke@1 219 writer.writeComments(
duke@1 220 (FieldDoc) enumConstants.get(currentEnumConstantsIndex));
duke@1 221 }
duke@1 222 }
duke@1 223
duke@1 224 /**
duke@1 225 * Build the tag information.
duke@1 226 */
duke@1 227 public void buildTagInfo() {
duke@1 228 writer.writeTags(
duke@1 229 (FieldDoc) enumConstants.get(currentEnumConstantsIndex));
duke@1 230 }
duke@1 231
duke@1 232 /**
duke@1 233 * Build the footer for the individual enum constants.
duke@1 234 */
duke@1 235 public void buildEnumConstantFooter() {
duke@1 236 writer.writeEnumConstantFooter();
duke@1 237 }
duke@1 238
duke@1 239 /**
duke@1 240 * Build the overall footer.
duke@1 241 */
duke@1 242 public void buildFooter() {
duke@1 243 writer.writeFooter(classDoc);
duke@1 244 }
duke@1 245
duke@1 246 /**
duke@1 247 * Return the enum constant writer for this builder.
duke@1 248 *
duke@1 249 * @return the enum constant writer for this builder.
duke@1 250 */
duke@1 251 public EnumConstantWriter getWriter() {
duke@1 252 return writer;
duke@1 253 }
duke@1 254 }

mercurial