Tue, 14 May 2013 10:14:54 -0700
8012175: Convert TagletOutputImpl to use ContentBuilder instead of StringBuilder
Reviewed-by: darcy
1 /*
2 * Copyright (c) 1997, 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 */
26 package com.sun.tools.doclets.formats.html;
28 import java.io.*;
29 import java.util.*;
31 import com.sun.javadoc.*;
32 import com.sun.tools.doclets.formats.html.markup.*;
33 import com.sun.tools.doclets.internal.toolkit.*;
34 import com.sun.tools.doclets.internal.toolkit.util.*;
36 /**
37 * Writes constructor documentation.
38 *
39 * <p><b>This is NOT part of any supported API.
40 * If you write code that depends on this, you do so at your own risk.
41 * This code and its internal interfaces are subject to change or
42 * deletion without notice.</b>
43 *
44 * @author Robert Field
45 * @author Atul M Dambalkar
46 * @author Bhavesh Patel (Modified)
47 */
48 public class ConstructorWriterImpl extends AbstractExecutableMemberWriter
49 implements ConstructorWriter, MemberSummaryWriter {
51 private boolean foundNonPubConstructor = false;
53 /**
54 * Construct a new ConstructorWriterImpl.
55 *
56 * @param writer The writer for the class that the constructors belong to.
57 * @param classDoc the class being documented.
58 */
59 public ConstructorWriterImpl(SubWriterHolderWriter writer,
60 ClassDoc classDoc) {
61 super(writer, classDoc);
62 VisibleMemberMap visibleMemberMap = new VisibleMemberMap(classDoc,
63 VisibleMemberMap.CONSTRUCTORS, configuration);
64 List<ProgramElementDoc> constructors = new ArrayList<ProgramElementDoc>(visibleMemberMap.getMembersFor(classDoc));
65 for (int i = 0; i < constructors.size(); i++) {
66 if ((constructors.get(i)).isProtected() ||
67 (constructors.get(i)).isPrivate()) {
68 setFoundNonPubConstructor(true);
69 }
70 }
71 }
73 /**
74 * Construct a new ConstructorWriterImpl.
75 *
76 * @param writer The writer for the class that the constructors belong to.
77 */
78 public ConstructorWriterImpl(SubWriterHolderWriter writer) {
79 super(writer);
80 }
82 /**
83 * {@inheritDoc}
84 */
85 public Content getMemberSummaryHeader(ClassDoc classDoc,
86 Content memberSummaryTree) {
87 memberSummaryTree.addContent(HtmlConstants.START_OF_CONSTRUCTOR_SUMMARY);
88 Content memberTree = writer.getMemberTreeHeader();
89 writer.addSummaryHeader(this, classDoc, memberTree);
90 return memberTree;
91 }
93 /**
94 * {@inheritDoc}
95 */
96 public Content getConstructorDetailsTreeHeader(ClassDoc classDoc,
97 Content memberDetailsTree) {
98 memberDetailsTree.addContent(HtmlConstants.START_OF_CONSTRUCTOR_DETAILS);
99 Content constructorDetailsTree = writer.getMemberTreeHeader();
100 constructorDetailsTree.addContent(writer.getMarkerAnchor("constructor_detail"));
101 Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING,
102 writer.constructorDetailsLabel);
103 constructorDetailsTree.addContent(heading);
104 return constructorDetailsTree;
105 }
107 /**
108 * {@inheritDoc}
109 */
110 public Content getConstructorDocTreeHeader(ConstructorDoc constructor,
111 Content constructorDetailsTree) {
112 String erasureAnchor;
113 if ((erasureAnchor = getErasureAnchor(constructor)) != null) {
114 constructorDetailsTree.addContent(writer.getMarkerAnchor((erasureAnchor)));
115 }
116 constructorDetailsTree.addContent(
117 writer.getMarkerAnchor(writer.getAnchor(constructor)));
118 Content constructorDocTree = writer.getMemberTreeHeader();
119 Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING);
120 heading.addContent(constructor.name());
121 constructorDocTree.addContent(heading);
122 return constructorDocTree;
123 }
125 /**
126 * {@inheritDoc}
127 */
128 public Content getSignature(ConstructorDoc constructor) {
129 Content pre = new HtmlTree(HtmlTag.PRE);
130 writer.addAnnotationInfo(constructor, pre);
131 addModifiers(constructor, pre);
132 if (configuration.linksource) {
133 Content constructorName = new StringContent(constructor.name());
134 writer.addSrcLink(constructor, constructorName, pre);
135 } else {
136 addName(constructor.name(), pre);
137 }
138 int indent = pre.charCount();
139 addParameters(constructor, pre, indent);
140 addExceptions(constructor, pre, indent);
141 return pre;
142 }
144 /**
145 * {@inheritDoc}
146 */
147 @Override
148 public void setSummaryColumnStyle(HtmlTree tdTree) {
149 if (foundNonPubConstructor)
150 tdTree.addStyle(HtmlStyle.colLast);
151 else
152 tdTree.addStyle(HtmlStyle.colOne);
153 }
155 /**
156 * {@inheritDoc}
157 */
158 public void addDeprecated(ConstructorDoc constructor, Content constructorDocTree) {
159 addDeprecatedInfo(constructor, constructorDocTree);
160 }
162 /**
163 * {@inheritDoc}
164 */
165 public void addComments(ConstructorDoc constructor, Content constructorDocTree) {
166 addComment(constructor, constructorDocTree);
167 }
169 /**
170 * {@inheritDoc}
171 */
172 public void addTags(ConstructorDoc constructor, Content constructorDocTree) {
173 writer.addTagsInfo(constructor, constructorDocTree);
174 }
176 /**
177 * {@inheritDoc}
178 */
179 public Content getConstructorDetails(Content constructorDetailsTree) {
180 return getMemberTree(constructorDetailsTree);
181 }
183 /**
184 * {@inheritDoc}
185 */
186 public Content getConstructorDoc(Content constructorDocTree,
187 boolean isLastContent) {
188 return getMemberTree(constructorDocTree, isLastContent);
189 }
191 /**
192 * Close the writer.
193 */
194 public void close() throws IOException {
195 writer.close();
196 }
198 /**
199 * Let the writer know whether a non public constructor was found.
200 *
201 * @param foundNonPubConstructor true if we found a non public constructor.
202 */
203 public void setFoundNonPubConstructor(boolean foundNonPubConstructor) {
204 this.foundNonPubConstructor = foundNonPubConstructor;
205 }
207 /**
208 * {@inheritDoc}
209 */
210 public void addSummaryLabel(Content memberTree) {
211 Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING,
212 writer.getResource("doclet.Constructor_Summary"));
213 memberTree.addContent(label);
214 }
216 /**
217 * {@inheritDoc}
218 */
219 public String getTableSummary() {
220 return configuration.getText("doclet.Member_Table_Summary",
221 configuration.getText("doclet.Constructor_Summary"),
222 configuration.getText("doclet.constructors"));
223 }
225 /**
226 * {@inheritDoc}
227 */
228 public String getCaption() {
229 return configuration.getText("doclet.Constructors");
230 }
232 /**
233 * {@inheritDoc}
234 */
235 public String[] getSummaryTableHeader(ProgramElementDoc member) {
236 String[] header;
237 if (foundNonPubConstructor) {
238 header = new String[] {
239 configuration.getText("doclet.Modifier"),
240 configuration.getText("doclet.0_and_1",
241 configuration.getText("doclet.Constructor"),
242 configuration.getText("doclet.Description"))
243 };
244 }
245 else {
246 header = new String[] {
247 configuration.getText("doclet.0_and_1",
248 configuration.getText("doclet.Constructor"),
249 configuration.getText("doclet.Description"))
250 };
251 }
252 return header;
253 }
255 /**
256 * {@inheritDoc}
257 */
258 public void addSummaryAnchor(ClassDoc cd, Content memberTree) {
259 memberTree.addContent(writer.getMarkerAnchor("constructor_summary"));
260 }
262 /**
263 * {@inheritDoc}
264 */
265 public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) {
266 }
268 /**
269 * {@inheritDoc}
270 */
271 public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) {
272 }
274 public int getMemberKind() {
275 return VisibleMemberMap.CONSTRUCTORS;
276 }
278 /**
279 * {@inheritDoc}
280 */
281 protected Content getNavSummaryLink(ClassDoc cd, boolean link) {
282 if (link) {
283 return writer.getHyperLink("constructor_summary",
284 writer.getResource("doclet.navConstructor"));
285 } else {
286 return writer.getResource("doclet.navConstructor");
287 }
288 }
290 /**
291 * {@inheritDoc}
292 */
293 protected void addNavDetailLink(boolean link, Content liNav) {
294 if (link) {
295 liNav.addContent(writer.getHyperLink("constructor_detail",
296 writer.getResource("doclet.navConstructor")));
297 } else {
298 liNav.addContent(writer.getResource("doclet.navConstructor"));
299 }
300 }
302 /**
303 * {@inheritDoc}
304 */
305 protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) {
306 if (foundNonPubConstructor) {
307 Content code = new HtmlTree(HtmlTag.CODE);
308 if (member.isProtected()) {
309 code.addContent("protected ");
310 } else if (member.isPrivate()) {
311 code.addContent("private ");
312 } else if (member.isPublic()) {
313 code.addContent(writer.getSpace());
314 } else {
315 code.addContent(
316 configuration.getText("doclet.Package_private"));
317 }
318 tdSummaryType.addContent(code);
319 }
320 }
321 }