KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > tools > ajdoc > ExecutableMemberDocImpl


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.ajdoc;
23
24 import org.aspectj.ajdoc.AdviceDoc;
25 import org.aspectj.compiler.base.ast.Formals;
26 import org.aspectj.compiler.base.ast.NameType;
27 import org.aspectj.compiler.base.ast.TypeDs;
28
29 import com.sun.javadoc.ClassDoc;
30 import com.sun.javadoc.ExecutableMemberDoc;
31 import com.sun.javadoc.ParamTag;
32 import com.sun.javadoc.Parameter;
33 import com.sun.javadoc.ThrowsTag;
34
35 import java.lang.reflect.Modifier JavaDoc;
36 import java.util.ArrayList JavaDoc;
37 import java.util.Collection JavaDoc;
38 import java.util.Collections JavaDoc;
39 import java.util.List JavaDoc;
40
41 public abstract class ExecutableMemberDocImpl
42     extends MemberDocImpl
43     implements ExecutableMemberDoc {
44
45     /*
46      * These three fields should be final, but can't because
47      * they contain calls to abstract methods that aren't
48      * valid until after the subclasses constructor is run.
49      * To compensate the accessor methods lazily evaluate
50      * them, and these methods are final.
51      */

52
53     /** The collection of advice placed on each ExecutableMemberDoc. */
54     private Collection JavaDoc advice;
55
56     /** The List of parameters. */
57     private Collection JavaDoc parameters;
58
59     /** The List of thrown exceptions. */
60     private Collection JavaDoc thrownExceptions;
61
62     /** The full signature. */
63     private String JavaDoc signature;
64
65     /** The flat signature. */
66     private String JavaDoc flatSignature;
67
68     /**
69      * Constructs a new Doc with the enclosing ClassDoc.
70      *
71      * @param containingClass enclosing ClassDoc.
72      */

73     public ExecutableMemberDocImpl(ClassDoc containingClass) {
74         super(containingClass);
75     }
76     
77     /**
78      * Returns a non-null Collection of AdviceDoc
79      * representing the advice placed on the underlying Dec.
80      *
81      * @return a non-null Collection of AdviceDoc
82      * representing the advice placed on the
83      * underlying Dec.
84      */

85     protected abstract Collection JavaDoc createAdvice();
86
87     /**
88      * Returns the Formals of the underlying Dec.
89      *
90      * @return the Formals of the underlying Dec.
91      */

92     protected abstract Formals getFormals();
93
94     /**
95      * Returns the TypeDs representing the exceptions
96      * thrown by the underlying Dec.
97      *
98      * @return the TypeDs representing the exceptions
99      * thrown by the underlying Dec.
100      */

101     protected abstract TypeDs getThrows();
102
103
104     /**
105      * Converts the passed in Formals to a Collection of
106      * Parameter and sets our parameters to this value.
107      *
108      * @param formals the Formals to use.
109      */

110     public void makeParameters(Formals formals) {
111         parameters = createParameters(formals);
112     }
113
114     /**
115      * Converts the passed in TypeDs to a Collection of
116      * ClassDoc and sets our thrownExceptions to this value.
117      *
118      * @param thrown the TypeDs to use.
119      */

120     public void makeThrownExceptions(TypeDs thrown) {
121         thrownExceptions = createThrownExceptions(thrown);
122     }
123
124     /**
125      * Returns the advice affecting this member.
126      *
127      * @return an array of AdviceDoc representing the advice
128      * affecting this member.
129      */

130     public final AdviceDoc[] advice() {
131         if (advice == null) advice = createAdvice();
132         return (AdviceDoc[])advice.toArray(new AdviceDoc[advice.size()]);
133     }
134
135     /**
136      * Returns the exceptions this code declares to throw.
137      *
138      * @return an array of ClassDoc representing the exceptions
139      * this code declares to throw.
140      */

141     public final ClassDoc[] thrownExceptions() {
142         if (thrownExceptions == null) makeThrownExceptions(getThrows());
143         return (ClassDoc[])thrownExceptions.toArray
144             (new ClassDoc[thrownExceptions.size()]);
145     }
146
147     /**
148      * Returns the parameters taken by this code.
149      *
150      * @return an array of Parameter representing the
151      * parameters this code takes.
152      */

153     public final Parameter[] parameters() {
154         if (parameters == null) makeParameters(getFormals());
155         return (Parameter[])parameters.toArray
156             (new Parameter[parameters.size()]);
157     }
158
159     /**
160      * Returns the flat signature.
161      *
162      * @return the flat signature with all types unqualified.
163      */

164     public String JavaDoc flatSignature() {
165         if (flatSignature == null) {
166             flatSignature = Util.flatSignature(parameters());
167         }
168         return flatSignature;
169     }
170
171     /**
172      * Returns the full signature.
173      *
174      * @return the full signature with all types qualified.
175      */

176     public String JavaDoc signature() {
177         if (signature == null) {
178             signature = Util.signature(parameters());
179         }
180         return signature;
181     }
182
183     /**
184      * Returns <code>true</code> if this code is <code>synchronized</code>.
185      *
186      * @return <code>true</code> if this code is <code>synchronized</code>.
187      */

188     public boolean isSynchronized() {
189         //return getModifiers().isSynchronized();
190
return Modifier.isSynchronized(modifierSpecifier());
191     }
192     
193     /**
194      * Returns <code>true</code>if this code is <code>native</code>.
195      *
196      * @return <code>true</code>if this code is <code>native</code>.
197      */

198     public boolean isNative() {
199         //return (modifierSpecifier() & Modifiers.NATIVE) != 0;
200
return Modifier.isNative(modifierSpecifier());
201     }
202
203     /**
204      * Returns the throw tags describing exceptions thrown
205      * declared by this code.
206      *
207      * @return an array of ThrowsTag representing the exception
208      * this code declares to throw.
209      */

210     public ThrowsTag[] throwsTags() {
211         return getComment().throwsTags();
212     }
213
214     /**
215      * Returns the param tags describing parameters taken
216      * by this code.
217      *
218      * @return an array of ParamTag representing the
219      * parameters taken by this code.
220      */

221     public ParamTag[] paramTags() {
222         return getComment().paramTags();
223     }
224
225     /**
226      * Returns the simple name followed the parameters
227      * enclosed in parens.
228      *
229      * @return the simple name followed the parameters
230      * enclosed in parens.
231      */

232     public String JavaDoc toString() {
233         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(name());
234         sb.append('(');
235         Parameter[] params = parameters();
236         for (int i = 0, N = params.length; i < N; i++) {
237             if (i > 0) sb.append(",");
238             sb.append(params[i].type().qualifiedTypeName());
239             sb.append(params[i].type().dimension());
240         }
241         sb.append(')');
242         return sb.toString();
243     }
244
245     /**
246      * Returns a Collection of Parameter corresponding to
247      * the Formals passed in.
248      *
249      * @param formals the Formals to use.
250      * @return a Collection of Parameter corresponding to
251      * the Formals passed in.
252      */

253     private Collection JavaDoc createParameters(Formals formals) {
254         if (formals == null) return Collections.EMPTY_LIST;
255         List JavaDoc list = new ArrayList JavaDoc(formals.size());
256         for (int i = 0, N = formals.size(); i < N; i++) {
257             list.add(new ParameterImpl(formals.get(i)));
258         }
259         return list;
260     }
261
262     /**
263      * Returns a Collection of ClassDoc corresponding to
264      * the TypeDs passed in.
265      *
266      * @param thrown the TypeDs to use
267      * @return a Collection of ClassDoc corresponding to
268      * the TypeDs passed in.
269      */

270     private Collection JavaDoc createThrownExceptions(TypeDs typeds) {
271         if (typeds == null) return Collections.EMPTY_LIST;
272         List JavaDoc list = new ArrayList JavaDoc(typeds.size());
273         for (int i = 0, N = typeds.size(); i < N; i++) {
274             list.add(ClassDocImpl.getInstance
275                      (((NameType)typeds.get(i).getType()).getTypeDec()));
276         }
277         return list;
278     }
279
280     /**
281      * Returns <code>true</code> if the passed in Object is
282      * an ExecutableMemberDocImpl, its name equals ours, and
283      * its parameters <code>equals</code> ours.
284      *
285      * @return equality based on name and parameters.
286      */

287     public boolean weakEquals(Object JavaDoc md) {
288         if (!(md instanceof ExecutableMemberDocImpl)) {
289             return false;
290         }
291         ExecutableMemberDocImpl emdi = (ExecutableMemberDocImpl)md;
292         if (!name().equals(emdi.name())) {
293             return false;
294         }
295         Parameter[] ourPds = this.parameters();
296         Parameter[] edsPds = emdi.parameters();
297         if (ourPds.length != edsPds.length) {
298             return false;
299         }
300         for (int i = 0, N = ourPds.length; i < N; i++) {
301             if (!ourPds[i].equals(edsPds[i])) {
302                 return false;
303             }
304         }
305         return true;
306     }
307 }
308
Popular Tags