src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/ConstructorBuilder.java

changeset 0
959103a6100f
child 2525
2eb010b6cb22
equal deleted inserted replaced
-1:000000000000 0:959103a6100f
1 /*
2 * Copyright (c) 2003, 2013, 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 */
25
26 package com.sun.tools.doclets.internal.toolkit.builders;
27
28 import java.util.*;
29
30 import com.sun.javadoc.*;
31 import com.sun.tools.doclets.internal.toolkit.*;
32 import com.sun.tools.doclets.internal.toolkit.util.*;
33
34 /**
35 * Builds documentation for a constructor.
36 *
37 * <p><b>This is NOT part of any supported API.
38 * If you write code that depends on this, you do so at your own risk.
39 * This code and its internal interfaces are subject to change or
40 * deletion without notice.</b>
41 *
42 * @author Jamie Ho
43 * @author Bhavesh Patel (Modified)
44 * @since 1.5
45 */
46 public class ConstructorBuilder extends AbstractMemberBuilder {
47
48 /**
49 * The name of this builder.
50 */
51 public static final String NAME = "ConstructorDetails";
52
53 /**
54 * The index of the current field that is being documented at this point
55 * in time.
56 */
57 private int currentConstructorIndex;
58
59 /**
60 * The class whose constructors are being documented.
61 */
62 private final ClassDoc classDoc;
63
64 /**
65 * The visible constructors for the given class.
66 */
67 private final VisibleMemberMap visibleMemberMap;
68
69 /**
70 * The writer to output the constructor documentation.
71 */
72 private final ConstructorWriter writer;
73
74 /**
75 * The constructors being documented.
76 */
77 private final List<ProgramElementDoc> constructors;
78
79 /**
80 * Construct a new ConstructorBuilder.
81 *
82 * @param context the build context.
83 * @param classDoc the class whoses members are being documented.
84 * @param writer the doclet specific writer.
85 */
86 private ConstructorBuilder(Context context,
87 ClassDoc classDoc,
88 ConstructorWriter writer) {
89 super(context);
90 this.classDoc = classDoc;
91 this.writer = writer;
92 visibleMemberMap =
93 new VisibleMemberMap(
94 classDoc,
95 VisibleMemberMap.CONSTRUCTORS,
96 configuration);
97 constructors =
98 new ArrayList<ProgramElementDoc>(visibleMemberMap.getMembersFor(classDoc));
99 for (int i = 0; i < constructors.size(); i++) {
100 if (constructors.get(i).isProtected()
101 || constructors.get(i).isPrivate()) {
102 writer.setFoundNonPubConstructor(true);
103 }
104 }
105 if (configuration.getMemberComparator() != null) {
106 Collections.sort(constructors,configuration.getMemberComparator());
107 }
108 }
109
110 /**
111 * Construct a new ConstructorBuilder.
112 *
113 * @param context the build context.
114 * @param classDoc the class whoses members are being documented.
115 * @param writer the doclet specific writer.
116 */
117 public static ConstructorBuilder getInstance(Context context,
118 ClassDoc classDoc, ConstructorWriter writer) {
119 return new ConstructorBuilder(context, classDoc, writer);
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 * 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 }
146
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 }
155
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 }
183
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 }
195
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 }
206
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 }
221
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 }

mercurial