KickJava   Java API By Example, From Geeks To Geeks.

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


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.AdviceDoc;
25 import org.aspectj.ajdoc.AspectDoc;
26
27 import com.sun.javadoc.ClassDoc;
28 import com.sun.javadoc.ProgramElementDoc;
29 import com.sun.tools.doclets.Util;
30
31 import java.util.ArrayList JavaDoc;
32 import java.util.Collections JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.List JavaDoc;
35
36 /**
37  * A splattering of misc. functionality.
38  *
39  * @author Jeff Palm
40  */

41 public class Statics {
42
43     /**
44      * Returns a aspectj-world type String of <code>cd</code>.
45      *
46      * @return either aspect interface or class depending
47      * on the type of <code>cd</code>.
48      */

49     public static String JavaDoc type(ClassDoc cd) {
50         return cd instanceof AspectDoc
51             ? "aspect" : cd.isInterface()
52             ? "interface" : "class";
53     }
54
55     /**
56      * Returns the link target for <code>member</code>.
57      *
58      * @param member the ProgramElementDoc in question.
59      * @return the link target for <code>member</code>.
60      */

61     public static String JavaDoc where(ProgramElementDoc member) {
62         return member.name();
63     }
64
65     /**
66      * Returns the link label for <code>member</code>.
67      *
68      * @param member the ProgramElementDoc in question.
69      * @return the link label for <code>member</code>.
70      */

71     public static String JavaDoc label(ProgramElementDoc member) {
72         return member.name();
73     }
74
75     /**
76      * Returns the link target for <code>member</code> from
77      * <code>cd</code>.
78      *
79      * @param cd the class from which we're linking.
80      * @param member the ProgramElementDoc in question.
81      * @return the link target for <code>member</code>.
82      */

83     public static String JavaDoc where(ClassDoc cd, ProgramElementDoc member) {
84         if (member instanceof AdviceDoc) {
85             return name(cd, (AdviceDoc)member).replace(' ','_').replace('#','-');
86         }
87         return member.name();
88     }
89
90     /**
91      * Returns the link label for <code>member</code> from
92      * <code>cd</code>.
93      *
94      * @param cd the class from which we're linking.
95      * @param member the ProgramElementDoc in question.
96      * @return the link target for <code>member</code>.
97      */

98     public static String JavaDoc label(ClassDoc cd, ProgramElementDoc member) {
99         return name(cd, member);
100     }
101
102     /**
103      * Returns the name for <code>member</code> from
104      * <code>cd</code>. This is here because we don't
105      * want really print the name of advice.
106      *
107      * @param cd the class from which we're printing.
108      * @param member the ProgramElementDoc in question.
109      * @return the name for <code>member</code>.
110      */

111     public static String JavaDoc name(ClassDoc cd, ProgramElementDoc member) {
112         if (member instanceof AdviceDoc) {
113             return name(cd, (AdviceDoc)member);
114         }
115         return member.name();
116     }
117
118     /**
119      * Returns the String that should be printed for
120      * an advice's name.
121      *
122      * @param cd the ClassDoc from where we're printing.
123      * @param advice the member in question.
124      * @return correct printing name for <code>advice</code>.
125      */

126     public static String JavaDoc name(ClassDoc cd, AdviceDoc advice) {
127         String JavaDoc name = advice.name();
128         int num = 1;
129         for (Iterator JavaDoc i = advice(cd).iterator(); i.hasNext();) {
130             AdviceDoc ad = (AdviceDoc)i.next();
131             if (ad.equals(advice)) {
132                 break;
133             }
134             if (ad.name().equals(name)) {
135                 num++;
136             }
137         }
138         return name + " #" + num;
139     }
140
141     /**
142      * Returns the advice contained in <code>classdoc</code>.
143      *
144      * @param cd ClassDoc in question.
145      * @return a List with the {@link AdviceDoc}s
146      * contained in <code>cd</code>.
147      */

148     public static List JavaDoc advice(ClassDoc classdoc) {
149         if (!(classdoc instanceof AspectDoc)) return Collections.EMPTY_LIST;
150         AdviceDoc[] advice = ((AspectDoc)classdoc).advice();
151         return advice == null ? Collections.EMPTY_LIST : Util.asList(advice);
152     }
153     
154     /**
155      * Returns an array of classes only.
156      *
157      * @param arr source array from where the ClassDocs in
158      * the result will come.
159      * @return an array of ClassDoc containing only
160      * classes, <b>no aspects</b>.
161      */

162     public static ClassDoc[] classes(ClassDoc[] arr) {
163         List JavaDoc list = new ArrayList JavaDoc();
164         for (int i = 0; i < arr.length; i++) {
165             if (!(arr[i] instanceof AspectDoc)) {
166                 list.add(arr[i]);
167             }
168         }
169         return (ClassDoc[])list.toArray(new ClassDoc[list.size()]);
170     }
171
172     /**
173      * Returns a list of the classes found in the
174      * passed in list of types.
175      *
176      * @param types List of ClassDocs.
177      * @return a List containing those ClassDocs in
178      * <code>types</code> that <i>are not</i> aspects.
179      * @see #types(List,boolean)
180      */

181     public static List JavaDoc classes(List JavaDoc types) {
182         return types(types, false);
183     }
184
185     /**
186      * Returns a list of the classes found in the
187      * passed in list of types.
188      *
189      * @param types List of ClassDocs.
190      * @return a List containing those ClassDocs in
191      * <code>types</code> that <i>are</i> aspects.
192      * @see #types(List,boolean)
193      */

194     public static List JavaDoc aspects(List JavaDoc types) {
195         return types(types, true);
196     }
197
198     /**
199      * Returns a list of ClassDocs taken from <code>types</code>
200      * that are aspects iff <code>wantAspects</code>.
201      *
202      * @param types source List of ClassDocs.
203      * @param wantAspects ClassDocs <i>c<i>in the resulting List will
204      * conform to the test:
205      * <code>c instanceof AspectDoc) == wantAspects<code>.
206      * @return a List of ClassDocs all who conform to the test:
207      * <code>c instanceof AspectDoc) == wantAspects<code>.
208      */

209     public static List JavaDoc types(List JavaDoc types, boolean wantAspects) {
210         List JavaDoc list = new ArrayList JavaDoc();
211         for (Iterator JavaDoc i = types.iterator(); i.hasNext();) {
212             ClassDoc cd = (ClassDoc)i.next();
213             if ((cd instanceof AspectDoc) == wantAspects) {
214                 list.add(cd);
215             }
216         }
217         return list;
218     }
219
220     /**
221      * Returns a prequalified class link to <code>cd</code> using
222      * the link target <code>where</code>.
223      *
224      * @param writer base writer to use.
225      * @param cd class to where we're linking.
226      * @param where link target.
227      * @return prequalified class link using
228      * <code>cd</code> and <code>where</code>.
229      */

230     public static String JavaDoc getPreQualifiedClassLink
231         (com.sun.tools.doclets.standard.SubWriterHolderWriter writer,
232          ClassDoc cd,
233          String JavaDoc where) {
234         return writer.getPkgName(cd) + writer.getClassLink(cd, where, cd.name());
235     }
236
237     /**
238      * Returns a prequalified class link to <code>cd</code> using
239      * the link target <code>where</code> returned by
240      * calling <code>getPreQualifiedClassLink</code>.
241      *
242      * @param writer base writer to use.
243      * @param cd class to where we're linking.
244      * @param where link target.
245      * @see #getPreQualifiedClassLink
246      */

247     public static void printPreQualifiedClassLink
248         (com.sun.tools.doclets.standard.SubWriterHolderWriter writer,
249          ClassDoc cd,
250          String JavaDoc where) {
251         writer.print(getPreQualifiedClassLink(writer, cd, where));
252     }
253 }
254
Popular Tags