001: /*
002: * Copyright 1997-2004 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.taglets.*;
030: import com.sun.tools.doclets.internal.toolkit.util.*;
031: import com.sun.javadoc.*;
032:
033: import java.io.*;
034:
035: /**
036: * Writes field documentation in HTML format.
037: *
038: * @author Robert Field
039: * @author Atul M Dambalkar
040: * @author Jamie Ho (rewrite)
041: */
042: public class FieldWriterImpl extends AbstractMemberWriter implements
043: FieldWriter, MemberSummaryWriter {
044:
045: private boolean printedSummaryHeader = false;
046:
047: public FieldWriterImpl(SubWriterHolderWriter writer,
048: ClassDoc classdoc) {
049: super (writer, classdoc);
050: }
051:
052: public FieldWriterImpl(SubWriterHolderWriter writer) {
053: super (writer);
054: }
055:
056: /**
057: * Write the fields summary header for the given class.
058: *
059: * @param classDoc the class the summary belongs to.
060: */
061: public void writeMemberSummaryHeader(ClassDoc classDoc) {
062: printedSummaryHeader = true;
063: writer
064: .println("<!-- =========== FIELD SUMMARY =========== -->");
065: writer.println();
066: writer.printSummaryHeader(this , classDoc);
067: }
068:
069: /**
070: * Write the fields summary footer for the given class.
071: *
072: * @param classDoc the class the summary belongs to.
073: */
074: public void writeMemberSummaryFooter(ClassDoc classDoc) {
075: writer.tableEnd();
076: writer.space();
077: }
078:
079: /**
080: * Write the inherited fields summary header for the given class.
081: *
082: * @param classDoc the class the summary belongs to.
083: */
084: public void writeInheritedMemberSummaryHeader(ClassDoc classDoc) {
085: if (!printedSummaryHeader) {
086: //We don't want inherited summary to not be under heading.
087: writeMemberSummaryHeader(classDoc);
088: writeMemberSummaryFooter(classDoc);
089: printedSummaryHeader = true;
090: }
091: writer.printInheritedSummaryHeader(this , classDoc);
092: }
093:
094: /**
095: * {@inheritDoc}
096: */
097: public void writeInheritedMemberSummary(ClassDoc classDoc,
098: ProgramElementDoc field, boolean isFirst, boolean isLast) {
099: writer.printInheritedSummaryMember(this , classDoc, field,
100: isFirst);
101: }
102:
103: /**
104: * Write the inherited fields summary footer for the given class.
105: *
106: * @param classDoc the class the summary belongs to.
107: */
108: public void writeInheritedMemberSummaryFooter(ClassDoc classDoc) {
109: writer.printInheritedSummaryFooter(this , classDoc);
110: }
111:
112: /**
113: * Write the header for the field documentation.
114: *
115: * @param classDoc the class that the fields belong to.
116: */
117: public void writeHeader(ClassDoc classDoc, String header) {
118: writer.println();
119: writer
120: .println("<!-- ============ FIELD DETAIL =========== -->");
121: writer.println();
122: writer.anchor("field_detail");
123: writer.printTableHeadingBackground(header);
124: writer.println();
125: }
126:
127: /**
128: * Write the field header for the given field.
129: *
130: * @param field the field being documented.
131: * @param isFirst the flag to indicate whether or not the field is the
132: * first to be documented.
133: */
134: public void writeFieldHeader(FieldDoc field, boolean isFirst) {
135: if (!isFirst) {
136: writer.printMemberHeader();
137: writer.println("");
138: }
139: writer.anchor(field.name());
140: writer.h3();
141: writer.print(field.name());
142: writer.h3End();
143: }
144:
145: /**
146: * Write the signature for the given field.
147: *
148: * @param field the field being documented.
149: */
150: public void writeSignature(FieldDoc field) {
151: writer.pre();
152: writer.writeAnnotationInfo(field);
153: printModifiers(field);
154: writer.printLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_MEMBER,
155: field.type()));
156: print(' ');
157: if (configuration().linksource) {
158: writer.printSrcLink(field, field.name());
159: } else {
160: bold(field.name());
161: }
162: writer.preEnd();
163: writer.dl();
164: }
165:
166: /**
167: * Write the deprecated output for the given field.
168: *
169: * @param field the field being documented.
170: */
171: public void writeDeprecated(FieldDoc field) {
172: print(((TagletOutputImpl) (new DeprecatedTaglet())
173: .getTagletOutput(field, writer
174: .getTagletWriterInstance(false))).toString());
175: }
176:
177: /**
178: * Write the comments for the given field.
179: *
180: * @param field the field being documented.
181: */
182: public void writeComments(FieldDoc field) {
183: ClassDoc holder = field.containingClass();
184: if (field.inlineTags().length > 0) {
185: if (holder.equals(classdoc)
186: || (!(holder.isPublic() || Util.isLinkable(holder,
187: configuration())))) {
188: writer.dd();
189: writer.printInlineComment(field);
190: } else {
191: String classlink = writer.codeText(writer.getDocLink(
192: LinkInfoImpl.CONTEXT_FIELD_DOC_COPY, holder,
193: field, holder.isIncluded() ? holder.typeName()
194: : holder.qualifiedTypeName(), false));
195: writer.dd();
196: writer
197: .bold(configuration()
198: .getText(
199: holder.isClass() ? "doclet.Description_From_Class"
200: : "doclet.Description_From_Interface",
201: classlink));
202: writer.ddEnd();
203: writer.dd();
204: writer.printInlineComment(field);
205: }
206: }
207: }
208:
209: /**
210: * Write the tag output for the given field.
211: *
212: * @param field the field being documented.
213: */
214: public void writeTags(FieldDoc field) {
215: writer.printTags(field);
216: }
217:
218: /**
219: * Write the field footer.
220: */
221: public void writeFieldFooter() {
222: writer.dlEnd();
223: }
224:
225: /**
226: * Write the footer for the field documentation.
227: *
228: * @param classDoc the class that the fields belong to.
229: */
230: public void writeFooter(ClassDoc classDoc) {
231: //No footer to write for field documentation
232: }
233:
234: /**
235: * Close the writer.
236: */
237: public void close() throws IOException {
238: writer.close();
239: }
240:
241: public int getMemberKind() {
242: return VisibleMemberMap.FIELDS;
243: }
244:
245: public void printSummaryLabel(ClassDoc cd) {
246: writer.boldText("doclet.Field_Summary");
247: }
248:
249: public void printSummaryAnchor(ClassDoc cd) {
250: writer.anchor("field_summary");
251: }
252:
253: public void printInheritedSummaryAnchor(ClassDoc cd) {
254: writer.anchor("fields_inherited_from_class_"
255: + configuration().getClassName(cd));
256: }
257:
258: public void printInheritedSummaryLabel(ClassDoc cd) {
259: String classlink = writer.getPreQualifiedClassLink(
260: LinkInfoImpl.CONTEXT_MEMBER, cd, false);
261: writer.bold();
262: String key = cd.isClass() ? "doclet.Fields_Inherited_From_Class"
263: : "doclet.Fields_Inherited_From_Interface";
264: writer.printText(key, classlink);
265: writer.boldEnd();
266: }
267:
268: protected void writeSummaryLink(int context, ClassDoc cd,
269: ProgramElementDoc member) {
270: writer.bold();
271: writer.printDocLink(context, cd, (MemberDoc) member, member
272: .name(), false);
273: writer.boldEnd();
274: }
275:
276: protected void writeInheritedSummaryLink(ClassDoc cd,
277: ProgramElementDoc member) {
278: writer.printDocLink(LinkInfoImpl.CONTEXT_MEMBER, cd,
279: (MemberDoc) member, member.name(), false);
280: }
281:
282: protected void printSummaryType(ProgramElementDoc member) {
283: FieldDoc field = (FieldDoc) member;
284: printModifierAndType(field, field.type());
285: }
286:
287: protected void writeDeprecatedLink(ProgramElementDoc member) {
288: writer.printDocLink(LinkInfoImpl.CONTEXT_MEMBER,
289: (MemberDoc) member,
290: ((FieldDoc) member).qualifiedName(), false);
291: }
292:
293: protected void printNavSummaryLink(ClassDoc cd, boolean link) {
294: if (link) {
295: writer.printHyperLink("", (cd == null) ? "field_summary"
296: : "fields_inherited_from_class_"
297: + configuration().getClassName(cd),
298: configuration().getText("doclet.navField"));
299: } else {
300: writer.printText("doclet.navField");
301: }
302: }
303:
304: protected void printNavDetailLink(boolean link) {
305: if (link) {
306: writer.printHyperLink("", "field_detail", configuration()
307: .getText("doclet.navField"));
308: } else {
309: writer.printText("doclet.navField");
310: }
311: }
312: }
|