Tue, 28 Dec 2010 15:54:52 -0800
6962318: Update copyright year
Reviewed-by: xdono
1 /*
2 * Copyright (c) 2003, 2010, 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.*;
29 import com.sun.tools.doclets.internal.toolkit.util.*;
30 import com.sun.tools.doclets.internal.toolkit.*;
31 import com.sun.javadoc.*;
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 * @author Bhavesh Patel (Modified)
42 * @since 1.5
43 */
44 public class MethodBuilder extends AbstractMemberBuilder {
46 /**
47 * The index of the current field that is being documented at this point
48 * in time.
49 */
50 private int currentMethodIndex;
52 /**
53 * The class whose methods are being documented.
54 */
55 private ClassDoc classDoc;
57 /**
58 * The visible methods for the given class.
59 */
60 private VisibleMemberMap visibleMemberMap;
62 /**
63 * The writer to output the method documentation.
64 */
65 private MethodWriter writer;
67 /**
68 * The methods being documented.
69 */
70 private List<ProgramElementDoc> methods;
72 private MethodBuilder(Configuration configuration) {
73 super(configuration);
74 }
76 /**
77 * Construct a new MethodBuilder.
78 *
79 * @param configuration the current configuration of the doclet.
80 * @param classDoc the class whoses members are being documented.
81 * @param writer the doclet specific writer.
82 *
83 * @return an instance of a MethodBuilder.
84 */
85 public static MethodBuilder getInstance(
86 Configuration configuration,
87 ClassDoc classDoc,
88 MethodWriter writer) {
89 MethodBuilder builder = new MethodBuilder(configuration);
90 builder.classDoc = classDoc;
91 builder.writer = writer;
92 builder.visibleMemberMap =
93 new VisibleMemberMap(
94 classDoc,
95 VisibleMemberMap.METHODS,
96 configuration.nodeprecated);
97 builder.methods =
98 new ArrayList<ProgramElementDoc>(builder.visibleMemberMap.getLeafClassMembers(
99 configuration));
100 if (configuration.getMemberComparator() != null) {
101 Collections.sort(
102 builder.methods,
103 configuration.getMemberComparator());
104 }
105 return builder;
106 }
108 /**
109 * {@inheritDoc}
110 */
111 public String getName() {
112 return "MethodDetails";
113 }
115 /**
116 * Returns a list of methods that will be documented for the given class.
117 * This information can be used for doclet specific documentation
118 * generation.
119 *
120 * @param classDoc the {@link ClassDoc} we want to check.
121 * @return a list of methods that will be documented.
122 */
123 public List<ProgramElementDoc> members(ClassDoc classDoc) {
124 return visibleMemberMap.getMembersFor(classDoc);
125 }
127 /**
128 * Returns the visible member map for the methods of this class.
129 *
130 * @return the visible member map for the methods of this class.
131 */
132 public VisibleMemberMap getVisibleMemberMap() {
133 return visibleMemberMap;
134 }
136 /**
137 * {@inheritDoc}
138 */
139 public boolean hasMembersToDocument() {
140 return methods.size() > 0;
141 }
143 /**
144 * Build the method documentation.
145 *
146 * @param node the XML element that specifies which components to document
147 * @param memberDetailsTree the content tree to which the documentation will be added
148 */
149 public void buildMethodDoc(XMLNode node, Content memberDetailsTree) {
150 if (writer == null) {
151 return;
152 }
153 int size = methods.size();
154 if (size > 0) {
155 Content methodDetailsTree = writer.getMethodDetailsTreeHeader(
156 classDoc, memberDetailsTree);
157 for (currentMethodIndex = 0; currentMethodIndex < size;
158 currentMethodIndex++) {
159 Content methodDocTree = writer.getMethodDocTreeHeader(
160 (MethodDoc) methods.get(currentMethodIndex),
161 methodDetailsTree);
162 buildChildren(node, methodDocTree);
163 methodDetailsTree.addContent(writer.getMethodDoc(
164 methodDocTree, (currentMethodIndex == size - 1)));
165 }
166 memberDetailsTree.addContent(
167 writer.getMethodDetails(methodDetailsTree));
168 }
169 }
171 /**
172 * Build the signature.
173 *
174 * @param node the XML element that specifies which components to document
175 * @param methodDocTree the content tree to which the documentation will be added
176 */
177 public void buildSignature(XMLNode node, Content methodDocTree) {
178 methodDocTree.addContent(
179 writer.getSignature((MethodDoc) methods.get(currentMethodIndex)));
180 }
182 /**
183 * Build the deprecation information.
184 *
185 * @param node the XML element that specifies which components to document
186 * @param methodDocTree the content tree to which the documentation will be added
187 */
188 public void buildDeprecationInfo(XMLNode node, Content methodDocTree) {
189 writer.addDeprecated(
190 (MethodDoc) methods.get(currentMethodIndex), methodDocTree);
191 }
193 /**
194 * Build the comments for the method. Do nothing if
195 * {@link Configuration#nocomment} is set to true.
196 *
197 * @param node the XML element that specifies which components to document
198 * @param methodDocTree the content tree to which the documentation will be added
199 */
200 public void buildMethodComments(XMLNode node, Content methodDocTree) {
201 if (!configuration.nocomment) {
202 MethodDoc method = (MethodDoc) methods.get(currentMethodIndex);
204 if (method.inlineTags().length == 0) {
205 DocFinder.Output docs = DocFinder.search(
206 new DocFinder.Input(method));
207 method = docs.inlineTags != null && docs.inlineTags.length > 0 ?
208 (MethodDoc) docs.holder : method;
209 }
210 //NOTE: When we fix the bug where ClassDoc.interfaceTypes() does
211 // not pass all implemented interfaces, holder will be the
212 // interface type. For now, it is really the erasure.
213 writer.addComments(method.containingClass(), method, methodDocTree);
214 }
215 }
217 /**
218 * Build the tag information.
219 *
220 * @param node the XML element that specifies which components to document
221 * @param methodDocTree the content tree to which the documentation will be added
222 */
223 public void buildTagInfo(XMLNode node, Content methodDocTree) {
224 writer.addTags((MethodDoc) methods.get(currentMethodIndex),
225 methodDocTree);
226 }
228 /**
229 * Return the method writer for this builder.
230 *
231 * @return the method writer for this builder.
232 */
233 public MethodWriter getWriter() {
234 return writer;
235 }
236 }