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

Wed, 01 Dec 2010 11:02:38 -0800

author
bpatel
date
Wed, 01 Dec 2010 11:02:38 -0800
changeset 766
90af8d87741f
parent 589
4177f5bdd189
child 798
4868a36f6fd8
permissions
-rw-r--r--

6851834: Javadoc doclet needs a structured approach to generate the output HTML.
Reviewed-by: jjg

duke@1 1 /*
ohair@554 2 * Copyright (c) 2003, 2008, Oracle and/or its affiliates. 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
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle 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 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.doclets.internal.toolkit.builders;
duke@1 27
bpatel@766 28 import java.util.*;
duke@1 29 import com.sun.tools.doclets.internal.toolkit.util.*;
duke@1 30 import com.sun.tools.doclets.internal.toolkit.*;
duke@1 31 import com.sun.javadoc.*;
duke@1 32
duke@1 33 /**
duke@1 34 * Builds documentation for a enum constants.
duke@1 35 *
duke@1 36 * This code is not part of an API.
duke@1 37 * It is implementation that is subject to change.
duke@1 38 * Do not use it as an API
duke@1 39 *
duke@1 40 * @author Jamie Ho
bpatel@766 41 * @author Bhavesh Patel (Modified)
duke@1 42 * @since 1.5
duke@1 43 */
duke@1 44 public class EnumConstantBuilder extends AbstractMemberBuilder {
duke@1 45
bpatel@766 46 /**
bpatel@766 47 * The class whose enum constants are being documented.
bpatel@766 48 */
bpatel@766 49 private ClassDoc classDoc;
duke@1 50
bpatel@766 51 /**
bpatel@766 52 * The visible enum constantss for the given class.
bpatel@766 53 */
bpatel@766 54 private VisibleMemberMap visibleMemberMap;
duke@1 55
bpatel@766 56 /**
bpatel@766 57 * The writer to output the enum constants documentation.
bpatel@766 58 */
bpatel@766 59 private EnumConstantWriter writer;
duke@1 60
bpatel@766 61 /**
bpatel@766 62 * The list of enum constants being documented.
bpatel@766 63 */
bpatel@766 64 private List<ProgramElementDoc> enumConstants;
duke@1 65
bpatel@766 66 /**
bpatel@766 67 * The index of the current enum constant that is being documented at this point
bpatel@766 68 * in time.
bpatel@766 69 */
bpatel@766 70 private int currentEnumConstantsIndex;
duke@1 71
bpatel@766 72 /**
bpatel@766 73 * Construct a new EnumConstantsBuilder.
bpatel@766 74 *
bpatel@766 75 * @param configuration the current configuration of the
bpatel@766 76 * doclet.
bpatel@766 77 */
bpatel@766 78 private EnumConstantBuilder(Configuration configuration) {
bpatel@766 79 super(configuration);
bpatel@766 80 }
bpatel@766 81
bpatel@766 82 /**
bpatel@766 83 * Construct a new EnumConstantsBuilder.
bpatel@766 84 *
bpatel@766 85 * @param configuration the current configuration of the doclet.
bpatel@766 86 * @param classDoc the class whoses members are being documented.
bpatel@766 87 * @param writer the doclet specific writer.
bpatel@766 88 */
bpatel@766 89 public static EnumConstantBuilder getInstance(
bpatel@766 90 Configuration configuration,
bpatel@766 91 ClassDoc classDoc,
bpatel@766 92 EnumConstantWriter writer) {
bpatel@766 93 EnumConstantBuilder builder = new EnumConstantBuilder(configuration);
bpatel@766 94 builder.classDoc = classDoc;
bpatel@766 95 builder.writer = writer;
bpatel@766 96 builder.visibleMemberMap =
bpatel@766 97 new VisibleMemberMap(
bpatel@766 98 classDoc,
bpatel@766 99 VisibleMemberMap.ENUM_CONSTANTS,
bpatel@766 100 configuration.nodeprecated);
bpatel@766 101 builder.enumConstants =
bpatel@766 102 new ArrayList<ProgramElementDoc>(builder.visibleMemberMap.getMembersFor(classDoc));
bpatel@766 103 if (configuration.getMemberComparator() != null) {
bpatel@766 104 Collections.sort(
bpatel@766 105 builder.enumConstants,
bpatel@766 106 configuration.getMemberComparator());
duke@1 107 }
bpatel@766 108 return builder;
bpatel@766 109 }
duke@1 110
bpatel@766 111 /**
bpatel@766 112 * {@inheritDoc}
bpatel@766 113 */
bpatel@766 114 public String getName() {
bpatel@766 115 return "EnumConstantDetails";
bpatel@766 116 }
bpatel@766 117
bpatel@766 118 /**
bpatel@766 119 * Returns a list of enum constants that will be documented for the given class.
bpatel@766 120 * This information can be used for doclet specific documentation
bpatel@766 121 * generation.
bpatel@766 122 *
bpatel@766 123 * @param classDoc the {@link ClassDoc} we want to check.
bpatel@766 124 * @return a list of enum constants that will be documented.
bpatel@766 125 */
bpatel@766 126 public List<ProgramElementDoc> members(ClassDoc classDoc) {
bpatel@766 127 return visibleMemberMap.getMembersFor(classDoc);
bpatel@766 128 }
bpatel@766 129
bpatel@766 130 /**
bpatel@766 131 * Returns the visible member map for the enum constants of this class.
bpatel@766 132 *
bpatel@766 133 * @return the visible member map for the enum constants of this class.
bpatel@766 134 */
bpatel@766 135 public VisibleMemberMap getVisibleMemberMap() {
bpatel@766 136 return visibleMemberMap;
bpatel@766 137 }
bpatel@766 138
bpatel@766 139 /**
bpatel@766 140 * summaryOrder.size()
bpatel@766 141 */
bpatel@766 142 public boolean hasMembersToDocument() {
bpatel@766 143 return enumConstants.size() > 0;
bpatel@766 144 }
bpatel@766 145
bpatel@766 146 /**
bpatel@766 147 * Build the enum constant documentation.
bpatel@766 148 *
bpatel@766 149 * @param node the XML element that specifies which components to document
bpatel@766 150 * @param memberDetailsTree the content tree to which the documentation will be added
bpatel@766 151 */
bpatel@766 152 public void buildEnumConstant(XMLNode node, Content memberDetailsTree) {
bpatel@766 153 if (writer == null) {
bpatel@766 154 return;
duke@1 155 }
bpatel@766 156 int size = enumConstants.size();
bpatel@766 157 if (size > 0) {
bpatel@766 158 Content enumConstantsDetailsTree = writer.getEnumConstantsDetailsTreeHeader(
bpatel@766 159 classDoc, memberDetailsTree);
bpatel@766 160 for (currentEnumConstantsIndex = 0; currentEnumConstantsIndex < size;
bpatel@766 161 currentEnumConstantsIndex++) {
bpatel@766 162 Content enumConstantsTree = writer.getEnumConstantsTreeHeader(
bpatel@766 163 (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
bpatel@766 164 enumConstantsDetailsTree);
bpatel@766 165 buildChildren(node, enumConstantsTree);
bpatel@766 166 enumConstantsDetailsTree.addContent(writer.getEnumConstants(
bpatel@766 167 enumConstantsTree, (currentEnumConstantsIndex == size - 1)));
bpatel@766 168 }
bpatel@766 169 memberDetailsTree.addContent(
bpatel@766 170 writer.getEnumConstantsDetails(enumConstantsDetailsTree));
bpatel@766 171 }
bpatel@766 172 }
duke@1 173
bpatel@766 174 /**
bpatel@766 175 * Build the signature.
bpatel@766 176 *
bpatel@766 177 * @param node the XML element that specifies which components to document
bpatel@766 178 * @param enumConstantsTree the content tree to which the documentation will be added
bpatel@766 179 */
bpatel@766 180 public void buildSignature(XMLNode node, Content enumConstantsTree) {
bpatel@766 181 enumConstantsTree.addContent(writer.getSignature(
bpatel@766 182 (FieldDoc) enumConstants.get(currentEnumConstantsIndex)));
bpatel@766 183 }
bpatel@766 184
bpatel@766 185 /**
bpatel@766 186 * Build the deprecation information.
bpatel@766 187 *
bpatel@766 188 * @param node the XML element that specifies which components to document
bpatel@766 189 * @param enumConstantsTree the content tree to which the documentation will be added
bpatel@766 190 */
bpatel@766 191 public void buildDeprecationInfo(XMLNode node, Content enumConstantsTree) {
bpatel@766 192 writer.addDeprecated(
bpatel@766 193 (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
bpatel@766 194 enumConstantsTree);
bpatel@766 195 }
bpatel@766 196
bpatel@766 197 /**
bpatel@766 198 * Build the comments for the enum constant. Do nothing if
bpatel@766 199 * {@link Configuration#nocomment} is set to true.
bpatel@766 200 *
bpatel@766 201 * @param node the XML element that specifies which components to document
bpatel@766 202 * @param enumConstantsTree the content tree to which the documentation will be added
bpatel@766 203 */
bpatel@766 204 public void buildEnumConstantComments(XMLNode node, Content enumConstantsTree) {
bpatel@766 205 if (!configuration.nocomment) {
bpatel@766 206 writer.addComments(
bpatel@766 207 (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
bpatel@766 208 enumConstantsTree);
duke@1 209 }
bpatel@766 210 }
duke@1 211
bpatel@766 212 /**
bpatel@766 213 * Build the tag information.
bpatel@766 214 *
bpatel@766 215 * @param node the XML element that specifies which components to document
bpatel@766 216 * @param enumConstantsTree the content tree to which the documentation will be added
bpatel@766 217 */
bpatel@766 218 public void buildTagInfo(XMLNode node, Content enumConstantsTree) {
bpatel@766 219 writer.addTags(
bpatel@766 220 (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
bpatel@766 221 enumConstantsTree);
bpatel@766 222 }
duke@1 223
bpatel@766 224 /**
bpatel@766 225 * Return the enum constant writer for this builder.
bpatel@766 226 *
bpatel@766 227 * @return the enum constant writer for this builder.
bpatel@766 228 */
bpatel@766 229 public EnumConstantWriter getWriter() {
bpatel@766 230 return writer;
bpatel@766 231 }
duke@1 232 }

mercurial