KickJava   Java API By Example, From Geeks To Geeks.

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


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.tools.ajdoc.Access;
25 import org.aspectj.tools.ajdoc.Util;
26
27 import com.sun.javadoc.ClassDoc;
28 import com.sun.javadoc.PackageDoc;
29 import com.sun.tools.doclets.DirectoryManager;
30 import com.sun.tools.doclets.DocletAbortException;
31
32 import java.io.File JavaDoc;
33 import java.io.IOException JavaDoc;
34 import java.util.Map JavaDoc;
35
36 /**
37  * Provides support for aspects.
38  *
39  * @author Jeff Palm
40  */

41 public class ClassUseWriter
42     extends com.sun.tools.doclets.standard.ClassUseWriter
43 {
44
45     /**
46      * The target ClassDoc.
47      */

48     protected final ClassDoc classdoc;
49
50     /**
51      * Maps PackageDocs to advice arguments.
52      */

53     protected final Map JavaDoc pkgToAdviceArgs;
54
55     /**
56      * Maps PackageDocs to advice return types.
57      */

58     protected final Map JavaDoc pkgToAdviceReturn;
59     
60     /**
61      * Maps PackageDocs to pointcut arguments.
62      */

63     protected final Map JavaDoc pkgToPointcutArgs;
64
65     /**
66      * Maps PackageDocs to pointcut return types.
67      */

68     protected final Map JavaDoc pkgToPointcutReturn;
69
70     /**
71      * Maps PackageDocs to field introductions.
72      */

73     protected final Map JavaDoc pkgToFieldIntroductions;
74
75     /**
76      * Maps PackageDocs to class introductions.
77      */

78     protected final Map JavaDoc pkgToClassIntroductions;
79     
80     /**
81      * Maps PackageDocs to interface introductions.
82      */

83     protected final Map JavaDoc pkgToInterfaceIntroductions;
84
85     /**
86      * Maps PackageDocs to class advisors.
87      */

88     protected final Map JavaDoc pkgToClassAdvisors;
89
90     /**
91      * Maps PackageDocs to aspects that dominate
92      * aspects in that package.
93      */

94     protected final Map JavaDoc pkgToAspectDominatees;
95
96     /**
97      * Maps PackageDocs to aspects that are dominated
98      * by aspects in that package.
99      */

100     protected final Map JavaDoc pkgToAspectDominators;
101
102     /**
103      * The MethodSubWriter to use.
104      */

105     protected final MethodSubWriter methodSubWriter
106         = new MethodSubWriter(this);
107     
108     /**
109      * The ConstructorSubWriter to use.
110      */

111     protected final ConstructorSubWriter constrSubWriter
112         = new ConstructorSubWriter(this);
113     
114     /**
115      * The FieldSubWriter to use.
116      */

117     protected final FieldSubWriter fieldSubWriter
118         = new FieldSubWriter(this);
119     
120     /**
121      * The ClassSubWriter to use.
122      */

123     protected final ClassSubWriter classSubWriter
124         = new ClassSubWriter(this);
125         
126     /**
127      * The PointcutSubWriter to use.
128      */

129     protected final PointcutSubWriter pointcutSubWriter
130         = new PointcutSubWriter(this);
131     
132     /**
133      * The SuperIntroductionSubWriter to use.
134      */

135     protected final SuperIntroductionSubWriter superIntroductionSubWriter
136         = new SuperIntroductionSubWriter(this);
137     
138     /**
139      * The FieldIntroductionSubWriter to use.
140      */

141     protected final FieldIntroductionSubWriter fieldIntroductionSubWriter
142         = new FieldIntroductionSubWriter(this);
143     
144     /**
145      * The ConstructorIntroductionSubWriter to use.
146      */

147     protected final ConstructorIntroductionSubWriter constrIntroductionSubWriter
148         = new ConstructorIntroductionSubWriter(this);
149     
150     /**
151      * The MethodIntroductionSubWriter to use.
152      */

153     protected final MethodIntroductionSubWriter methodIntroductionSubWriter
154         = new MethodIntroductionSubWriter(this);
155     
156     /**
157      * The AdviceSubWriter to use.
158      */

159     protected final AdviceSubWriter adviceSubWriter
160         = new AdviceSubWriter(this);
161     
162
163
164     public ClassUseWriter(ClassUseMapper mapper,
165                           String JavaDoc path,
166                           String JavaDoc filename,
167                           String JavaDoc relpath,
168                           ClassDoc classdoc)
169         throws IOException JavaDoc, DocletAbortException {
170
171         super(mapper.mapper(classdoc), path,
172               filename, relpath, classdoc);
173
174         mapper.restore(classdoc);
175
176         this.classdoc = Access.classdoc(this);
177
178         this.pkgToAdviceReturn =
179             _pkgDivide(mapper.classToAdviceReturn);
180         this.pkgToAdviceArgs =
181             _pkgDivide(mapper.classToAdviceArgs);
182         this.pkgToPointcutReturn =
183             _pkgDivide(mapper.classToPointcutReturn);
184         this.pkgToPointcutArgs =
185             _pkgDivide(mapper.classToPointcutArgs);
186         this.pkgToFieldIntroductions =
187             _pkgDivide(mapper.classToFieldIntroductions);
188         this.pkgToClassIntroductions =
189             _pkgDivide(mapper.classToClassIntroductions);
190         this.pkgToInterfaceIntroductions =
191             _pkgDivide(mapper.classToInterfaceIntroductions);
192         this.pkgToClassAdvisors =
193             _pkgDivide(mapper.classToAdvisors);
194         this.pkgToAspectDominatees =
195             _pkgDivide(mapper.classToDominatees);
196         this.pkgToAspectDominators =
197             _pkgDivide(mapper.classToDominators);
198     }
199
200     protected com.sun.tools.doclets.standard.ClassUseWriter
201         writer;
202     private Map JavaDoc _pkgDivide(Map JavaDoc classMap) {
203         return (Map JavaDoc)Util.invoke
204             (com.sun.tools.doclets.standard.ClassUseWriter.class,
205              this, "pkgDivide",
206              new Class JavaDoc[]{java.util.Map JavaDoc.class},
207              new Object JavaDoc[]{classMap});
208     }
209     
210     public static void generate(ClassUseMapper mapper,
211                                 ClassDoc classdoc)
212         throws DocletAbortException {
213         ClassUseWriter cw = null;
214         String JavaDoc path = DirectoryManager.getDirectoryPath(classdoc.
215                                                         containingPackage());
216         if (path.length() > 0) {
217             path += File.separator;
218         }
219         path += "class-use";
220         String JavaDoc filename = classdoc.name() + ".html";
221         String JavaDoc pkgname = classdoc.containingPackage().name();
222         pkgname += (pkgname.length() > 0 ? "." : "") + "class-use";
223         String JavaDoc relpath = DirectoryManager.getRelativePath(pkgname);
224         try {
225             (cw = new ClassUseWriter(mapper, path, filename,
226                                      relpath, classdoc)).
227                 generateClassUseFile();
228         } catch (IOException JavaDoc e) {
229             Standard.configuration().standardmessage.
230                 error("doclet.exception_encountered", e+"", filename);
231             throw new DocletAbortException();
232         } finally {
233             if (cw != null) cw.close();
234         }
235     }
236
237     protected void generateClassUse(PackageDoc pkg) throws IOException JavaDoc {
238         super.generateClassUse(pkg);
239         String JavaDoc classlink = getClassLink(classdoc);
240         String JavaDoc pkglink = getPackageLink(pkg);
241
242         printUseInfo(adviceSubWriter, pkgToAdviceReturn,
243                      pkg, "AdviceReturn", classlink, pkglink);
244         printUseInfo(adviceSubWriter, pkgToAdviceArgs,
245                      pkg, "AdviceArgs", classlink, pkglink);
246         printUseInfo(pointcutSubWriter, pkgToPointcutReturn,
247                      pkg, "PointcutReturn", classlink, pkglink);
248         printUseInfo(pointcutSubWriter, pkgToPointcutArgs,
249                      pkg, "PointcutArgs", classlink, pkglink);
250         printUseInfo(fieldIntroductionSubWriter, pkgToFieldIntroductions,
251                      pkg, "FieldIntroductions", classlink, pkglink);
252         printUseInfo(superIntroductionSubWriter, pkgToClassIntroductions,
253                      pkg, "ClassIntroductions", classlink, pkglink);
254         printUseInfo(superIntroductionSubWriter, pkgToInterfaceIntroductions,
255                      pkg, "InterfaceIntroductions", classlink, pkglink);
256         printUseInfo(classSubWriter, pkgToClassAdvisors,
257                      pkg, "ClassAdvisors", classlink, pkglink);
258
259         printUseInfo(classSubWriter, pkgToAspectDominatees,
260                      pkg, "AspectDominatees", classlink, pkglink);
261         printUseInfo(classSubWriter, pkgToAspectDominators,
262                      pkg, "AspectDominators", classlink, pkglink);
263     }
264
265     protected final void printUseInfo(AbstractSubWriter mw, Map JavaDoc map,
266                                       PackageDoc pkg, String JavaDoc kind,
267                                       String JavaDoc classlink, String JavaDoc pkglink) {
268         Access.printUseInfo(mw, map.get(pkg),
269                             getText("doclet.ClassUse_" + kind,
270                                     classlink,pkglink));
271     }
272 }
273
Popular Tags