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 constructor.
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 ConstructorBuilder extends AbstractMemberBuilder {
46 /**
47 * The name of this builder.
48 */
49 public static final String NAME = "ConstructorDetails";
51 /**
52 * The index of the current field that is being documented at this point
53 * in time.
54 */
55 private int currentConstructorIndex;
57 /**
58 * The class whose constructors are being documented.
59 */
60 private ClassDoc classDoc;
62 /**
63 * The visible constructors for the given class.
64 */
65 private VisibleMemberMap visibleMemberMap;
67 /**
68 * The writer to output the constructor documentation.
69 */
70 private ConstructorWriter writer;
72 /**
73 * The constructors being documented.
74 */
75 private List<ProgramElementDoc> constructors;
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 }
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 =
107 new ArrayList<ProgramElementDoc>(builder.visibleMemberMap.getMembersFor(classDoc));
108 for (int i = 0; i < builder.constructors.size(); i++) {
109 if (builder.constructors.get(i).isProtected()
110 || builder.constructors.get(i).isPrivate()) {
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 }
122 /**
123 * {@inheritDoc}
124 */
125 public String getName() {
126 return NAME;
127 }
129 /**
130 * {@inheritDoc}
131 */
132 public boolean hasMembersToDocument() {
133 return constructors.size() > 0;
134 }
136 /**
137 * Returns a list of constructors that will be documented for the given class.
138 * This information can be used for doclet specific documentation
139 * generation.
140 *
141 * @return a list of constructors that will be documented.
142 */
143 public List<ProgramElementDoc> members(ClassDoc classDoc) {
144 return visibleMemberMap.getMembersFor(classDoc);
145 }
147 /**
148 * Return the constructor writer for this builder.
149 *
150 * @return the constructor writer for this builder.
151 */
152 public ConstructorWriter getWriter() {
153 return writer;
154 }
156 /**
157 * Build the constructor documentation.
158 *
159 * @param node the XML element that specifies which components to document
160 * @param memberDetailsTree the content tree to which the documentation will be added
161 */
162 public void buildConstructorDoc(XMLNode node, Content memberDetailsTree) {
163 if (writer == null) {
164 return;
165 }
166 int size = constructors.size();
167 if (size > 0) {
168 Content constructorDetailsTree = writer.getConstructorDetailsTreeHeader(
169 classDoc, memberDetailsTree);
170 for (currentConstructorIndex = 0; currentConstructorIndex < size;
171 currentConstructorIndex++) {
172 Content constructorDocTree = writer.getConstructorDocTreeHeader(
173 (ConstructorDoc) constructors.get(currentConstructorIndex),
174 constructorDetailsTree);
175 buildChildren(node, constructorDocTree);
176 constructorDetailsTree.addContent(writer.getConstructorDoc(
177 constructorDocTree, (currentConstructorIndex == size - 1)));
178 }
179 memberDetailsTree.addContent(
180 writer.getConstructorDetails(constructorDetailsTree));
181 }
182 }
184 /**
185 * Build the signature.
186 *
187 * @param node the XML element that specifies which components to document
188 * @param constructorDocTree the content tree to which the documentation will be added
189 */
190 public void buildSignature(XMLNode node, Content constructorDocTree) {
191 constructorDocTree.addContent(
192 writer.getSignature(
193 (ConstructorDoc) constructors.get(currentConstructorIndex)));
194 }
196 /**
197 * Build the deprecation information.
198 *
199 * @param node the XML element that specifies which components to document
200 * @param constructorDocTree the content tree to which the documentation will be added
201 */
202 public void buildDeprecationInfo(XMLNode node, Content constructorDocTree) {
203 writer.addDeprecated(
204 (ConstructorDoc) constructors.get(currentConstructorIndex), constructorDocTree);
205 }
207 /**
208 * Build the comments for the constructor. Do nothing if
209 * {@link Configuration#nocomment} is set to true.
210 *
211 * @param node the XML element that specifies which components to document
212 * @param constructorDocTree the content tree to which the documentation will be added
213 */
214 public void buildConstructorComments(XMLNode node, Content constructorDocTree) {
215 if (!configuration.nocomment) {
216 writer.addComments(
217 (ConstructorDoc) constructors.get(currentConstructorIndex),
218 constructorDocTree);
219 }
220 }
222 /**
223 * Build the tag information.
224 *
225 * @param node the XML element that specifies which components to document
226 * @param constructorDocTree the content tree to which the documentation will be added
227 */
228 public void buildTagInfo(XMLNode node, Content constructorDocTree) {
229 writer.addTags((ConstructorDoc) constructors.get(currentConstructorIndex),
230 constructorDocTree);
231 }
232 }