author | mcimadamore |
Tue, 13 Jan 2009 13:27:14 +0000 | |
changeset 1789 | 7ac8c0815000 |
parent 1264 | 076a3cde30d5 |
child 5520 | 86e4b9a9da40 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
1264 | 2 |
* Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved. |
10 | 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 field. |
|
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 FieldBuilder extends AbstractMemberBuilder { |
|
45 |
||
46 |
/** |
|
47 |
* The class whose fields are being documented. |
|
48 |
*/ |
|
49 |
private ClassDoc classDoc; |
|
50 |
||
51 |
/** |
|
52 |
* The visible fields for the given class. |
|
53 |
*/ |
|
54 |
private VisibleMemberMap visibleMemberMap; |
|
55 |
||
56 |
/** |
|
57 |
* The writer to output the field documentation. |
|
58 |
*/ |
|
59 |
private FieldWriter writer; |
|
60 |
||
61 |
/** |
|
62 |
* The list of fields being documented. |
|
63 |
*/ |
|
868 | 64 |
private List<ProgramElementDoc> fields; |
10 | 65 |
|
66 |
/** |
|
67 |
* The index of the current field that is being documented at this point |
|
68 |
* in time. |
|
69 |
*/ |
|
70 |
private int currentFieldIndex; |
|
71 |
||
72 |
/** |
|
73 |
* Construct a new FieldBuilder. |
|
74 |
* |
|
75 |
* @param configuration the current configuration of the |
|
76 |
* doclet. |
|
77 |
*/ |
|
78 |
private FieldBuilder(Configuration configuration) { |
|
79 |
super(configuration); |
|
80 |
} |
|
81 |
||
82 |
/** |
|
83 |
* Construct a new FieldBuilder. |
|
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 FieldBuilder getInstance( |
|
90 |
Configuration configuration, |
|
91 |
ClassDoc classDoc, |
|
92 |
FieldWriter writer) { |
|
93 |
FieldBuilder builder = new FieldBuilder(configuration); |
|
94 |
builder.classDoc = classDoc; |
|
95 |
builder.writer = writer; |
|
96 |
builder.visibleMemberMap = |
|
97 |
new VisibleMemberMap( |
|
98 |
classDoc, |
|
99 |
VisibleMemberMap.FIELDS, |
|
100 |
configuration.nodeprecated); |
|
101 |
builder.fields = |
|
868 | 102 |
new ArrayList<ProgramElementDoc>(builder.visibleMemberMap.getLeafClassMembers( |
103 |
configuration)); |
|
10 | 104 |
if (configuration.getMemberComparator() != null) { |
105 |
Collections.sort( |
|
106 |
builder.fields, |
|
107 |
configuration.getMemberComparator()); |
|
108 |
} |
|
109 |
return builder; |
|
110 |
} |
|
111 |
||
112 |
/** |
|
113 |
* {@inheritDoc} |
|
114 |
*/ |
|
115 |
public String getName() { |
|
116 |
return "FieldDetails"; |
|
117 |
} |
|
118 |
||
119 |
/** |
|
120 |
* {@inheritDoc} |
|
121 |
*/ |
|
122 |
public void invokeMethod( |
|
123 |
String methodName, |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
124 |
Class<?>[] paramClasses, |
10 | 125 |
Object[] params) |
126 |
throws Exception { |
|
127 |
if (DEBUG) { |
|
128 |
configuration.root.printError( |
|
129 |
"DEBUG: " + this.getClass().getName() + "." + methodName); |
|
130 |
} |
|
131 |
Method method = this.getClass().getMethod(methodName, paramClasses); |
|
132 |
method.invoke(this, params); |
|
133 |
} |
|
134 |
||
135 |
/** |
|
136 |
* Returns a list of fields that will be documented for the given class. |
|
137 |
* This information can be used for doclet specific documentation |
|
138 |
* generation. |
|
139 |
* |
|
140 |
* @param classDoc the {@link ClassDoc} we want to check. |
|
141 |
* @return a list of fields that will be documented. |
|
142 |
*/ |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
143 |
public List<ProgramElementDoc> members(ClassDoc classDoc) { |
10 | 144 |
return visibleMemberMap.getMembersFor(classDoc); |
145 |
} |
|
146 |
||
147 |
/** |
|
148 |
* Returns the visible member map for the fields of this class. |
|
149 |
* |
|
150 |
* @return the visible member map for the fields of this class. |
|
151 |
*/ |
|
152 |
public VisibleMemberMap getVisibleMemberMap() { |
|
153 |
return visibleMemberMap; |
|
154 |
} |
|
155 |
||
156 |
/** |
|
157 |
* summaryOrder.size() |
|
158 |
*/ |
|
159 |
public boolean hasMembersToDocument() { |
|
160 |
return fields.size() > 0; |
|
161 |
} |
|
162 |
||
163 |
/** |
|
164 |
* Build the field documentation. |
|
165 |
* |
|
166 |
* @param elements the XML elements that specify how to construct this |
|
167 |
* documentation. |
|
168 |
*/ |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
169 |
public void buildFieldDoc(List<?> elements) { |
10 | 170 |
if (writer == null) { |
171 |
return; |
|
172 |
} |
|
173 |
for (currentFieldIndex = 0; |
|
174 |
currentFieldIndex < fields.size(); |
|
175 |
currentFieldIndex++) { |
|
176 |
build(elements); |
|
177 |
} |
|
178 |
} |
|
179 |
||
180 |
/** |
|
181 |
* Build the overall header. |
|
182 |
*/ |
|
183 |
public void buildHeader() { |
|
184 |
writer.writeHeader( |
|
185 |
classDoc, |
|
186 |
configuration.getText("doclet.Field_Detail")); |
|
187 |
} |
|
188 |
||
189 |
/** |
|
190 |
* Build the header for the individual field. |
|
191 |
*/ |
|
192 |
public void buildFieldHeader() { |
|
193 |
writer.writeFieldHeader( |
|
194 |
(FieldDoc) fields.get(currentFieldIndex), |
|
195 |
currentFieldIndex == 0); |
|
196 |
} |
|
197 |
||
198 |
/** |
|
199 |
* Build the signature. |
|
200 |
*/ |
|
201 |
public void buildSignature() { |
|
202 |
writer.writeSignature((FieldDoc) fields.get(currentFieldIndex)); |
|
203 |
} |
|
204 |
||
205 |
/** |
|
206 |
* Build the deprecation information. |
|
207 |
*/ |
|
208 |
public void buildDeprecationInfo() { |
|
209 |
writer.writeDeprecated((FieldDoc) fields.get(currentFieldIndex)); |
|
210 |
} |
|
211 |
||
212 |
/** |
|
213 |
* Build the comments for the field. Do nothing if |
|
214 |
* {@link Configuration#nocomment} is set to true. |
|
215 |
*/ |
|
216 |
public void buildFieldComments() { |
|
217 |
if (!configuration.nocomment) { |
|
218 |
writer.writeComments((FieldDoc) fields.get(currentFieldIndex)); |
|
219 |
} |
|
220 |
} |
|
221 |
||
222 |
/** |
|
223 |
* Build the tag information. |
|
224 |
*/ |
|
225 |
public void buildTagInfo() { |
|
226 |
writer.writeTags((FieldDoc) fields.get(currentFieldIndex)); |
|
227 |
} |
|
228 |
||
229 |
/** |
|
230 |
* Build the footer for the individual field. |
|
231 |
*/ |
|
232 |
public void buildFieldFooter() { |
|
233 |
writer.writeFieldFooter(); |
|
234 |
} |
|
235 |
||
236 |
/** |
|
237 |
* Build the overall footer. |
|
238 |
*/ |
|
239 |
public void buildFooter() { |
|
240 |
writer.writeFooter(classDoc); |
|
241 |
} |
|
242 |
||
243 |
/** |
|
244 |
* Return the field writer for this builder. |
|
245 |
* |
|
246 |
* @return the field writer for this builder. |
|
247 |
*/ |
|
248 |
public FieldWriter getWriter() { |
|
249 |
return writer; |
|
250 |
} |
|
251 |
} |