Sun, 11 Apr 2010 23:24:24 -0700
6875904: Java 7 message synchronization 1
Reviewed-by: ogino, faryad
1 /*
2 * Copyright 1997-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.formats.html;
28 import java.io.*;
29 import java.util.*;
31 import com.sun.javadoc.*;
32 import com.sun.tools.doclets.internal.toolkit.*;
33 import com.sun.tools.doclets.internal.toolkit.util.*;
35 /**
36 * Writes constructor documentation.
37 *
38 * @author Robert Field
39 * @author Atul M Dambalkar
40 * @author Bhavesh Patel (Modified)
41 */
42 public class ConstructorWriterImpl extends AbstractExecutableMemberWriter
43 implements ConstructorWriter, MemberSummaryWriter {
45 private boolean foundNonPubConstructor = false;
46 private boolean printedSummaryHeader = false;
48 /**
49 * Construct a new ConstructorWriterImpl.
50 *
51 * @param writer The writer for the class that the constructors belong to.
52 * @param classDoc the class being documented.
53 */
54 public ConstructorWriterImpl(SubWriterHolderWriter writer,
55 ClassDoc classDoc) {
56 super(writer, classDoc);
57 VisibleMemberMap visibleMemberMap = new VisibleMemberMap(classDoc,
58 VisibleMemberMap.CONSTRUCTORS, configuration().nodeprecated);
59 List<ProgramElementDoc> constructors = new ArrayList<ProgramElementDoc>(visibleMemberMap.getMembersFor(classDoc));
60 for (int i = 0; i < constructors.size(); i++) {
61 if ((constructors.get(i)).isProtected() ||
62 (constructors.get(i)).isPrivate()) {
63 setFoundNonPubConstructor(true);
64 }
65 }
66 }
68 /**
69 * Construct a new ConstructorWriterImpl.
70 *
71 * @param writer The writer for the class that the constructors belong to.
72 */
73 public ConstructorWriterImpl(SubWriterHolderWriter writer) {
74 super(writer);
75 }
77 /**
78 * Write the constructors summary header for the given class.
79 *
80 * @param classDoc the class the summary belongs to.
81 */
82 public void writeMemberSummaryHeader(ClassDoc classDoc) {
83 printedSummaryHeader = true;
84 writer.println();
85 writer.println("<!-- ======== CONSTRUCTOR SUMMARY ======== -->");
86 writer.println();
87 writer.printSummaryHeader(this, classDoc);
88 }
90 /**
91 * Write the constructors summary footer for the given class.
92 *
93 * @param classDoc the class the summary belongs to.
94 */
95 public void writeMemberSummaryFooter(ClassDoc classDoc) {
96 writer.printSummaryFooter(this, classDoc);
97 }
99 /**
100 * Write the header for the constructor documentation.
101 *
102 * @param classDoc the class that the constructors belong to.
103 */
104 public void writeHeader(ClassDoc classDoc, String header) {
105 writer.println();
106 writer.println("<!-- ========= CONSTRUCTOR DETAIL ======== -->");
107 writer.println();
108 writer.anchor("constructor_detail");
109 writer.printTableHeadingBackground(header);
110 }
112 /**
113 * Write the constructor header for the given constructor.
114 *
115 * @param constructor the constructor being documented.
116 * @param isFirst the flag to indicate whether or not the constructor is the
117 * first to be documented.
118 */
119 public void writeConstructorHeader(ConstructorDoc constructor, boolean isFirst) {
120 if (! isFirst) {
121 writer.printMemberHeader();
122 }
123 writer.println();
124 String erasureAnchor;
125 if ((erasureAnchor = getErasureAnchor(constructor)) != null) {
126 writer.anchor(erasureAnchor);
127 }
128 writer.anchor(constructor);
129 writer.h3();
130 writer.print(constructor.name());
131 writer.h3End();
132 }
134 /**
135 * Write the signature for the given constructor.
136 *
137 * @param constructor the constructor being documented.
138 */
139 public void writeSignature(ConstructorDoc constructor) {
140 writer.displayLength = 0;
141 writer.pre();
142 writer.writeAnnotationInfo(constructor);
143 printModifiers(constructor);
144 //printReturnType((ConstructorDoc)constructor);
145 if (configuration().linksource) {
146 writer.printSrcLink(constructor, constructor.name());
147 } else {
148 strong(constructor.name());
149 }
150 writeParameters(constructor);
151 writeExceptions(constructor);
152 writer.preEnd();
153 assert !writer.getMemberDetailsListPrinted();
154 }
156 /**
157 * Write the deprecated output for the given constructor.
158 *
159 * @param constructor the constructor being documented.
160 */
161 public void writeDeprecated(ConstructorDoc constructor) {
162 printDeprecated(constructor);
163 }
165 /**
166 * Write the comments for the given constructor.
167 *
168 * @param constructor the constructor being documented.
169 */
170 public void writeComments(ConstructorDoc constructor) {
171 printComment(constructor);
172 }
174 /**
175 * Write the tag output for the given constructor.
176 *
177 * @param constructor the constructor being documented.
178 */
179 public void writeTags(ConstructorDoc constructor) {
180 writer.printTags(constructor);
181 }
183 /**
184 * Write the constructor footer.
185 */
186 public void writeConstructorFooter() {
187 printMemberFooter();
188 }
190 /**
191 * Write the footer for the constructor documentation.
192 *
193 * @param classDoc the class that the constructors belong to.
194 */
195 public void writeFooter(ClassDoc classDoc) {
196 //No footer to write for constructor documentation
197 }
199 /**
200 * Close the writer.
201 */
202 public void close() throws IOException {
203 writer.close();
204 }
206 /**
207 * Let the writer know whether a non public constructor was found.
208 *
209 * @param foundNonPubConstructor true if we found a non public constructor.
210 */
211 public void setFoundNonPubConstructor(boolean foundNonPubConstructor) {
212 this.foundNonPubConstructor = foundNonPubConstructor;
213 }
215 public void printSummaryLabel() {
216 writer.printText("doclet.Constructor_Summary");
217 }
219 public void printTableSummary() {
220 writer.tableIndexSummary(configuration().getText("doclet.Member_Table_Summary",
221 configuration().getText("doclet.Constructor_Summary"),
222 configuration().getText("doclet.constructors")));
223 }
225 public void printSummaryTableHeader(ProgramElementDoc member) {
226 String[] header;
227 if (foundNonPubConstructor) {
228 header = new String[] {
229 configuration().getText("doclet.Modifier"),
230 configuration().getText("doclet.0_and_1",
231 configuration().getText("doclet.Constructor"),
232 configuration().getText("doclet.Description"))
233 };
234 }
235 else {
236 header = new String[] {
237 configuration().getText("doclet.0_and_1",
238 configuration().getText("doclet.Constructor"),
239 configuration().getText("doclet.Description"))
240 };
241 }
242 writer.summaryTableHeader(header, "col");
243 }
245 public void printSummaryAnchor(ClassDoc cd) {
246 writer.anchor("constructor_summary");
247 }
249 public void printInheritedSummaryAnchor(ClassDoc cd) {
250 } // no such
252 public void printInheritedSummaryLabel(ClassDoc cd) {
253 // no such
254 }
256 public int getMemberKind() {
257 return VisibleMemberMap.CONSTRUCTORS;
258 }
260 protected void navSummaryLink(List<?> members) {
261 printNavSummaryLink(classdoc,
262 members.size() > 0? true: false);
263 }
265 protected void printNavSummaryLink(ClassDoc cd, boolean link) {
266 if (link) {
267 writer.printHyperLink("", "constructor_summary",
268 ConfigurationImpl.getInstance().getText("doclet.navConstructor"));
269 } else {
270 writer.printText("doclet.navConstructor");
271 }
272 }
274 protected void printNavDetailLink(boolean link) {
275 if (link) {
276 writer.printHyperLink("", "constructor_detail",
277 ConfigurationImpl.getInstance().getText("doclet.navConstructor"));
278 } else {
279 writer.printText("doclet.navConstructor");
280 }
281 }
283 protected void printSummaryType(ProgramElementDoc member) {
284 if (foundNonPubConstructor) {
285 writer.printTypeSummaryHeader();
286 if (member.isProtected()) {
287 print("protected ");
288 } else if (member.isPrivate()) {
289 print("private ");
290 } else if (member.isPublic()) {
291 writer.space();
292 } else {
293 writer.printText("doclet.Package_private");
294 }
295 writer.printTypeSummaryFooter();
296 }
297 }
299 /**
300 * Write the inherited member summary header for the given class.
301 *
302 * @param classDoc the class the summary belongs to.
303 */
304 public void writeInheritedMemberSummaryHeader(ClassDoc classDoc) {
305 if(! printedSummaryHeader){
306 //We don't want inherited summary to not be under heading.
307 writeMemberSummaryHeader(classDoc);
308 writeMemberSummaryFooter(classDoc);
309 printedSummaryHeader = true;
310 }
311 }
313 /**
314 * {@inheritDoc}
315 */
316 public void writeInheritedMemberSummary(ClassDoc classDoc,
317 ProgramElementDoc member, boolean isFirst, boolean isLast) {}
319 /**
320 * Write the inherited member summary footer for the given class.
321 *
322 * @param classDoc the class the summary belongs to.
323 */
324 public void writeInheritedMemberSummaryFooter(ClassDoc classDoc) {}
325 }