Mon, 09 Mar 2009 23:53:41 -0700
Merge
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 */
41 public class ConstructorWriterImpl extends AbstractExecutableMemberWriter
42 implements ConstructorWriter, MemberSummaryWriter {
44 private boolean foundNonPubConstructor = false;
45 private boolean printedSummaryHeader = false;
47 /**
48 * Construct a new ConstructorWriterImpl.
49 *
50 * @param writer The writer for the class that the constructors belong to.
51 * @param classDoc the class being documented.
52 */
53 public ConstructorWriterImpl(SubWriterHolderWriter writer,
54 ClassDoc classDoc) {
55 super(writer, classDoc);
56 VisibleMemberMap visibleMemberMap = new VisibleMemberMap(classDoc,
57 VisibleMemberMap.CONSTRUCTORS, configuration().nodeprecated);
58 List<ProgramElementDoc> constructors = new ArrayList<ProgramElementDoc>(visibleMemberMap.getMembersFor(classDoc));
59 for (int i = 0; i < constructors.size(); i++) {
60 if ((constructors.get(i)).isProtected() ||
61 (constructors.get(i)).isPrivate()) {
62 setFoundNonPubConstructor(true);
63 }
64 }
65 }
67 /**
68 * Construct a new ConstructorWriterImpl.
69 *
70 * @param writer The writer for the class that the constructors belong to.
71 */
72 public ConstructorWriterImpl(SubWriterHolderWriter writer) {
73 super(writer);
74 }
76 /**
77 * Write the constructors summary header for the given class.
78 *
79 * @param classDoc the class the summary belongs to.
80 */
81 public void writeMemberSummaryHeader(ClassDoc classDoc) {
82 printedSummaryHeader = true;
83 writer.println();
84 writer.println("<!-- ======== CONSTRUCTOR SUMMARY ======== -->");
85 writer.println();
86 writer.printSummaryHeader(this, classDoc);
87 }
89 /**
90 * Write the constructors summary footer for the given class.
91 *
92 * @param classDoc the class the summary belongs to.
93 */
94 public void writeMemberSummaryFooter(ClassDoc classDoc) {
95 writer.printSummaryFooter(this, classDoc);
96 }
98 /**
99 * Write the header for the constructor documentation.
100 *
101 * @param classDoc the class that the constructors belong to.
102 */
103 public void writeHeader(ClassDoc classDoc, String header) {
104 writer.println();
105 writer.println("<!-- ========= CONSTRUCTOR DETAIL ======== -->");
106 writer.println();
107 writer.anchor("constructor_detail");
108 writer.printTableHeadingBackground(header);
109 }
111 /**
112 * Write the constructor header for the given constructor.
113 *
114 * @param constructor the constructor being documented.
115 * @param isFirst the flag to indicate whether or not the constructor is the
116 * first to be documented.
117 */
118 public void writeConstructorHeader(ConstructorDoc constructor, boolean isFirst) {
119 if (! isFirst) {
120 writer.printMemberHeader();
121 }
122 writer.println();
123 String erasureAnchor;
124 if ((erasureAnchor = getErasureAnchor(constructor)) != null) {
125 writer.anchor(erasureAnchor);
126 }
127 writer.anchor(constructor);
128 writer.h3();
129 writer.print(constructor.name());
130 writer.h3End();
131 }
133 /**
134 * Write the signature for the given constructor.
135 *
136 * @param constructor the constructor being documented.
137 */
138 public void writeSignature(ConstructorDoc constructor) {
139 writer.displayLength = 0;
140 writer.pre();
141 writer.writeAnnotationInfo(constructor);
142 printModifiers(constructor);
143 //printReturnType((ConstructorDoc)constructor);
144 if (configuration().linksource) {
145 writer.printSrcLink(constructor, constructor.name());
146 } else {
147 strong(constructor.name());
148 }
149 writeParameters(constructor);
150 writeExceptions(constructor);
151 writer.preEnd();
152 assert !writer.getMemberDetailsListPrinted();
153 }
155 /**
156 * Write the deprecated output for the given constructor.
157 *
158 * @param constructor the constructor being documented.
159 */
160 public void writeDeprecated(ConstructorDoc constructor) {
161 printDeprecated(constructor);
162 }
164 /**
165 * Write the comments for the given constructor.
166 *
167 * @param constructor the constructor being documented.
168 */
169 public void writeComments(ConstructorDoc constructor) {
170 printComment(constructor);
171 }
173 /**
174 * Write the tag output for the given constructor.
175 *
176 * @param constructor the constructor being documented.
177 */
178 public void writeTags(ConstructorDoc constructor) {
179 writer.printTags(constructor);
180 }
182 /**
183 * Write the constructor footer.
184 */
185 public void writeConstructorFooter() {
186 printMemberFooter();
187 }
189 /**
190 * Write the footer for the constructor documentation.
191 *
192 * @param classDoc the class that the constructors belong to.
193 */
194 public void writeFooter(ClassDoc classDoc) {
195 //No footer to write for constructor documentation
196 }
198 /**
199 * Close the writer.
200 */
201 public void close() throws IOException {
202 writer.close();
203 }
205 /**
206 * Let the writer know whether a non public constructor was found.
207 *
208 * @param foundNonPubConstructor true if we found a non public constructor.
209 */
210 public void setFoundNonPubConstructor(boolean foundNonPubConstructor) {
211 this.foundNonPubConstructor = foundNonPubConstructor;
212 }
214 public void printSummaryLabel(ClassDoc cd) {
215 writer.strongText("doclet.Constructor_Summary");
216 }
218 public void printSummaryAnchor(ClassDoc cd) {
219 writer.anchor("constructor_summary");
220 }
222 public void printInheritedSummaryAnchor(ClassDoc cd) {
223 } // no such
225 public void printInheritedSummaryLabel(ClassDoc cd) {
226 // no such
227 }
229 public int getMemberKind() {
230 return VisibleMemberMap.CONSTRUCTORS;
231 }
233 protected void navSummaryLink(List<?> members) {
234 printNavSummaryLink(classdoc,
235 members.size() > 0? true: false);
236 }
238 protected void printNavSummaryLink(ClassDoc cd, boolean link) {
239 if (link) {
240 writer.printHyperLink("", "constructor_summary",
241 ConfigurationImpl.getInstance().getText("doclet.navConstructor"));
242 } else {
243 writer.printText("doclet.navConstructor");
244 }
245 }
247 protected void printNavDetailLink(boolean link) {
248 if (link) {
249 writer.printHyperLink("", "constructor_detail",
250 ConfigurationImpl.getInstance().getText("doclet.navConstructor"));
251 } else {
252 writer.printText("doclet.navConstructor");
253 }
254 }
256 protected void printSummaryType(ProgramElementDoc member) {
257 if (foundNonPubConstructor) {
258 writer.printTypeSummaryHeader();
259 if (member.isProtected()) {
260 print("protected ");
261 } else if (member.isPrivate()) {
262 print("private ");
263 } else if (member.isPublic()) {
264 writer.space();
265 } else {
266 writer.printText("doclet.Package_private");
267 }
268 writer.printTypeSummaryFooter();
269 }
270 }
272 /**
273 * Write the inherited member summary header for the given class.
274 *
275 * @param classDoc the class the summary belongs to.
276 */
277 public void writeInheritedMemberSummaryHeader(ClassDoc classDoc) {
278 if(! printedSummaryHeader){
279 //We don't want inherited summary to not be under heading.
280 writeMemberSummaryHeader(classDoc);
281 writeMemberSummaryFooter(classDoc);
282 printedSummaryHeader = true;
283 }
284 }
286 /**
287 * {@inheritDoc}
288 */
289 public void writeInheritedMemberSummary(ClassDoc classDoc,
290 ProgramElementDoc member, boolean isFirst, boolean isLast) {}
292 /**
293 * Write the inherited member summary footer for the given class.
294 *
295 * @param classDoc the class the summary belongs to.
296 */
297 public void writeInheritedMemberSummaryFooter(ClassDoc classDoc) {}
298 }