001: /*
002: * Copyright 1997-2003 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.doclets.formats.html;
027:
028: import com.sun.tools.doclets.internal.toolkit.*;
029: import com.sun.tools.doclets.internal.toolkit.util.*;
030: import com.sun.tools.doclets.internal.toolkit.taglets.*;
031: import com.sun.javadoc.*;
032: import java.util.*;
033: import java.io.*;
034:
035: /**
036: * Writes constructor documentation.
037: *
038: * @author Robert Field
039: * @author Atul M Dambalkar
040: */
041: public class ConstructorWriterImpl extends
042: AbstractExecutableMemberWriter implements ConstructorWriter,
043: MemberSummaryWriter {
044:
045: private boolean foundNonPubConstructor = false;
046: private boolean printedSummaryHeader = false;
047:
048: /**
049: * Construct a new ConstructorWriterImpl.
050: *
051: * @param writer The writer for the class that the constructors belong to.
052: * @param classDoc the class being documented.
053: */
054: public ConstructorWriterImpl(SubWriterHolderWriter writer,
055: ClassDoc classDoc) {
056: super (writer, classDoc);
057: VisibleMemberMap visibleMemberMap = new VisibleMemberMap(
058: classDoc, VisibleMemberMap.CONSTRUCTORS,
059: configuration().nodeprecated);
060: List constructors = new ArrayList(visibleMemberMap
061: .getMembersFor(classDoc));
062: for (int i = 0; i < constructors.size(); i++) {
063: if (((ProgramElementDoc) (constructors.get(i)))
064: .isProtected()
065: || ((ProgramElementDoc) (constructors.get(i)))
066: .isPrivate()) {
067: setFoundNonPubConstructor(true);
068: }
069: }
070: }
071:
072: /**
073: * Construct a new ConstructorWriterImpl.
074: *
075: * @param writer The writer for the class that the constructors belong to.
076: */
077: public ConstructorWriterImpl(SubWriterHolderWriter writer) {
078: super (writer);
079: }
080:
081: /**
082: * Write the constructors summary header for the given class.
083: *
084: * @param classDoc the class the summary belongs to.
085: */
086: public void writeMemberSummaryHeader(ClassDoc classDoc) {
087: printedSummaryHeader = true;
088: writer.println();
089: writer
090: .println("<!-- ======== CONSTRUCTOR SUMMARY ======== -->");
091: writer.println();
092: writer.printSummaryHeader(this , classDoc);
093: }
094:
095: /**
096: * Write the constructors summary footer for the given class.
097: *
098: * @param classDoc the class the summary belongs to.
099: */
100: public void writeMemberSummaryFooter(ClassDoc classDoc) {
101: writer.printSummaryFooter(this , classDoc);
102: }
103:
104: /**
105: * Write the header for the constructor documentation.
106: *
107: * @param classDoc the class that the constructors belong to.
108: */
109: public void writeHeader(ClassDoc classDoc, String header) {
110: writer.println();
111: writer
112: .println("<!-- ========= CONSTRUCTOR DETAIL ======== -->");
113: writer.println();
114: writer.anchor("constructor_detail");
115: writer.printTableHeadingBackground(header);
116: }
117:
118: /**
119: * Write the constructor header for the given constructor.
120: *
121: * @param constructor the constructor being documented.
122: * @param isFirst the flag to indicate whether or not the constructor is the
123: * first to be documented.
124: */
125: public void writeConstructorHeader(ConstructorDoc constructor,
126: boolean isFirst) {
127: if (!isFirst) {
128: writer.printMemberHeader();
129: }
130: writer.println();
131: String erasureAnchor;
132: if ((erasureAnchor = getErasureAnchor(constructor)) != null) {
133: writer.anchor(erasureAnchor);
134: }
135: writer.anchor(constructor);
136: writer.h3();
137: writer.print(constructor.name());
138: writer.h3End();
139: }
140:
141: /**
142: * Write the signature for the given constructor.
143: *
144: * @param constructor the constructor being documented.
145: */
146: public void writeSignature(ConstructorDoc constructor) {
147: writer.displayLength = 0;
148: writer.pre();
149: writer.writeAnnotationInfo(constructor);
150: printModifiers(constructor);
151: //printReturnType((ConstructorDoc)constructor);
152: if (configuration().linksource) {
153: writer.printSrcLink(constructor, constructor.name());
154: } else {
155: bold(constructor.name());
156: }
157: writeParameters(constructor);
158: writeExceptions(constructor);
159: writer.preEnd();
160: writer.dl();
161: }
162:
163: /**
164: * Write the deprecated output for the given constructor.
165: *
166: * @param constructor the constructor being documented.
167: */
168: public void writeDeprecated(ConstructorDoc constructor) {
169: String output = ((TagletOutputImpl) (new DeprecatedTaglet())
170: .getTagletOutput(constructor, writer
171: .getTagletWriterInstance(false))).toString();
172: if (output != null && output.trim().length() > 0) {
173: writer.print(output);
174: }
175: }
176:
177: /**
178: * Write the comments for the given constructor.
179: *
180: * @param constructor the constructor being documented.
181: */
182: public void writeComments(ConstructorDoc constructor) {
183: if (constructor.inlineTags().length > 0) {
184: writer.dd();
185: writer.printInlineComment(constructor);
186: }
187: }
188:
189: /**
190: * Write the tag output for the given constructor.
191: *
192: * @param constructor the constructor being documented.
193: */
194: public void writeTags(ConstructorDoc constructor) {
195: writer.printTags(constructor);
196: }
197:
198: /**
199: * Write the constructor footer.
200: */
201: public void writeConstructorFooter() {
202: writer.dlEnd();
203: }
204:
205: /**
206: * Write the footer for the constructor documentation.
207: *
208: * @param classDoc the class that the constructors belong to.
209: */
210: public void writeFooter(ClassDoc classDoc) {
211: //No footer to write for constructor documentation
212: }
213:
214: /**
215: * Close the writer.
216: */
217: public void close() throws IOException {
218: writer.close();
219: }
220:
221: /**
222: * Let the writer know whether a non public constructor was found.
223: *
224: * @param foundNonPubConstructor true if we found a non public constructor.
225: */
226: public void setFoundNonPubConstructor(boolean foundNonPubConstructor) {
227: this .foundNonPubConstructor = foundNonPubConstructor;
228: }
229:
230: public void printSummaryLabel(ClassDoc cd) {
231: writer.boldText("doclet.Constructor_Summary");
232: }
233:
234: public void printSummaryAnchor(ClassDoc cd) {
235: writer.anchor("constructor_summary");
236: }
237:
238: public void printInheritedSummaryAnchor(ClassDoc cd) {
239: } // no such
240:
241: public void printInheritedSummaryLabel(ClassDoc cd) {
242: // no such
243: }
244:
245: public int getMemberKind() {
246: return VisibleMemberMap.CONSTRUCTORS;
247: }
248:
249: protected void navSummaryLink(List members) {
250: printNavSummaryLink(classdoc, members.size() > 0 ? true : false);
251: }
252:
253: protected void printNavSummaryLink(ClassDoc cd, boolean link) {
254: if (link) {
255: writer.printHyperLink("", "constructor_summary",
256: ConfigurationImpl.getInstance().getText(
257: "doclet.navConstructor"));
258: } else {
259: writer.printText("doclet.navConstructor");
260: }
261: }
262:
263: protected void printNavDetailLink(boolean link) {
264: if (link) {
265: writer.printHyperLink("", "constructor_detail",
266: ConfigurationImpl.getInstance().getText(
267: "doclet.navConstructor"));
268: } else {
269: writer.printText("doclet.navConstructor");
270: }
271: }
272:
273: protected void printSummaryType(ProgramElementDoc member) {
274: if (foundNonPubConstructor) {
275: writer.printTypeSummaryHeader();
276: if (member.isProtected()) {
277: print("protected ");
278: } else if (member.isPrivate()) {
279: print("private ");
280: } else if (member.isPublic()) {
281: writer.space();
282: } else {
283: writer.printText("doclet.Package_private");
284: }
285: writer.printTypeSummaryFooter();
286: }
287: }
288:
289: /**
290: * Write the inherited member summary header for the given class.
291: *
292: * @param classDoc the class the summary belongs to.
293: */
294: public void writeInheritedMemberSummaryHeader(ClassDoc classDoc) {
295: if (!printedSummaryHeader) {
296: //We don't want inherited summary to not be under heading.
297: writeMemberSummaryHeader(classDoc);
298: writeMemberSummaryFooter(classDoc);
299: printedSummaryHeader = true;
300: }
301: }
302:
303: /**
304: * {@inheritDoc}
305: */
306: public void writeInheritedMemberSummary(ClassDoc classDoc,
307: ProgramElementDoc member, boolean isFirst, boolean isLast) {
308: }
309:
310: /**
311: * Write the inherited member summary footer for the given class.
312: *
313: * @param classDoc the class the summary belongs to.
314: */
315: public void writeInheritedMemberSummaryFooter(ClassDoc classDoc) {
316: }
317: }
|