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