001: /*
002: * Copyright 2003-2005 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.builders.*;
031: import com.sun.javadoc.*;
032:
033: /**
034: * Generate the Class Information Page.
035: * @see com.sun.javadoc.ClassDoc
036: * @see java.util.Collections
037: * @see java.util.List
038: * @see java.util.ArrayList
039: * @see java.util.HashMap
040: *
041: * @author Atul M Dambalkar
042: * @author Robert Field
043: */
044: public class AnnotationTypeWriterImpl extends SubWriterHolderWriter
045: implements AnnotationTypeWriter {
046:
047: protected AnnotationTypeDoc annotationType;
048:
049: protected Type prev;
050:
051: protected Type next;
052:
053: /**
054: * @param annotationType the annotation type being documented.
055: * @param prevType the previous class that was documented.
056: * @param nextType the next class being documented.
057: */
058: public AnnotationTypeWriterImpl(AnnotationTypeDoc annotationType,
059: Type prevType, Type nextType) throws Exception {
060: super (ConfigurationImpl.getInstance(), DirectoryManager
061: .getDirectoryPath(annotationType.containingPackage()),
062: annotationType.name() + ".html", DirectoryManager
063: .getRelativePath(annotationType
064: .containingPackage().name()));
065: this .annotationType = annotationType;
066: configuration.currentcd = annotationType.asClassDoc();
067: this .prev = prevType;
068: this .next = nextType;
069: }
070:
071: /**
072: * Print this package link
073: */
074: protected void navLinkPackage() {
075: navCellStart();
076: printHyperLink("package-summary.html", "", configuration
077: .getText("doclet.Package"), true, "NavBarFont1");
078: navCellEnd();
079: }
080:
081: /**
082: * Print class page indicator
083: */
084: protected void navLinkClass() {
085: navCellRevStart();
086: fontStyle("NavBarFont1Rev");
087: boldText("doclet.Class");
088: fontEnd();
089: navCellEnd();
090: }
091:
092: /**
093: * Print class use link
094: */
095: protected void navLinkClassUse() {
096: navCellStart();
097: printHyperLink("class-use/" + filename, "", configuration
098: .getText("doclet.navClassUse"), true, "NavBarFont1");
099: navCellEnd();
100: }
101:
102: /**
103: * Print previous package link
104: */
105: protected void navLinkPrevious() {
106: if (prev == null) {
107: printText("doclet.Prev_Class");
108: } else {
109: printLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_CLASS, prev
110: .asClassDoc(), "", configuration
111: .getText("doclet.Prev_Class"), true));
112: }
113: }
114:
115: /**
116: * Print next package link
117: */
118: protected void navLinkNext() {
119: if (next == null) {
120: printText("doclet.Next_Class");
121: } else {
122: printLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_CLASS, next
123: .asClassDoc(), "", configuration
124: .getText("doclet.Next_Class"), true));
125: }
126: }
127:
128: /**
129: * {@inheritDoc}
130: */
131: public void writeHeader(String header) {
132:
133: String pkgname = (annotationType.containingPackage() != null) ? annotationType
134: .containingPackage().name()
135: : "";
136: String clname = annotationType.name();
137:
138: printHtmlHeader(clname, configuration.metakeywords
139: .getMetaKeywords(annotationType), true);
140: printTop();
141: navLinks(true);
142: hr();
143: println("<!-- ======== START OF CLASS DATA ======== -->");
144: h2();
145: if (pkgname.length() > 0) {
146: font("-1");
147: print(pkgname);
148: fontEnd();
149: br();
150: }
151: print(header
152: + getTypeParameterLinks(new LinkInfoImpl(
153: LinkInfoImpl.CONTEXT_CLASS_HEADER,
154: annotationType, false)));
155: h2End();
156: }
157:
158: /**
159: * {@inheritDoc}
160: */
161: public void writeFooter() {
162: println("<!-- ========= END OF CLASS DATA ========= -->");
163: hr();
164: navLinks(false);
165: printBottom();
166: printBodyHtmlEnd();
167: }
168:
169: /**
170: * {@inheritDoc}
171: */
172: public void writeAnnotationTypeSignature(String modifiers) {
173: dl();
174: dt();
175: preNoNewLine();
176: writeAnnotationInfo(annotationType);
177: print(modifiers);
178: String name = annotationType.name()
179: + getTypeParameterLinks(new LinkInfoImpl(
180: LinkInfoImpl.CONTEXT_CLASS_SIGNATURE,
181: annotationType, false));
182: if (configuration().linksource) {
183: printSrcLink(annotationType, name);
184: } else {
185: bold(name);
186: }
187: dlEnd();
188: preEnd();
189: p();
190: }
191:
192: /**
193: * {@inheritDoc}
194: */
195: public void writeAnnotationTypeDescription() {
196: if (!configuration.nocomment) {
197: // generate documentation for the class.
198: if (annotationType.inlineTags().length > 0) {
199: printInlineComment(annotationType);
200: p();
201: }
202: }
203: }
204:
205: /**
206: * {@inheritDoc}
207: */
208: public void writeAnnotationTypeTagInfo() {
209: boolean needHr = annotationType.elements().length > 0;
210: if (!configuration.nocomment) {
211: // Print Information about all the tags here
212: printTags(annotationType);
213: if (needHr) {
214: hr();
215: }
216: p();
217: } else if (needHr) {
218: hr();
219: }
220: }
221:
222: /**
223: * {@inheritDoc}
224: */
225: public void writeAnnotationTypeDeprecationInfo() {
226: hr();
227: Tag[] deprs = annotationType.tags("deprecated");
228: if (Util.isDeprecated(annotationType)) {
229: boldText("doclet.Deprecated");
230: if (deprs.length > 0) {
231: Tag[] commentTags = deprs[0].inlineTags();
232: if (commentTags.length > 0) {
233:
234: space();
235: printInlineDeprecatedComment(annotationType,
236: deprs[0]);
237: }
238: }
239: p();
240: }
241: }
242:
243: protected void navLinkTree() {
244: navCellStart();
245: printHyperLink("package-tree.html", "", configuration
246: .getText("doclet.Tree"), true, "NavBarFont1");
247: navCellEnd();
248: }
249:
250: protected void printSummaryDetailLinks() {
251: try {
252: tr();
253: tdVAlignClass("top", "NavBarCell3");
254: font("-2");
255: print(" ");
256: navSummaryLinks();
257: fontEnd();
258: tdEnd();
259:
260: tdVAlignClass("top", "NavBarCell3");
261: font("-2");
262: navDetailLinks();
263: fontEnd();
264: tdEnd();
265: trEnd();
266: } catch (Exception e) {
267: e.printStackTrace();
268: throw new DocletAbortException();
269: }
270: }
271:
272: protected void navSummaryLinks() throws Exception {
273: printText("doclet.Summary");
274: space();
275: MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder) configuration
276: .getBuilderFactory().getMemberSummaryBuilder(this );
277: writeNavSummaryLink(memberSummaryBuilder,
278: "doclet.navAnnotationTypeRequiredMember",
279: VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED);
280: navGap();
281: writeNavSummaryLink(memberSummaryBuilder,
282: "doclet.navAnnotationTypeOptionalMember",
283: VisibleMemberMap.ANNOTATION_TYPE_MEMBER_OPTIONAL);
284: }
285:
286: private void writeNavSummaryLink(MemberSummaryBuilder builder,
287: String label, int type) {
288: AbstractMemberWriter writer = ((AbstractMemberWriter) builder
289: .getMemberSummaryWriter(type));
290: if (writer == null) {
291: printText(label);
292: } else {
293: writer.printNavSummaryLink(null, !builder
294: .getVisibleMemberMap(type).noVisibleMembers());
295: }
296: }
297:
298: /**
299: * Method navDetailLinks
300: *
301: * @throws Exception
302: *
303: */
304: protected void navDetailLinks() throws Exception {
305: printText("doclet.Detail");
306: space();
307: MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder) configuration
308: .getBuilderFactory().getMemberSummaryBuilder(this );
309: AbstractMemberWriter writerOptional = ((AbstractMemberWriter) memberSummaryBuilder
310: .getMemberSummaryWriter(VisibleMemberMap.ANNOTATION_TYPE_MEMBER_OPTIONAL));
311: AbstractMemberWriter writerRequired = ((AbstractMemberWriter) memberSummaryBuilder
312: .getMemberSummaryWriter(VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED));
313: if (writerOptional != null) {
314: writerOptional
315: .printNavDetailLink(annotationType.elements().length > 0);
316: } else if (writerRequired != null) {
317: writerRequired
318: .printNavDetailLink(annotationType.elements().length > 0);
319: } else {
320: printText("doclet.navAnnotationTypeMember");
321: }
322: }
323:
324: protected void navGap() {
325: space();
326: print('|');
327: space();
328: }
329:
330: /**
331: * If this is an inner class or interface, write the enclosing class or
332: * interface.
333: */
334: public void writeNestedClassInfo() {
335: ClassDoc outerClass = annotationType.containingClass();
336: if (outerClass != null) {
337: dl();
338: dt();
339: if (annotationType.isInterface()) {
340: boldText("doclet.Enclosing_Interface");
341: } else {
342: boldText("doclet.Enclosing_Class");
343: }
344: dd();
345: printLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_CLASS,
346: outerClass, false));
347: ddEnd();
348: dlEnd();
349: }
350: }
351:
352: /**
353: * {@inheritDoc}
354: */
355: public AnnotationTypeDoc getAnnotationTypeDoc() {
356: return annotationType;
357: }
358:
359: /**
360: * {@inheritDoc}
361: */
362: public void completeMemberSummaryBuild() {
363: p();
364: }
365: }
|