Wed, 31 Oct 2012 13:48:15 -0700
8001664: refactor javadoc to use abstraction to handle files
Reviewed-by: darcy
1 /*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.tools.doclets.internal.toolkit.builders;
28 import java.util.*;
30 import com.sun.javadoc.*;
31 import com.sun.tools.doclets.internal.toolkit.*;
32 import com.sun.tools.doclets.internal.toolkit.util.*;
34 /**
35 * Builds documentation for a enum constants.
36 *
37 * <p><b>This is NOT part of any supported API.
38 * If you write code that depends on this, you do so at your own risk.
39 * This code and its internal interfaces are subject to change or
40 * deletion without notice.</b>
41 *
42 * @author Jamie Ho
43 * @author Bhavesh Patel (Modified)
44 * @since 1.5
45 */
46 public class EnumConstantBuilder extends AbstractMemberBuilder {
48 /**
49 * The class whose enum constants are being documented.
50 */
51 private ClassDoc classDoc;
53 /**
54 * The visible enum constantss for the given class.
55 */
56 private VisibleMemberMap visibleMemberMap;
58 /**
59 * The writer to output the enum constants documentation.
60 */
61 private EnumConstantWriter writer;
63 /**
64 * The list of enum constants being documented.
65 */
66 private List<ProgramElementDoc> enumConstants;
68 /**
69 * The index of the current enum constant that is being documented at this point
70 * in time.
71 */
72 private int currentEnumConstantsIndex;
74 /**
75 * Construct a new EnumConstantsBuilder.
76 *
77 * @param configuration the current configuration of the
78 * doclet.
79 */
80 private EnumConstantBuilder(Configuration configuration) {
81 super(configuration);
82 }
84 /**
85 * Construct a new EnumConstantsBuilder.
86 *
87 * @param configuration the current configuration of the doclet.
88 * @param classDoc the class whoses members are being documented.
89 * @param writer the doclet specific writer.
90 */
91 public static EnumConstantBuilder getInstance(
92 Configuration configuration,
93 ClassDoc classDoc,
94 EnumConstantWriter writer) {
95 EnumConstantBuilder builder = new EnumConstantBuilder(configuration);
96 builder.classDoc = classDoc;
97 builder.writer = writer;
98 builder.visibleMemberMap =
99 new VisibleMemberMap(
100 classDoc,
101 VisibleMemberMap.ENUM_CONSTANTS,
102 configuration.nodeprecated);
103 builder.enumConstants =
104 new ArrayList<ProgramElementDoc>(builder.visibleMemberMap.getMembersFor(classDoc));
105 if (configuration.getMemberComparator() != null) {
106 Collections.sort(
107 builder.enumConstants,
108 configuration.getMemberComparator());
109 }
110 return builder;
111 }
113 /**
114 * {@inheritDoc}
115 */
116 public String getName() {
117 return "EnumConstantDetails";
118 }
120 /**
121 * Returns a list of enum constants that will be documented for the given class.
122 * This information can be used for doclet specific documentation
123 * generation.
124 *
125 * @param classDoc the {@link ClassDoc} we want to check.
126 * @return a list of enum constants that will be documented.
127 */
128 public List<ProgramElementDoc> members(ClassDoc classDoc) {
129 return visibleMemberMap.getMembersFor(classDoc);
130 }
132 /**
133 * Returns the visible member map for the enum constants of this class.
134 *
135 * @return the visible member map for the enum constants of this class.
136 */
137 public VisibleMemberMap getVisibleMemberMap() {
138 return visibleMemberMap;
139 }
141 /**
142 * summaryOrder.size()
143 */
144 public boolean hasMembersToDocument() {
145 return enumConstants.size() > 0;
146 }
148 /**
149 * Build the enum constant documentation.
150 *
151 * @param node the XML element that specifies which components to document
152 * @param memberDetailsTree the content tree to which the documentation will be added
153 */
154 public void buildEnumConstant(XMLNode node, Content memberDetailsTree) {
155 if (writer == null) {
156 return;
157 }
158 int size = enumConstants.size();
159 if (size > 0) {
160 Content enumConstantsDetailsTree = writer.getEnumConstantsDetailsTreeHeader(
161 classDoc, memberDetailsTree);
162 for (currentEnumConstantsIndex = 0; currentEnumConstantsIndex < size;
163 currentEnumConstantsIndex++) {
164 Content enumConstantsTree = writer.getEnumConstantsTreeHeader(
165 (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
166 enumConstantsDetailsTree);
167 buildChildren(node, enumConstantsTree);
168 enumConstantsDetailsTree.addContent(writer.getEnumConstants(
169 enumConstantsTree, (currentEnumConstantsIndex == size - 1)));
170 }
171 memberDetailsTree.addContent(
172 writer.getEnumConstantsDetails(enumConstantsDetailsTree));
173 }
174 }
176 /**
177 * Build the signature.
178 *
179 * @param node the XML element that specifies which components to document
180 * @param enumConstantsTree the content tree to which the documentation will be added
181 */
182 public void buildSignature(XMLNode node, Content enumConstantsTree) {
183 enumConstantsTree.addContent(writer.getSignature(
184 (FieldDoc) enumConstants.get(currentEnumConstantsIndex)));
185 }
187 /**
188 * Build the deprecation information.
189 *
190 * @param node the XML element that specifies which components to document
191 * @param enumConstantsTree the content tree to which the documentation will be added
192 */
193 public void buildDeprecationInfo(XMLNode node, Content enumConstantsTree) {
194 writer.addDeprecated(
195 (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
196 enumConstantsTree);
197 }
199 /**
200 * Build the comments for the enum constant. Do nothing if
201 * {@link Configuration#nocomment} is set to true.
202 *
203 * @param node the XML element that specifies which components to document
204 * @param enumConstantsTree the content tree to which the documentation will be added
205 */
206 public void buildEnumConstantComments(XMLNode node, Content enumConstantsTree) {
207 if (!configuration.nocomment) {
208 writer.addComments(
209 (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
210 enumConstantsTree);
211 }
212 }
214 /**
215 * Build the tag information.
216 *
217 * @param node the XML element that specifies which components to document
218 * @param enumConstantsTree the content tree to which the documentation will be added
219 */
220 public void buildTagInfo(XMLNode node, Content enumConstantsTree) {
221 writer.addTags(
222 (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
223 enumConstantsTree);
224 }
226 /**
227 * Return the enum constant writer for this builder.
228 *
229 * @return the enum constant writer for this builder.
230 */
231 public EnumConstantWriter getWriter() {
232 return writer;
233 }
234 }