KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > tools > doclets > standard > AbstractSubWriter


1 /* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the debugger and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  */

22 package org.aspectj.tools.doclets.standard;
23
24 import org.aspectj.ajdoc.IntroducedDoc;
25 import org.aspectj.tools.ajdoc.Access;
26
27 import com.sun.javadoc.ClassDoc;
28 import com.sun.javadoc.ProgramElementDoc;
29
30 import java.lang.reflect.Constructor JavaDoc;
31 import java.lang.reflect.Method JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.Collections JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import java.util.List JavaDoc;
37 import java.util.Map JavaDoc;
38
39
40 public class AbstractSubWriter
41     extends com.sun.tools.doclets.standard.AbstractSubWriter
42     implements AbstractSubWriterAJ
43 {
44
45     public AbstractSubWriter
46         (com.sun.tools.doclets.standard.SubWriterHolderWriter writer,
47          ClassDoc classdoc)
48     {
49         super(writer, classdoc);
50     }
51
52     public AbstractSubWriter
53         (com.sun.tools.doclets.standard.SubWriterHolderWriter writer)
54     {
55         super(writer);
56     }
57
58     public final void printSummaryMember(ClassDoc cd, ProgramElementDoc member) {
59         writer.printSummaryLinkType(this, member);
60         printSummaryLink(cd, member);
61         printSummaryLinkComment(member);
62     }
63     
64     protected final void printCrosscuts(ProgramElementDoc member) {
65         if (hasCrosscuts(classdoc, member)) {
66             writer.dl();
67             writer.dd();
68             printCrosscuts(classdoc, member);
69             writer.ddEnd();
70             writer.dlEnd();
71         }
72     }
73     
74     protected /*abstract*/ Class JavaDoc delegateClass() { throw new RuntimeException JavaDoc(""); }
75     /*final*/ private com.sun.tools.doclets.standard.AbstractSubWriter del;
76     { setDelegator(); }
77     protected final void setDelegator() {
78         com.sun.tools.doclets.standard.AbstractSubWriter mw = null;
79         try {
80             List JavaDoc list = new ArrayList JavaDoc();
81             if (writer != null) list.add(writer);
82             if (classdoc != null) list.add(classdoc);
83             setDelegator(mw = findDelegate
84                          (list.toArray
85                           (new Object JavaDoc[list.size()])));
86         } finally {
87             del = mw;
88         }
89     }
90     public final com.sun.tools.doclets.standard.AbstractSubWriter del() {
91         return del;
92     }
93     private final void setDelegator(Object JavaDoc o) {
94         if (o == null) return;
95         try {
96             Method JavaDoc[] ms = o.getClass().getMethods();
97             for (int i = 0; i < ms.length; i++) {
98                 if (ms[i].getName().equals("setDelegator")) {
99                     ms[i].invoke(o, new Object JavaDoc[]{this});
100                 }
101             }
102         } catch (Exception JavaDoc e) {
103             Standard.configuration().standardmessage.
104                 error("doclet.exception_encountered", e+"");
105         }
106     }
107     private final com.sun.tools.doclets.standard.AbstractSubWriter
108         findDelegate(Object JavaDoc[] params) {
109         if (delegateClass() == null) {
110             return this;
111         }
112         try {
113             Constructor JavaDoc[] cs = delegateClass().getConstructors();
114             for (int i = 0; i < cs.length; i++) {
115                 if (cs[i].getParameterTypes().length == params.length) {
116                     return (com.sun.tools.doclets.standard.AbstractSubWriter)
117                         cs[i].newInstance(params);
118                 }
119             }
120         } catch (Exception JavaDoc e) {
121             Standard.configuration().standardmessage.
122                 error("doclet.exception_encountered", e+"");
123         }
124         return null;
125     }
126
127     public int getMemberKind() {
128         return -1;
129     }
130     public void printSummaryLabel(ClassDoc cd) {
131         if (keyName() != null) {
132             summaryLabel(keyName());
133         } else {
134             del.printSummaryLabel(cd);
135         }
136     }
137     public void printSummaryAnchor(ClassDoc cd) {
138         if (keyName() != null) {
139             summaryAnchor(keyName());
140         } else {
141             del.printSummaryAnchor(cd);
142         }
143     }
144     public void printInheritedSummaryAnchor(ClassDoc cd) {
145         del.printInheritedSummaryAnchor(cd);
146     }
147     protected void printSummaryType(ProgramElementDoc member) {
148         Access.printSummaryType(this, member);
149     }
150     protected void printSummaryLink(ClassDoc cd,
151                                     ProgramElementDoc member) {
152         Access.printSummaryLink(this, cd, member);
153     }
154     protected void printInheritedSummaryLink(ClassDoc cd,
155                                              ProgramElementDoc member) {
156         Access.printInheritedSummaryLink(this, cd, member);
157     }
158     protected void printHeader(ClassDoc cd) {
159         if (keyName() != null) {
160             header(keyName());
161         } else {
162             Access.printHeader(this, cd);
163         }
164     }
165     protected void printBodyHtmlEnd(ClassDoc cd) {
166         Access.printBodyHtmlEnd(this, cd);
167     }
168     protected final void printMember(ProgramElementDoc elem) {
169         nonfinalPrintMember(elem);
170         printCrosscuts(elem);
171     }
172     protected void nonfinalPrintMember(ProgramElementDoc elem) {
173         Access.printMember(this, elem);
174     }
175     protected void printDeprecatedLink(ProgramElementDoc member) {
176         Access.printDeprecatedLink(this, member);
177     }
178     protected void printNavSummaryLink(ClassDoc cd, boolean link) {
179         if (keyName() != null) {
180             navSummaryLink(cd, keyName(), link);
181         } else {
182             Access.printNavSummaryLink(this, cd, link);
183         }
184     }
185     protected void printNavDetailLink(boolean link) {
186         if (keyName() != null) {
187             navDetailLink(keyName(), link);
188         } else {
189             Access.printNavDetailLink(this, link);
190         }
191     }
192
193     protected /*abstract*/ String JavaDoc propertyName() { return keyName(); }
194     protected /*abstract*/ String JavaDoc keyName() { return null; }
195     protected final String JavaDoc lowercase() {
196         String JavaDoc str = propertyName();
197         return str == null || str.length() == 0 ? "" :
198             Character.toLowerCase(str.charAt(0)) +
199             str.substring(1);
200     }
201     public void printInheritedSummaryLabel(ClassDoc cd) {
202         summaryLabel("Inherited_From", cd);
203     }
204     public void printIntroducedSummaryLabel(ClassDoc cd) {
205         summaryLabel("Introduced_From", cd);
206     }
207     public void printIntroducedSummaryAnchor(ClassDoc cd) {
208         summaryAnchor("introduced_from_class", cd);
209     }
210     protected final void summaryLabel(String JavaDoc keyName) {
211         writer.boldText("doclet." + keyName + "_Summary");
212     }
213     protected final void summaryAnchor(String JavaDoc keyName) {
214         writer.anchor(keyName.toLowerCase() + "_summary");
215     }
216     protected final void summaryLabel(String JavaDoc type, ClassDoc cd) {
217         writer.bold();
218         writer.printText("doclet." + propertyName() + "s_" + type,
219                          Statics.type(cd),
220                          writer.getPreQualifiedClassLink(cd));
221         writer.boldEnd();
222     }
223     protected final void summaryAnchor(String JavaDoc type, ClassDoc cd) {
224         writer.anchor(lowercase() + "s_" + type + "_" + cd.qualifiedName());
225     }
226     protected final String JavaDoc navKey(String JavaDoc keyName) {
227         return "doclet.nav" + keyName;
228     }
229     protected final String JavaDoc navKey() {
230         return navKey(keyName());
231     }
232     protected final void navLink(ClassDoc cd, String JavaDoc keyName,
233                                  boolean link, String JavaDoc kind) {
234         if (link) {
235             writer.printHyperLink
236                 ("",
237                  cd == null ?
238                  keyName.toLowerCase() + "_" + kind :
239                  keyName.toLowerCase() + "s_inherited_from_class_" +
240                  cd.qualifiedName(),
241                  writer.getText(navKey(keyName)));
242         } else {
243             writer.printText(navKey(keyName));
244         }
245     }
246     protected final void navSummaryLink(ClassDoc cd, String JavaDoc keyName, boolean link) {
247         navLink(cd, keyName, link, "summary");
248     }
249     protected final void navDetailLink(String JavaDoc keyName, boolean link) {
250         navLink(null, keyName, link, "detail");
251     }
252     protected final void header(String JavaDoc keyName) {
253         writer.anchor(keyName.toLowerCase() + "_detail");
254         writer.printTableHeadingBackground
255             (writer.getText("doclet." + keyName + "_Detail"));
256     }
257     
258     public void printCrosscuts(ClassDoc cd, ProgramElementDoc member) {}
259     public void printSummaryCrosscuts(ClassDoc cd, ProgramElementDoc member) {}
260     public boolean hasCrosscuts(ClassDoc cd,ProgramElementDoc member) {
261         return false;
262     }
263
264     protected void printHead(String JavaDoc name) {
265         writer.h3();
266         writer.print(name);
267         writer.h3End();
268     }
269
270     protected List JavaDoc nointros(List JavaDoc members) {
271         List JavaDoc list = new ArrayList JavaDoc();
272         for (Iterator JavaDoc i = members.iterator(); i.hasNext();) {
273             Object JavaDoc o = i.next();
274             if (o instanceof org.aspectj.ajdoc.MemberDoc) {
275                 IntroducedDoc intro =
276                     ((org.aspectj.ajdoc.MemberDoc)o).introduced();
277                 if (intro == null || intro.containingClass().equals(classdoc)) {
278                     list.add(o);
279                 }
280             } else {
281                 list.add(o);
282             }
283         }
284         return list;
285     }
286
287     public void printMembersSummary() {
288         nointros = true;
289         super.printMembersSummary();
290         nointros = false;
291     }
292
293     protected final void printSummaryLinkComment(ProgramElementDoc member) {
294         writer.codeEnd();
295         writer.println();
296         writer.br();
297         Access.printCommentDef(this, member);
298         boolean newline = member.tags("deprecated").length +
299             member.firstSentenceTags().length > 0;
300         if (classdoc != null || true) { // ?? always
301
if (hasCrosscuts(classdoc, member)) {
302                 if (newline) {
303                     writer.br();
304                     writer.printNbsps();
305                 }
306                 printSummaryCrosscuts(classdoc, member);
307             }
308         }
309         writer.summaryRowEnd();
310         writer.trEnd();
311     }
312
313     public void printIntroducedSummaryHeader(ClassDoc cd) {
314             printIntroducedSummaryAnchor(cd);
315             writer.tableIndexSummary();
316             writer.tableInheritedHeaderStart("#EEEEFF");
317             printIntroducedSummaryLabel(cd);
318             writer.tableInheritedHeaderEnd();
319             writer.trBgcolorStyle("white", "TableRowColor");
320             writer.summaryRow(0);
321             writer.code();
322     }
323     
324     public void printIntroducedSummaryFooter(ClassDoc cd) {
325             writer.codeEnd();
326             writer.summaryRowEnd();
327             writer.trEnd();
328             writer.tableEnd();
329             writer.space();
330     }
331     
332     public void printIntroducedSummaryMember(ClassDoc cd,
333                                              ProgramElementDoc member) {
334         printIntroducedSummaryLink(cd, member);
335     }
336     
337     public void printIntroducedSummaryLink(ClassDoc cd,
338                                            ProgramElementDoc member) {}
339     public void printIntroducedMembersSummary() {
340         Map JavaDoc typesToMembers = new HashMap JavaDoc();
341         for (Iterator JavaDoc i = members(classdoc).iterator(); i.hasNext();) {
342             Object JavaDoc o = i.next();
343             if (!(o instanceof org.aspectj.ajdoc.MemberDoc)) continue;
344             org.aspectj.ajdoc.MemberDoc md = (org.aspectj.ajdoc.MemberDoc)o;
345             if (md.introduced() != null) {
346                 ClassDoc cd = md.introduced().containingClass();
347                 List JavaDoc members = (List JavaDoc)typesToMembers.get(cd);
348                 if (members == null) members = new ArrayList JavaDoc();
349                 members.add(md);
350                 typesToMembers.put(cd, members);
351             }
352         }
353         for (Iterator JavaDoc i = typesToMembers.keySet().iterator(); i.hasNext();) {
354             ClassDoc cd = (ClassDoc)i.next();
355             printIntroducedSummaryHeader(cd);
356             List JavaDoc members = (List JavaDoc)typesToMembers.get(cd);
357             Collections.sort(members);
358             for (Iterator JavaDoc j = members.iterator(); j.hasNext();) {
359                 printIntroducedSummaryMember(cd, (ProgramElementDoc)j.next());
360                 if (j.hasNext()) print(", ");
361             }
362             printIntroducedSummaryFooter(cd);
363         }
364     }
365
366
367     private boolean nointros = false;
368     public void printMembers() {
369         nointros = true;
370         super.printMembers();
371         nointros = false;
372     }
373
374     public void navSummaryLink() {
375         nointros = true;
376         super.navSummaryLink();
377         nointros = false;
378     }
379         
380     protected void navDetailLink() {
381         printNavDetailLink(members(classdoc).size() > 0 ? true : false);
382     }
383     
384     public final List JavaDoc members(ClassDoc cd) {
385         return nointros ? nointros(getMembers(cd)) : getMembers(cd);
386     }
387     
388     protected List JavaDoc getMembers(ClassDoc cd) {
389         return super.members(cd);
390     }
391 }
392     
393     
394
Popular Tags