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