Thu, 02 Oct 2008 19:58:40 -0700
6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell
1 /*
2 * Copyright 2003-2008 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 */
26 package com.sun.tools.doclets.internal.toolkit.builders;
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 * Builds documentation for a method.
35 *
36 * This code is not part of an API.
37 * It is implementation that is subject to change.
38 * Do not use it as an API
39 *
40 * @author Jamie Ho
41 * @since 1.5
42 */
43 public class MethodBuilder extends AbstractMemberBuilder {
45 /**
46 * The index of the current field that is being documented at this point
47 * in time.
48 */
49 private int currentMethodIndex;
51 /**
52 * The class whose methods are being documented.
53 */
54 private ClassDoc classDoc;
56 /**
57 * The visible methods for the given class.
58 */
59 private VisibleMemberMap visibleMemberMap;
61 /**
62 * The writer to output the method documentation.
63 */
64 private MethodWriter writer;
66 /**
67 * The methods being documented.
68 */
69 private List<ProgramElementDoc> methods;
71 private MethodBuilder(Configuration configuration) {
72 super(configuration);
73 }
75 /**
76 * Construct a new MethodBuilder.
77 *
78 * @param configuration the current configuration of the doclet.
79 * @param classDoc the class whoses members are being documented.
80 * @param writer the doclet specific writer.
81 *
82 * @return an instance of a MethodBuilder.
83 */
84 public static MethodBuilder getInstance(
85 Configuration configuration,
86 ClassDoc classDoc,
87 MethodWriter writer) {
88 MethodBuilder builder = new MethodBuilder(configuration);
89 builder.classDoc = classDoc;
90 builder.writer = writer;
91 builder.visibleMemberMap =
92 new VisibleMemberMap(
93 classDoc,
94 VisibleMemberMap.METHODS,
95 configuration.nodeprecated);
96 builder.methods =
97 new ArrayList<ProgramElementDoc>(builder.visibleMemberMap.getLeafClassMembers(
98 configuration));
99 if (configuration.getMemberComparator() != null) {
100 Collections.sort(
101 builder.methods,
102 configuration.getMemberComparator());
103 }
104 return builder;
105 }
107 /**
108 * {@inheritDoc}
109 */
110 public String getName() {
111 return "MethodDetails";
112 }
114 /**
115 * {@inheritDoc}
116 */
117 public void invokeMethod(
118 String methodName,
119 Class[] paramClasses,
120 Object[] params)
121 throws Exception {
122 if (DEBUG) {
123 configuration.root.printError(
124 "DEBUG: " + this.getClass().getName() + "." + methodName);
125 }
126 Method method = this.getClass().getMethod(methodName, paramClasses);
127 method.invoke(this, params);
128 }
130 /**
131 * Returns a list of methods that will be documented for the given class.
132 * This information can be used for doclet specific documentation
133 * generation.
134 *
135 * @param classDoc the {@link ClassDoc} we want to check.
136 * @return a list of methods that will be documented.
137 */
138 public List members(ClassDoc classDoc) {
139 return visibleMemberMap.getMembersFor(classDoc);
140 }
142 /**
143 * Returns the visible member map for the methods of this class.
144 *
145 * @return the visible member map for the methods of this class.
146 */
147 public VisibleMemberMap getVisibleMemberMap() {
148 return visibleMemberMap;
149 }
151 /**
152 * {@inheritDoc}
153 */
154 public boolean hasMembersToDocument() {
155 return methods.size() > 0;
156 }
158 /**
159 * Build the method documentation.
160 */
161 public void buildMethodDoc(List elements) {
162 if (writer == null) {
163 return;
164 }
165 for (currentMethodIndex = 0;
166 currentMethodIndex < methods.size();
167 currentMethodIndex++) {
168 build(elements);
169 }
170 }
172 /**
173 * Build the overall header.
174 */
175 public void buildHeader() {
176 writer.writeHeader(
177 classDoc,
178 configuration.getText("doclet.Method_Detail"));
179 }
181 /**
182 * Build the header for the individual method.
183 */
184 public void buildMethodHeader() {
185 writer.writeMethodHeader(
186 (MethodDoc) methods.get(currentMethodIndex),
187 currentMethodIndex == 0);
188 }
190 /**
191 * Build the signature.
192 */
193 public void buildSignature() {
194 writer.writeSignature((MethodDoc) methods.get(currentMethodIndex));
195 }
197 /**
198 * Build the deprecation information.
199 */
200 public void buildDeprecationInfo() {
201 writer.writeDeprecated((MethodDoc) methods.get(currentMethodIndex));
202 }
204 /**
205 * Build the comments for the method. Do nothing if
206 * {@link Configuration#nocomment} is set to true. If this method
207 */
208 public void buildMethodComments() {
209 if (!configuration.nocomment) {
210 MethodDoc method = (MethodDoc) methods.get(currentMethodIndex);
212 if (method.inlineTags().length == 0) {
213 DocFinder.Output docs = DocFinder.search(
214 new DocFinder.Input(method));
215 method = docs.inlineTags != null && docs.inlineTags.length > 0 ?
216 (MethodDoc) docs.holder : method;
218 }
219 //NOTE: When we fix the bug where ClassDoc.interfaceTypes() does
220 // not pass all implemented interfaces, holder will be the
221 // interface type. For now, it is really the erasure.
222 writer.writeComments(method.containingClass(), method);
223 }
224 }
228 /**
229 * Build the tag information.
230 */
231 public void buildTagInfo() {
232 writer.writeTags((MethodDoc) methods.get(currentMethodIndex));
233 }
235 /**
236 * Build the footer of the method.
237 */
238 public void buildMethodFooter() {
239 writer.writeMethodFooter();
240 }
242 /**
243 * Build the overall footer.
244 */
245 public void buildFooter() {
246 writer.writeFooter(classDoc);
247 }
249 /**
250 * Return the method writer for this builder.
251 *
252 * @return the method writer for this builder.
253 */
254 public MethodWriter getWriter() {
255 return writer;
256 }
257 }