KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > internal > lang > reflect > AjTypeImpl


1 /* *******************************************************************
2  * Copyright (c) 2005 Contributors.
3  * All rights reserved.
4  * This program and the accompanying materials are made available
5  * under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution and is available at
7  * http://eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Adrian Colyer Initial implementation
11  * ******************************************************************/

12 package org.aspectj.internal.lang.reflect;
13
14 import java.lang.annotation.Annotation JavaDoc;
15 import java.lang.reflect.Constructor JavaDoc;
16 import java.lang.reflect.Field JavaDoc;
17 import java.lang.reflect.Method JavaDoc;
18 import java.lang.reflect.Modifier JavaDoc;
19 import java.lang.reflect.Type JavaDoc;
20 import java.lang.reflect.TypeVariable JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.Arrays JavaDoc;
23 import java.util.EnumSet JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Set JavaDoc;
26
27 import org.aspectj.internal.lang.annotation.ajcDeclareAnnotation;
28 import org.aspectj.internal.lang.annotation.ajcDeclareEoW;
29 import org.aspectj.internal.lang.annotation.ajcDeclareParents;
30 import org.aspectj.internal.lang.annotation.ajcDeclarePrecedence;
31 import org.aspectj.internal.lang.annotation.ajcDeclareSoft;
32 import org.aspectj.internal.lang.annotation.ajcITD;
33 import org.aspectj.internal.lang.annotation.ajcPrivileged;
34 import org.aspectj.lang.annotation.After;
35 import org.aspectj.lang.annotation.AfterReturning;
36 import org.aspectj.lang.annotation.AfterThrowing;
37 import org.aspectj.lang.annotation.Around;
38 import org.aspectj.lang.annotation.Aspect;
39 import org.aspectj.lang.annotation.Before;
40 import org.aspectj.lang.annotation.DeclareError;
41 import org.aspectj.lang.annotation.DeclareWarning;
42 import org.aspectj.lang.reflect.Advice;
43 import org.aspectj.lang.reflect.AdviceKind;
44 import org.aspectj.lang.reflect.AjType;
45 import org.aspectj.lang.reflect.AjTypeSystem;
46 import org.aspectj.lang.reflect.DeclareAnnotation;
47 import org.aspectj.lang.reflect.DeclareErrorOrWarning;
48 import org.aspectj.lang.reflect.DeclareParents;
49 import org.aspectj.lang.reflect.DeclarePrecedence;
50 import org.aspectj.lang.reflect.DeclareSoft;
51 import org.aspectj.lang.reflect.InterTypeConstructorDeclaration;
52 import org.aspectj.lang.reflect.InterTypeFieldDeclaration;
53 import org.aspectj.lang.reflect.InterTypeMethodDeclaration;
54 import org.aspectj.lang.reflect.NoSuchAdviceException;
55 import org.aspectj.lang.reflect.NoSuchPointcutException;
56 import org.aspectj.lang.reflect.PerClause;
57 import org.aspectj.lang.reflect.PerClauseKind;
58 import org.aspectj.lang.reflect.Pointcut;
59
60
61 /**
62  * @author colyer
63  *
64  */

65 public class AjTypeImpl<T> implements AjType<T> {
66     
67     private static final String JavaDoc ajcMagic = "ajc$";
68     
69     private Class JavaDoc<T> clazz;
70     private Pointcut[] declaredPointcuts = null;
71     private Pointcut[] pointcuts = null;
72     private Advice[] declaredAdvice = null;
73     private Advice[] advice = null;
74     private InterTypeMethodDeclaration[] declaredITDMethods = null;
75     private InterTypeMethodDeclaration[] itdMethods = null;
76     private InterTypeFieldDeclaration[] declaredITDFields = null;
77     private InterTypeFieldDeclaration[] itdFields = null;
78     private InterTypeConstructorDeclaration[] itdCons = null;
79     private InterTypeConstructorDeclaration[] declaredITDCons = null;
80     
81     public AjTypeImpl(Class JavaDoc<T> fromClass) {
82         this.clazz = fromClass;
83     }
84
85     /* (non-Javadoc)
86      * @see org.aspectj.lang.reflect.AjType#getName()
87      */

88     public String JavaDoc getName() {
89         return clazz.getName();
90     }
91
92     /* (non-Javadoc)
93      * @see org.aspectj.lang.reflect.AjType#getPackage()
94      */

95     public Package JavaDoc getPackage() {
96         return clazz.getPackage();
97     }
98
99     /* (non-Javadoc)
100      * @see org.aspectj.lang.reflect.AjType#getInterfaces()
101      */

102     public AjType<?>[] getInterfaces() {
103         Class JavaDoc<?>[] baseInterfaces = clazz.getInterfaces();
104         return toAjTypeArray(baseInterfaces);
105     }
106
107     /* (non-Javadoc)
108      * @see org.aspectj.lang.reflect.AjType#getModifiers()
109      */

110     public int getModifiers() {
111         return clazz.getModifiers();
112     }
113     
114     public Class JavaDoc<T> getJavaClass() {
115         return clazz;
116     }
117
118     /* (non-Javadoc)
119      * @see org.aspectj.lang.reflect.AjType#getSupertype()
120      */

121     public AjType<? super T> getSupertype() {
122         Class JavaDoc<? super T> superclass = clazz.getSuperclass();
123         return superclass==null ? null : (AjType<? super T>) new AjTypeImpl(superclass);
124     }
125
126     /* (non-Javadoc)
127      * @see org.aspectj.lang.reflect.AjType#getGenericSupertype()
128      */

129     public Type JavaDoc getGenericSupertype() {
130         return clazz.getGenericSuperclass();
131     }
132
133     /* (non-Javadoc)
134      * @see org.aspectj.lang.reflect.AjType#getEnclosingMethod()
135      */

136     public Method JavaDoc getEnclosingMethod() {
137         return clazz.getEnclosingMethod();
138     }
139
140     /* (non-Javadoc)
141      * @see org.aspectj.lang.reflect.AjType#getEnclosingConstructor()
142      */

143     public Constructor JavaDoc getEnclosingConstructor() {
144         return clazz.getEnclosingConstructor();
145     }
146
147     /* (non-Javadoc)
148      * @see org.aspectj.lang.reflect.AjType#getEnclosingType()
149      */

150     public AjType<?> getEnclosingType() {
151         Class JavaDoc<?> enc = clazz.getEnclosingClass();
152         return enc != null ? new AjTypeImpl(enc) : null;
153     }
154
155     /* (non-Javadoc)
156      * @see org.aspectj.lang.reflect.AjType#getDeclaringType()
157      */

158     public AjType<?> getDeclaringType() {
159         Class JavaDoc dec = clazz.getDeclaringClass();
160         return dec != null ? new AjTypeImpl(dec) : null;
161     }
162     
163     public PerClause getPerClause() {
164         if (isAspect()) {
165             Aspect aspectAnn = clazz.getAnnotation(Aspect.class);
166             String JavaDoc perClause = aspectAnn.value();
167             if (perClause.equals("")) {
168                 if (getSupertype().isAspect()) {
169                     return getSupertype().getPerClause();
170                 }
171                 return new PerClauseImpl(PerClauseKind.SINGLETON);
172             } else if (perClause.startsWith("perthis(")) {
173                 return new PointcutBasedPerClauseImpl(PerClauseKind.PERTHIS,perClause.substring("perthis(".length(),perClause.length() - 1));
174             } else if (perClause.startsWith("pertarget(")) {
175                 return new PointcutBasedPerClauseImpl(PerClauseKind.PERTARGET,perClause.substring("pertarget(".length(),perClause.length() - 1));
176             } else if (perClause.startsWith("percflow(")) {
177                 return new PointcutBasedPerClauseImpl(PerClauseKind.PERCFLOW,perClause.substring("percflow(".length(),perClause.length() - 1));
178             } else if (perClause.startsWith("percflowbelow(")) {
179                 return new PointcutBasedPerClauseImpl(PerClauseKind.PERCFLOWBELOW,perClause.substring("percflowbelow(".length(),perClause.length() - 1));
180             } else if (perClause.startsWith("pertypewithin")) {
181                 return new TypePatternBasedPerClauseImpl(PerClauseKind.PERTYPEWITHIN,perClause.substring("pertypewithin(".length(),perClause.length() - 1));
182             } else {
183                 throw new IllegalStateException JavaDoc("Per-clause not recognized: " + perClause);
184             }
185         } else {
186             return null;
187         }
188     }
189
190     /* (non-Javadoc)
191      * @see org.aspectj.lang.reflect.AjType#isAnnotationPresent(java.lang.Class)
192      */

193     public boolean isAnnotationPresent(Class JavaDoc<? extends Annotation JavaDoc> annotationType) {
194         return clazz.isAnnotationPresent(annotationType);
195     }
196
197     public <A extends Annotation JavaDoc> A getAnnotation(Class JavaDoc<A> annotationType) {
198         return clazz.getAnnotation(annotationType);
199     }
200     
201     /* (non-Javadoc)
202      * @see org.aspectj.lang.reflect.AjType#getAnnotations()
203      */

204     public Annotation JavaDoc[] getAnnotations() {
205         return clazz.getAnnotations();
206     }
207
208     /* (non-Javadoc)
209      * @see org.aspectj.lang.reflect.AjType#getDeclaredAnnotations()
210      */

211     public Annotation JavaDoc[] getDeclaredAnnotations() {
212         return clazz.getDeclaredAnnotations();
213     }
214
215     /* (non-Javadoc)
216      * @see org.aspectj.lang.reflect.AjType#getAspects()
217      */

218     public AjType<?>[] getAjTypes() {
219         Class JavaDoc[] classes = clazz.getClasses();
220         return toAjTypeArray(classes);
221     }
222
223     /* (non-Javadoc)
224      * @see org.aspectj.lang.reflect.AjType#getDeclaredAspects()
225      */

226     public AjType<?>[] getDeclaredAjTypes() {
227         Class JavaDoc[] classes = clazz.getDeclaredClasses();
228         return toAjTypeArray(classes);
229     }
230
231     /* (non-Javadoc)
232      * @see org.aspectj.lang.reflect.AjType#getConstructor(java.lang.Class...)
233      */

234     public Constructor JavaDoc getConstructor(AjType<?>... parameterTypes) throws NoSuchMethodException JavaDoc {
235         return clazz.getConstructor(toClassArray(parameterTypes));
236     }
237
238     /* (non-Javadoc)
239      * @see org.aspectj.lang.reflect.AjType#getConstructors()
240      */

241     public Constructor JavaDoc[] getConstructors() {
242         return clazz.getConstructors();
243     }
244
245     /* (non-Javadoc)
246      * @see org.aspectj.lang.reflect.AjType#getDeclaredConstructor(java.lang.Class...)
247      */

248     public Constructor JavaDoc getDeclaredConstructor(AjType<?>... parameterTypes) throws NoSuchMethodException JavaDoc {
249         return clazz.getDeclaredConstructor(toClassArray(parameterTypes));
250     }
251
252     /* (non-Javadoc)
253      * @see org.aspectj.lang.reflect.AjType#getDeclaredConstructors()
254      */

255     public Constructor JavaDoc[] getDeclaredConstructors() {
256         return clazz.getDeclaredConstructors();
257     }
258
259     /* (non-Javadoc)
260      * @see org.aspectj.lang.reflect.AjType#getDeclaredField(java.lang.String)
261      */

262     public Field JavaDoc getDeclaredField(String JavaDoc name) throws NoSuchFieldException JavaDoc {
263         Field JavaDoc f = clazz.getDeclaredField(name);
264         if (f.getName().startsWith(ajcMagic)) throw new NoSuchFieldException JavaDoc(name);
265         return f;
266     }
267
268     /* (non-Javadoc)
269      * @see org.aspectj.lang.reflect.AjType#getDeclaredFields()
270      */

271     public Field JavaDoc[] getDeclaredFields() {
272         Field JavaDoc[] fields = clazz.getDeclaredFields();
273         List JavaDoc<Field JavaDoc> filteredFields = new ArrayList JavaDoc<Field JavaDoc>();
274         for (Field JavaDoc field : fields)
275             if (!field.getName().startsWith(ajcMagic)
276                 && !field.isAnnotationPresent(DeclareWarning.class)
277                 && !field.isAnnotationPresent(DeclareError.class)) {
278                 filteredFields.add(field);
279             }
280         Field JavaDoc[] ret = new Field JavaDoc[filteredFields.size()];
281         filteredFields.toArray(ret);
282         return ret;
283     }
284
285     /* (non-Javadoc)
286      * @see org.aspectj.lang.reflect.AjType#getField(java.lang.String)
287      */

288     public Field JavaDoc getField(String JavaDoc name) throws NoSuchFieldException JavaDoc {
289         Field JavaDoc f = clazz.getField(name);
290         if (f.getName().startsWith(ajcMagic)) throw new NoSuchFieldException JavaDoc(name);
291         return f;
292     }
293
294     /* (non-Javadoc)
295      * @see org.aspectj.lang.reflect.AjType#getFields()
296      */

297     public Field JavaDoc[] getFields() {
298         Field JavaDoc[] fields = clazz.getFields();
299         List JavaDoc<Field JavaDoc> filteredFields = new ArrayList JavaDoc<Field JavaDoc>();
300         for (Field JavaDoc field : fields)
301             if (!field.getName().startsWith(ajcMagic)
302                     && !field.isAnnotationPresent(DeclareWarning.class)
303                     && !field.isAnnotationPresent(DeclareError.class)) {
304                     filteredFields.add(field);
305                 }
306         Field JavaDoc[] ret = new Field JavaDoc[filteredFields.size()];
307         filteredFields.toArray(ret);
308         return ret;
309     }
310
311     /* (non-Javadoc)
312      * @see org.aspectj.lang.reflect.AjType#getDeclaredMethod(java.lang.String, java.lang.Class...)
313      */

314     public Method JavaDoc getDeclaredMethod(String JavaDoc name, AjType<?>... parameterTypes) throws NoSuchMethodException JavaDoc {
315         Method JavaDoc m = clazz.getDeclaredMethod(name,toClassArray(parameterTypes));
316         if (!isReallyAMethod(m)) throw new NoSuchMethodException JavaDoc(name);
317         return m;
318     }
319
320     /* (non-Javadoc)
321      * @see org.aspectj.lang.reflect.AjType#getMethod(java.lang.String, java.lang.Class...)
322      */

323     public Method JavaDoc getMethod(String JavaDoc name, AjType<?>... parameterTypes) throws NoSuchMethodException JavaDoc {
324         Method JavaDoc m = clazz.getMethod(name,toClassArray(parameterTypes));
325         if (!isReallyAMethod(m)) throw new NoSuchMethodException JavaDoc(name);
326         return m;
327     }
328
329     /* (non-Javadoc)
330      * @see org.aspectj.lang.reflect.AjType#getDeclaredMethods()
331      */

332     public Method JavaDoc[] getDeclaredMethods() {
333         Method JavaDoc[] methods = clazz.getDeclaredMethods();
334         List JavaDoc<Method JavaDoc> filteredMethods = new ArrayList JavaDoc<Method JavaDoc>();
335         for (Method JavaDoc method : methods) {
336             if (isReallyAMethod(method)) filteredMethods.add(method);
337         }
338         Method JavaDoc[] ret = new Method JavaDoc[filteredMethods.size()];
339         filteredMethods.toArray(ret);
340         return ret;
341     }
342
343     /* (non-Javadoc)
344      * @see org.aspectj.lang.reflect.AjType#getMethods()
345      */

346     public Method JavaDoc[] getMethods() {
347         Method JavaDoc[] methods = clazz.getMethods();
348         List JavaDoc<Method JavaDoc> filteredMethods = new ArrayList JavaDoc<Method JavaDoc>();
349         for (Method JavaDoc method : methods) {
350             if (isReallyAMethod(method)) filteredMethods.add(method);
351         }
352         Method JavaDoc[] ret = new Method JavaDoc[filteredMethods.size()];
353         filteredMethods.toArray(ret);
354         return ret;
355     }
356
357     private boolean isReallyAMethod(Method JavaDoc method) {
358         if (method.getName().startsWith(ajcMagic)) return false;
359         if (method.isAnnotationPresent(org.aspectj.lang.annotation.Pointcut.class)) return false;
360         if (method.isAnnotationPresent(Before.class)) return false;
361         if (method.isAnnotationPresent(After.class)) return false;
362         if (method.isAnnotationPresent(AfterReturning.class)) return false;
363         if (method.isAnnotationPresent(AfterThrowing.class)) return false;
364         if (method.isAnnotationPresent(Around.class)) return false;
365         return true;
366     }
367     
368     /* (non-Javadoc)
369      * @see org.aspectj.lang.reflect.AjType#getDeclaredPointcut(java.lang.String)
370      */

371     public Pointcut getDeclaredPointcut(String JavaDoc name) throws NoSuchPointcutException {
372         Pointcut[] pcs = getDeclaredPointcuts();
373         for (Pointcut pc : pcs)
374             if (pc.getName().equals(name)) return pc;
375         throw new NoSuchPointcutException(name);
376     }
377
378     /* (non-Javadoc)
379      * @see org.aspectj.lang.reflect.AjType#getPointcut(java.lang.String)
380      */

381     public Pointcut getPointcut(String JavaDoc name) throws NoSuchPointcutException {
382         Pointcut[] pcs = getPointcuts();
383         for (Pointcut pc : pcs)
384             if (pc.getName().equals(name)) return pc;
385         throw new NoSuchPointcutException(name);
386     }
387
388     /* (non-Javadoc)
389      * @see org.aspectj.lang.reflect.AjType#getDeclaredPointcuts()
390      */

391     public Pointcut[] getDeclaredPointcuts() {
392         if (declaredPointcuts != null) return declaredPointcuts;
393         List JavaDoc<Pointcut> pointcuts = new ArrayList JavaDoc<Pointcut>();
394         Method JavaDoc[] methods = clazz.getDeclaredMethods();
395         for (Method JavaDoc method : methods) {
396             Pointcut pc = asPointcut(method);
397             if (pc != null) pointcuts.add(pc);
398         }
399         Pointcut[] ret = new Pointcut[pointcuts.size()];
400         pointcuts.toArray(ret);
401         declaredPointcuts = ret;
402         return ret;
403     }
404
405     /* (non-Javadoc)
406      * @see org.aspectj.lang.reflect.AjType#getPointcuts()
407      */

408     public Pointcut[] getPointcuts() {
409         if (pointcuts != null) return pointcuts;
410         List JavaDoc<Pointcut> pcuts = new ArrayList JavaDoc<Pointcut>();
411         Method JavaDoc[] methods = clazz.getMethods();
412         for (Method JavaDoc method : methods) {
413             Pointcut pc = asPointcut(method);
414             if (pc != null) pcuts.add(pc);
415         }
416         Pointcut[] ret = new Pointcut[pcuts.size()];
417         pcuts.toArray(ret);
418         pointcuts = ret;
419         return ret;
420     }
421
422     private Pointcut asPointcut(Method JavaDoc method) {
423         org.aspectj.lang.annotation.Pointcut pcAnn = method.getAnnotation(org.aspectj.lang.annotation.Pointcut.class);
424         if (pcAnn != null) {
425             String JavaDoc name = method.getName();
426             if (name.startsWith(ajcMagic)) {
427                 // extract real name
428
int nameStart = name.indexOf("$$");
429                 name = name.substring(nameStart +2,name.length());
430                 int nextDollar = name.indexOf("$");
431                 if (nextDollar != -1) name = name.substring(0,nextDollar);
432             }
433             return new PointcutImpl(name,pcAnn.value(),method,AjTypeSystem.getAjType(method.getDeclaringClass()),pcAnn.argNames());
434         } else {
435             return null;
436         }
437     }
438     
439     
440     public Advice[] getDeclaredAdvice(AdviceKind... ofType) {
441         Set JavaDoc<AdviceKind> types;
442         if (ofType.length == 0) {
443             types = EnumSet.allOf(AdviceKind.class);
444         } else {
445             types = EnumSet.noneOf(AdviceKind.class);
446             types.addAll(Arrays.asList(ofType));
447         }
448         return getDeclaredAdvice(types);
449     }
450     
451     public Advice[] getAdvice(AdviceKind... ofType) {
452         Set JavaDoc<AdviceKind> types;
453         if (ofType.length == 0) {
454             types = EnumSet.allOf(AdviceKind.class);
455         } else {
456             types = EnumSet.noneOf(AdviceKind.class);
457             types.addAll(Arrays.asList(ofType));
458         }
459         return getAdvice(types);
460     }
461
462     /* (non-Javadoc)
463      * @see org.aspectj.lang.reflect.AjType#getDeclaredAdvice(org.aspectj.lang.reflect.AdviceType)
464      */

465     private Advice[] getDeclaredAdvice(Set JavaDoc ofAdviceTypes) {
466         if (declaredAdvice == null) initDeclaredAdvice();
467         List JavaDoc<Advice> adviceList = new ArrayList JavaDoc<Advice>();
468         for (Advice a : declaredAdvice) {
469             if (ofAdviceTypes.contains(a.getKind())) adviceList.add(a);
470         }
471         Advice[] ret = new Advice[adviceList.size()];
472         adviceList.toArray(ret);
473         return ret;
474     }
475
476     private void initDeclaredAdvice() {
477         Method JavaDoc[] methods = clazz.getDeclaredMethods();
478         List JavaDoc<Advice> adviceList = new ArrayList JavaDoc<Advice>();
479         for (Method JavaDoc method : methods) {
480             Advice advice = asAdvice(method);
481             if (advice != null) adviceList.add(advice);
482         }
483         declaredAdvice = new Advice[adviceList.size()];
484         adviceList.toArray(declaredAdvice);
485     }
486
487     /* (non-Javadoc)
488      * @see org.aspectj.lang.reflect.AjType#getDeclaredAdvice(org.aspectj.lang.reflect.AdviceType)
489      */

490     private Advice[] getAdvice(Set JavaDoc ofAdviceTypes) {
491         if (advice == null) initAdvice();
492         List JavaDoc<Advice> adviceList = new ArrayList JavaDoc<Advice>();
493         for (Advice a : advice) {
494             if (ofAdviceTypes.contains(a.getKind())) adviceList.add(a);
495         }
496         Advice[] ret = new Advice[adviceList.size()];
497         adviceList.toArray(ret);
498         return ret;
499     }
500
501     private void initAdvice() {
502         Method JavaDoc[] methods = clazz.getMethods();
503         List JavaDoc<Advice> adviceList = new ArrayList JavaDoc<Advice>();
504         for (Method JavaDoc method : methods) {
505             Advice advice = asAdvice(method);
506             if (advice != null) adviceList.add(advice);
507         }
508         advice = new Advice[adviceList.size()];
509         adviceList.toArray(advice);
510     }
511
512
513     public Advice getAdvice(String JavaDoc name) throws NoSuchAdviceException {
514         if (name.equals("")) throw new IllegalArgumentException JavaDoc("use getAdvice(AdviceType...) instead for un-named advice");
515         if (advice == null) initAdvice();
516         for (Advice a : advice) {
517             if (a.getName().equals(name)) return a;
518         }
519         throw new NoSuchAdviceException(name);
520     }
521     
522     public Advice getDeclaredAdvice(String JavaDoc name) throws NoSuchAdviceException {
523         if (name.equals("")) throw new IllegalArgumentException JavaDoc("use getAdvice(AdviceType...) instead for un-named advice");
524         if (declaredAdvice == null) initDeclaredAdvice();
525         for (Advice a : declaredAdvice) {
526             if (a.getName().equals(name)) return a;
527         }
528         throw new NoSuchAdviceException(name);
529     }
530     
531     private Advice asAdvice(Method JavaDoc method) {
532         if (method.getAnnotations().length == 0) return null;
533         Before beforeAnn = method.getAnnotation(Before.class);
534         if (beforeAnn != null) return new AdviceImpl(method,beforeAnn.value(),AdviceKind.BEFORE);
535         After afterAnn = method.getAnnotation(After.class);
536         if (afterAnn != null) return new AdviceImpl(method,afterAnn.value(),AdviceKind.AFTER);
537         AfterReturning afterReturningAnn = method.getAnnotation(AfterReturning.class);
538         if (afterReturningAnn != null) {
539             String JavaDoc pcExpr = afterReturningAnn.pointcut();
540             if (pcExpr.equals("")) pcExpr = afterReturningAnn.value();
541             return new AdviceImpl(method,pcExpr,AdviceKind.AFTER_RETURNING,afterReturningAnn.returning());
542         }
543         AfterThrowing afterThrowingAnn = method.getAnnotation(AfterThrowing.class);
544         if (afterThrowingAnn != null) {
545             String JavaDoc pcExpr = afterThrowingAnn.pointcut();
546             if (pcExpr == null) pcExpr = afterThrowingAnn.value();
547             return new AdviceImpl(method,pcExpr,AdviceKind.AFTER_THROWING,afterThrowingAnn.throwing());
548         }
549         Around aroundAnn = method.getAnnotation(Around.class);
550         if (aroundAnn != null) return new AdviceImpl(method,aroundAnn.value(),AdviceKind.AROUND);
551         return null;
552     }
553     
554     /* (non-Javadoc)
555      * @see org.aspectj.lang.reflect.AjType#getDeclaredITDMethod(java.lang.String, java.lang.Class, java.lang.Class...)
556      */

557     public InterTypeMethodDeclaration getDeclaredITDMethod(String JavaDoc name,
558             AjType<?> target, AjType<?>... parameterTypes) throws NoSuchMethodException JavaDoc {
559         InterTypeMethodDeclaration[] itdms = getDeclaredITDMethods();
560         outer: for (InterTypeMethodDeclaration itdm : itdms) {
561             try {
562                 if (!itdm.getName().equals(name)) continue;
563                 AjType<?> itdTarget = itdm.getTargetType();
564                 if (itdTarget.equals(target)) {
565                     AjType<?>[] ptypes = itdm.getParameterTypes();
566                     if (ptypes.length == parameterTypes.length) {
567                         for (int i = 0; i < ptypes.length; i++) {
568                             if (!ptypes[i].equals(parameterTypes[i]))
569                                 continue outer;
570                         }
571                         return itdm;
572                     }
573                 }
574             } catch (ClassNotFoundException JavaDoc cnf) {
575                 // just move on to the next one
576
}
577         }
578         throw new NoSuchMethodException JavaDoc(name);
579     }
580
581     /* (non-Javadoc)
582      * @see org.aspectj.lang.reflect.AjType#getDeclaredITDMethods()
583      */

584     public InterTypeMethodDeclaration[] getDeclaredITDMethods() {
585         if (this.declaredITDMethods == null) {
586             List JavaDoc<InterTypeMethodDeclaration> itdms = new ArrayList JavaDoc<InterTypeMethodDeclaration>();
587             Method JavaDoc[] baseMethods = clazz.getDeclaredMethods();
588             for (Method JavaDoc m : baseMethods) {
589                 if (!m.getName().contains("ajc$interMethodDispatch1$")) continue;
590                 if (m.isAnnotationPresent(ajcITD.class)) {
591                     ajcITD ann = m.getAnnotation(ajcITD.class);
592                     InterTypeMethodDeclaration itdm =
593                         new InterTypeMethodDeclarationImpl(
594                                 this,ann.targetType(),ann.modifiers(),
595                                 ann.name(),m);
596                     itdms.add(itdm);
597                 }
598             }
599             addAnnotationStyleITDMethods(itdms,false);
600             this.declaredITDMethods = new InterTypeMethodDeclaration[itdms.size()];
601             itdms.toArray(this.declaredITDMethods);
602         }
603         return this.declaredITDMethods;
604     }
605
606     /* (non-Javadoc)
607      * @see org.aspectj.lang.reflect.AjType#getITDMethod(java.lang.String, java.lang.Class, java.lang.Class...)
608      */

609     public InterTypeMethodDeclaration getITDMethod(String JavaDoc name, AjType<?> target,
610             AjType<?>... parameterTypes)
611     throws NoSuchMethodException JavaDoc {
612         InterTypeMethodDeclaration[] itdms = getITDMethods();
613         outer: for (InterTypeMethodDeclaration itdm : itdms) {
614             try {
615                 if (!itdm.getName().equals(name)) continue;
616                 AjType<?> itdTarget = itdm.getTargetType();
617                 if (itdTarget.equals(target)) {
618                     AjType<?>[] ptypes = itdm.getParameterTypes();
619                     if (ptypes.length == parameterTypes.length) {
620                         for (int i = 0; i < ptypes.length; i++) {
621                             if (!ptypes[i].equals(parameterTypes[i]))
622                                 continue outer;
623                         }
624                         return itdm;
625                     }
626                 }
627             } catch (ClassNotFoundException JavaDoc cnf) {
628                 // just move on to the next one
629
}
630         }
631         throw new NoSuchMethodException JavaDoc(name);
632     }
633
634     /* (non-Javadoc)
635      * @see org.aspectj.lang.reflect.AjType#getITDMethods()
636      */

637     public InterTypeMethodDeclaration[] getITDMethods() {
638         if (this.itdMethods == null) {
639             List JavaDoc<InterTypeMethodDeclaration> itdms = new ArrayList JavaDoc<InterTypeMethodDeclaration>();
640             Method JavaDoc[] baseMethods = clazz.getDeclaredMethods();
641             for (Method JavaDoc m : baseMethods) {
642                 if (!m.getName().contains("ajc$interMethod$")) continue;
643                 if (m.isAnnotationPresent(ajcITD.class)) {
644                     ajcITD ann = m.getAnnotation(ajcITD.class);
645                     if (!Modifier.isPublic(ann.modifiers())) continue;
646                     InterTypeMethodDeclaration itdm =
647                         new InterTypeMethodDeclarationImpl(
648                                 this,ann.targetType(),ann.modifiers(),
649                                 ann.name(),m);
650                     itdms.add(itdm);
651                 }
652             }
653             addAnnotationStyleITDMethods(itdms,true);
654             this.itdMethods = new InterTypeMethodDeclaration[itdms.size()];
655             itdms.toArray(this.itdMethods);
656         }
657         return this.itdMethods;
658     }
659     
660     private void addAnnotationStyleITDMethods(List JavaDoc<InterTypeMethodDeclaration> toList, boolean publicOnly) {
661         if (isAspect()) {
662             for (Field JavaDoc f : clazz.getDeclaredFields()) {
663                 if (!f.getType().isInterface()) continue;
664                 if (f.isAnnotationPresent(org.aspectj.lang.annotation.DeclareParents.class)) {
665                     Class JavaDoc<org.aspectj.lang.annotation.DeclareParents> decPAnnClass = org.aspectj.lang.annotation.DeclareParents.class;
666                     org.aspectj.lang.annotation.DeclareParents decPAnn = f.getAnnotation(decPAnnClass);
667                     if (decPAnn.defaultImpl() == decPAnnClass) continue; // doesn't contribute members...
668
for (Method JavaDoc itdM : f.getType().getDeclaredMethods()) {
669                         if (!Modifier.isPublic(itdM.getModifiers()) && publicOnly) continue;
670                         InterTypeMethodDeclaration itdm = new InterTypeMethodDeclarationImpl(
671                                     this, AjTypeSystem.getAjType(f.getType()), itdM,
672                                     Modifier.PUBLIC
673                         );
674                         toList.add(itdm);
675                     }
676                 }
677             }
678         }
679     }
680
681     private void addAnnotationStyleITDFields(List JavaDoc<InterTypeFieldDeclaration> toList, boolean publicOnly) {
682         //AV: I think it is meaningless
683
//@AJ decp is interface driven ie no field
684
return;
685     }
686
687     /* (non-Javadoc)
688      * @see org.aspectj.lang.reflect.AjType#getDeclaredITDConstructor(java.lang.Class, java.lang.Class...)
689      */

690     public InterTypeConstructorDeclaration getDeclaredITDConstructor(
691             AjType<?> target, AjType<?>... parameterTypes) throws NoSuchMethodException JavaDoc {
692         InterTypeConstructorDeclaration[] itdcs = getDeclaredITDConstructors();
693         outer: for (InterTypeConstructorDeclaration itdc : itdcs) {
694             try {
695                 AjType<?> itdTarget = itdc.getTargetType();
696                 if (itdTarget.equals(target)) {
697                     AjType<?>[] ptypes = itdc.getParameterTypes();
698                     if (ptypes.length == parameterTypes.length) {
699                         for (int i = 0; i < ptypes.length; i++) {
700                             if (!ptypes[i].equals(parameterTypes[i]))
701                                 continue outer;
702                         }
703                         return itdc;
704                     }
705                 }
706             } catch (ClassNotFoundException JavaDoc cnf) {
707                 // just move on to the next one
708
}
709         }
710         throw new NoSuchMethodException JavaDoc();
711     }
712
713     /* (non-Javadoc)
714      * @see org.aspectj.lang.reflect.AjType#getDeclaredITDConstructors()
715      */

716     public InterTypeConstructorDeclaration[] getDeclaredITDConstructors() {
717         if (this.declaredITDCons == null) {
718             List JavaDoc<InterTypeConstructorDeclaration> itdcs = new ArrayList JavaDoc<InterTypeConstructorDeclaration>();
719             Method JavaDoc[] baseMethods = clazz.getDeclaredMethods();
720             for (Method JavaDoc m : baseMethods) {
721                 if (!m.getName().contains("ajc$postInterConstructor")) continue;
722                 if (m.isAnnotationPresent(ajcITD.class)) {
723                     ajcITD ann = m.getAnnotation(ajcITD.class);
724                     InterTypeConstructorDeclaration itdc =
725                         new InterTypeConstructorDeclarationImpl(this,ann.targetType(),ann.modifiers(),m);
726                     itdcs.add(itdc);
727                 }
728             }
729             this.declaredITDCons = new InterTypeConstructorDeclaration[itdcs.size()];
730             itdcs.toArray(this.declaredITDCons);
731         }
732         return this.declaredITDCons;
733     }
734
735     /* (non-Javadoc)
736      * @see org.aspectj.lang.reflect.AjType#getITDConstructor(java.lang.Class, java.lang.Class...)
737      */

738     public InterTypeConstructorDeclaration getITDConstructor(AjType<?> target,
739             AjType<?>... parameterTypes) throws NoSuchMethodException JavaDoc {
740         InterTypeConstructorDeclaration[] itdcs = getITDConstructors();
741         outer: for (InterTypeConstructorDeclaration itdc : itdcs) {
742             try {
743                 AjType<?> itdTarget = itdc.getTargetType();
744                 if (itdTarget.equals(target)) {
745                     AjType<?>[] ptypes = itdc.getParameterTypes();
746                     if (ptypes.length == parameterTypes.length) {
747                         for (int i = 0; i < ptypes.length; i++) {
748                             if (!ptypes[i].equals(parameterTypes[i]))
749                                 continue outer;
750                         }
751                         return itdc;
752                     }
753                 }
754             } catch (ClassNotFoundException JavaDoc cnf) {
755                 // just move on to the next one
756
}
757         }
758         throw new NoSuchMethodException JavaDoc();
759     }
760
761     /* (non-Javadoc)
762      * @see org.aspectj.lang.reflect.AjType#getITDConstructors()
763      */

764     public InterTypeConstructorDeclaration[] getITDConstructors() {
765         if (this.itdCons == null) {
766             List JavaDoc<InterTypeConstructorDeclaration> itdcs = new ArrayList JavaDoc<InterTypeConstructorDeclaration>();
767             Method JavaDoc[] baseMethods = clazz.getMethods();
768             for (Method JavaDoc m : baseMethods) {
769                 if (!m.getName().contains("ajc$postInterConstructor")) continue;
770                 if (m.isAnnotationPresent(ajcITD.class)) {
771                     ajcITD ann = m.getAnnotation(ajcITD.class);
772                     if (!Modifier.isPublic(ann.modifiers())) continue;
773                     InterTypeConstructorDeclaration itdc =
774                         new InterTypeConstructorDeclarationImpl(this,ann.targetType(),ann.modifiers(),m);
775                     itdcs.add(itdc);
776                 }
777             }
778             this.itdCons = new InterTypeConstructorDeclaration[itdcs.size()];
779             itdcs.toArray(this.itdCons);
780         }
781         return this.itdCons; }
782
783     /* (non-Javadoc)
784      * @see org.aspectj.lang.reflect.AjType#getDeclaredITDField(java.lang.String, java.lang.Class)
785      */

786     public InterTypeFieldDeclaration getDeclaredITDField(String JavaDoc name,
787             AjType<?> target) throws NoSuchFieldException JavaDoc {
788         InterTypeFieldDeclaration[] itdfs = getDeclaredITDFields();
789         for (InterTypeFieldDeclaration itdf : itdfs) {
790             if (itdf.getName().equals(name)) {
791                 try {
792                     AjType<?> itdTarget = itdf.getTargetType();
793                     if (itdTarget.equals(target)) return itdf;
794                 } catch (ClassNotFoundException JavaDoc cnfEx) {
795                     // move on to next field
796
}
797             }
798         }
799         throw new NoSuchFieldException JavaDoc(name);
800     }
801
802     /* (non-Javadoc)
803      * @see org.aspectj.lang.reflect.AjType#getDeclaredITDFields()
804      */

805     public InterTypeFieldDeclaration[] getDeclaredITDFields() {
806         List JavaDoc<InterTypeFieldDeclaration> itdfs = new ArrayList JavaDoc<InterTypeFieldDeclaration>();
807         if (this.declaredITDFields == null) {
808             Method JavaDoc[] baseMethods = clazz.getDeclaredMethods();
809             for(Method JavaDoc m : baseMethods) {
810                 if (m.isAnnotationPresent(ajcITD.class)) {
811                     if (!m.getName().contains("ajc$interFieldInit")) continue;
812                     ajcITD ann = m.getAnnotation(ajcITD.class);
813                     String JavaDoc interFieldInitMethodName = m.getName();
814                     String JavaDoc interFieldGetDispatchMethodName =
815                         interFieldInitMethodName.replace("FieldInit","FieldGetDispatch");
816                     try {
817                         Method JavaDoc dispatch = clazz.getDeclaredMethod(interFieldGetDispatchMethodName, m.getParameterTypes());
818                         InterTypeFieldDeclaration itdf = new InterTypeFieldDeclarationImpl(
819                                 this,ann.targetType(),ann.modifiers(),ann.name(),
820                                 AjTypeSystem.getAjType(dispatch.getReturnType()),
821                                 dispatch.getGenericReturnType());
822                         itdfs.add(itdf);
823                     } catch (NoSuchMethodException JavaDoc nsmEx) {
824                         throw new IllegalStateException JavaDoc("Can't find field get dispatch method for " + m.getName());
825                     }
826                 }
827             }
828             addAnnotationStyleITDFields(itdfs, false);
829             this.declaredITDFields = new InterTypeFieldDeclaration[itdfs.size()];
830             itdfs.toArray(this.declaredITDFields);
831         }
832         return this.declaredITDFields;
833     }
834
835     /* (non-Javadoc)
836      * @see org.aspectj.lang.reflect.AjType#getITDField(java.lang.String, java.lang.Class)
837      */

838     public InterTypeFieldDeclaration getITDField(String JavaDoc name, AjType<?> target)
839     throws NoSuchFieldException JavaDoc {
840         InterTypeFieldDeclaration[] itdfs = getITDFields();
841         for (InterTypeFieldDeclaration itdf : itdfs) {
842             if (itdf.getName().equals(name)) {
843                 try {
844                     AjType<?> itdTarget = itdf.getTargetType();
845                     if (itdTarget.equals(target)) return itdf;
846                 } catch (ClassNotFoundException JavaDoc cnfEx) {
847                     // move on to next field
848
}
849             }
850         }
851         throw new NoSuchFieldException JavaDoc(name);
852     }
853
854     /* (non-Javadoc)
855      * @see org.aspectj.lang.reflect.AjType#getITDFields()
856      */

857     public InterTypeFieldDeclaration[] getITDFields() {
858         List JavaDoc<InterTypeFieldDeclaration> itdfs = new ArrayList JavaDoc<InterTypeFieldDeclaration>();
859         if (this.itdFields == null) {
860             Method JavaDoc[] baseMethods = clazz.getMethods();
861             for(Method JavaDoc m : baseMethods) {
862                 if (m.isAnnotationPresent(ajcITD.class)) {
863                     ajcITD ann = m.getAnnotation(ajcITD.class);
864                     if (!m.getName().contains("ajc$interFieldInit")) continue;
865                     if (!Modifier.isPublic(ann.modifiers())) continue;
866                     String JavaDoc interFieldInitMethodName = m.getName();
867                     String JavaDoc interFieldGetDispatchMethodName =
868                         interFieldInitMethodName.replace("FieldInit","FieldGetDispatch");
869                     try {
870                         Method JavaDoc dispatch = m.getDeclaringClass().getDeclaredMethod(interFieldGetDispatchMethodName, m.getParameterTypes());
871                         InterTypeFieldDeclaration itdf = new InterTypeFieldDeclarationImpl(
872                                 this,ann.targetType(),ann.modifiers(),ann.name(),
873                                 AjTypeSystem.getAjType(dispatch.getReturnType()),
874                                 dispatch.getGenericReturnType());
875                         itdfs.add(itdf);
876                     } catch (NoSuchMethodException JavaDoc nsmEx) {
877                         throw new IllegalStateException JavaDoc("Can't find field get dispatch method for " + m.getName());
878                     }
879                 }
880             }
881             addAnnotationStyleITDFields(itdfs, true);
882             this.itdFields = new InterTypeFieldDeclaration[itdfs.size()];
883             itdfs.toArray(this.itdFields);
884         }
885         return this.itdFields;
886     }
887
888     /* (non-Javadoc)
889      * @see org.aspectj.lang.reflect.AjType#getDeclareErrorOrWarnings()
890      */

891     public DeclareErrorOrWarning[] getDeclareErrorOrWarnings() {
892         List JavaDoc<DeclareErrorOrWarning> deows = new ArrayList JavaDoc<DeclareErrorOrWarning>();
893         for (Field JavaDoc field : clazz.getDeclaredFields()) {
894             try {
895                 if (field.isAnnotationPresent(DeclareWarning.class)) {
896                      DeclareWarning dw = field.getAnnotation(DeclareWarning.class);
897                      if (Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers())) {
898                          String JavaDoc message = (String JavaDoc) field.get(null);
899                          DeclareErrorOrWarningImpl deow = new DeclareErrorOrWarningImpl(dw.value(),message,false,this);
900                          deows.add(deow);
901                      }
902                 } else if (field.isAnnotationPresent(DeclareError.class)) {
903                      DeclareError de = field.getAnnotation(DeclareError.class);
904                      if (Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers())) {
905                          String JavaDoc message = (String JavaDoc) field.get(null);
906                          DeclareErrorOrWarningImpl deow = new DeclareErrorOrWarningImpl(de.value(),message,true,this);
907                          deows.add(deow);
908                      }
909                 }
910             } catch (IllegalArgumentException JavaDoc e) {
911                 // just move on to the next field
912
} catch (IllegalAccessException JavaDoc e) {
913                 // just move on to the next field
914
}
915         }
916         for (Method JavaDoc method : clazz.getDeclaredMethods()) {
917             if (method.isAnnotationPresent(ajcDeclareEoW.class)) {
918                 ajcDeclareEoW deowAnn = method.getAnnotation(ajcDeclareEoW.class);
919                 DeclareErrorOrWarning deow = new DeclareErrorOrWarningImpl(deowAnn.pointcut(),deowAnn.message(),deowAnn.isError(),this);
920                 deows.add(deow);
921             }
922         }
923         DeclareErrorOrWarning[] ret = new DeclareErrorOrWarning[deows.size()];
924         deows.toArray(ret);
925         return ret;
926     }
927
928     /* (non-Javadoc)
929      * @see org.aspectj.lang.reflect.AjType#getDeclareParents()
930      */

931     public DeclareParents[] getDeclareParents() {
932         List JavaDoc<DeclareParents> decps = new ArrayList JavaDoc<DeclareParents>();
933         for (Method JavaDoc method : clazz.getDeclaredMethods()) {
934             if (method.isAnnotationPresent(ajcDeclareParents.class)) {
935                 ajcDeclareParents decPAnn = method.getAnnotation(ajcDeclareParents.class);
936                 DeclareParentsImpl decp = new DeclareParentsImpl(
937                         decPAnn.targetTypePattern(),
938                         decPAnn.parentTypes(),
939                         decPAnn.isExtends(),
940                         this
941                         );
942                 decps.add(decp);
943             }
944         }
945         addAnnotationStyleDeclareParents(decps);
946         if (getSupertype().isAspect()) {
947             decps.addAll(Arrays.asList(getSupertype().getDeclareParents()));
948         }
949         DeclareParents[] ret = new DeclareParents[decps.size()];
950         decps.toArray(ret);
951         return ret;
952     }
953     
954     private void addAnnotationStyleDeclareParents(List JavaDoc<DeclareParents> toList) {
955         for (Field JavaDoc f : clazz.getDeclaredFields()) {
956             if (f.isAnnotationPresent(org.aspectj.lang.annotation.DeclareParents.class)) {
957                 if (!f.getType().isInterface()) continue;
958                 org.aspectj.lang.annotation.DeclareParents ann = f.getAnnotation(org.aspectj.lang.annotation.DeclareParents.class);
959                 String JavaDoc parentType = f.getType().getName();
960                 DeclareParentsImpl decp = new DeclareParentsImpl(
961                         ann.value(),
962                         parentType,
963                         false,
964                         this
965                 );
966                 toList.add(decp);
967             }
968         }
969     }
970
971     /* (non-Javadoc)
972      * @see org.aspectj.lang.reflect.AjType#getDeclareSofts()
973      */

974     public DeclareSoft[] getDeclareSofts() {
975         List JavaDoc<DeclareSoft> decs = new ArrayList JavaDoc<DeclareSoft>();
976         for (Method JavaDoc method : clazz.getDeclaredMethods()) {
977             if (method.isAnnotationPresent(ajcDeclareSoft.class)) {
978                 ajcDeclareSoft decSAnn = method.getAnnotation(ajcDeclareSoft.class);
979                 DeclareSoftImpl ds = new DeclareSoftImpl(
980                         this,
981                         decSAnn.pointcut(),
982                         decSAnn.exceptionType()
983                         );
984                 decs.add(ds);
985             }
986         }
987         if (getSupertype().isAspect()) {
988             decs.addAll(Arrays.asList(getSupertype().getDeclareSofts()));
989         }
990         DeclareSoft[] ret = new DeclareSoft[decs.size()];
991         decs.toArray(ret);
992         return ret;
993     }
994
995     /* (non-Javadoc)
996      * @see org.aspectj.lang.reflect.AjType#getDeclareAnnotations()
997      */

998     public DeclareAnnotation[] getDeclareAnnotations() {
999         List JavaDoc<DeclareAnnotation> decAs = new ArrayList JavaDoc<DeclareAnnotation>();
1000        for (Method JavaDoc method : clazz.getDeclaredMethods()) {
1001            if (method.isAnnotationPresent(ajcDeclareAnnotation.class)) {
1002                ajcDeclareAnnotation decAnn = method.getAnnotation(ajcDeclareAnnotation.class);
1003                // the target annotation is on this method...
1004
Annotation JavaDoc targetAnnotation = null;
1005                Annotation JavaDoc[] anns = method.getAnnotations();
1006                for (Annotation JavaDoc ann: anns) {
1007                    if (ann.annotationType() != ajcDeclareAnnotation.class) {
1008                        // this must be the one...
1009
targetAnnotation = ann;
1010                        break;
1011                    }
1012                }
1013                DeclareAnnotationImpl da = new DeclareAnnotationImpl(
1014                        this,
1015                        decAnn.kind(),
1016                        decAnn.pattern(),
1017                        targetAnnotation,
1018                        decAnn.annotation()
1019                        );
1020                decAs.add(da);
1021            }
1022        }
1023        if (getSupertype().isAspect()) {
1024            decAs.addAll(Arrays.asList(getSupertype().getDeclareAnnotations()));
1025        }
1026        DeclareAnnotation[] ret = new DeclareAnnotation[decAs.size()];
1027        decAs.toArray(ret);
1028        return ret;
1029    }
1030
1031    /* (non-Javadoc)
1032     * @see org.aspectj.lang.reflect.AjType#getDeclarePrecedence()
1033     */

1034    public DeclarePrecedence[] getDeclarePrecedence() {
1035        List JavaDoc<DeclarePrecedence> decps = new ArrayList JavaDoc<DeclarePrecedence>();
1036        
1037        // @AspectJ Style
1038
if (clazz.isAnnotationPresent(org.aspectj.lang.annotation.DeclarePrecedence.class)) {
1039            org.aspectj.lang.annotation.DeclarePrecedence ann =
1040                clazz.getAnnotation(org.aspectj.lang.annotation.DeclarePrecedence.class);
1041            DeclarePrecedenceImpl decp = new DeclarePrecedenceImpl(
1042                    ann.value(),
1043                    this
1044                    );
1045            decps.add(decp);
1046        }
1047        
1048        // annotated code-style
1049
for (Method JavaDoc method : clazz.getDeclaredMethods()) {
1050            if (method.isAnnotationPresent(ajcDeclarePrecedence.class)) {
1051                ajcDeclarePrecedence decPAnn = method.getAnnotation(ajcDeclarePrecedence.class);
1052                DeclarePrecedenceImpl decp = new DeclarePrecedenceImpl(
1053                        decPAnn.value(),
1054                        this
1055                        );
1056                decps.add(decp);
1057            }
1058        }
1059        if (getSupertype().isAspect()) {
1060            decps.addAll(Arrays.asList(getSupertype().getDeclarePrecedence()));
1061        }
1062        DeclarePrecedence[] ret = new DeclarePrecedence[decps.size()];
1063        decps.toArray(ret);
1064        return ret;
1065    }
1066
1067    /* (non-Javadoc)
1068     * @see org.aspectj.lang.reflect.AjType#getEnumConstants()
1069     */

1070    public T[] getEnumConstants() {
1071        return clazz.getEnumConstants();
1072    }
1073
1074    /* (non-Javadoc)
1075     * @see org.aspectj.lang.reflect.AjType#getTypeParameters()
1076     */

1077    public TypeVariable JavaDoc<Class JavaDoc<T>>[] getTypeParameters() {
1078        return clazz.getTypeParameters();
1079    }
1080
1081    /* (non-Javadoc)
1082     * @see org.aspectj.lang.reflect.AjType#isEnum()
1083     */

1084    public boolean isEnum() {
1085        return clazz.isEnum();
1086    }
1087
1088    /* (non-Javadoc)
1089     * @see org.aspectj.lang.reflect.AjType#isInstance(java.lang.Object)
1090     */

1091    public boolean isInstance(Object JavaDoc o) {
1092        return clazz.isInstance(o);
1093    }
1094
1095    /* (non-Javadoc)
1096     * @see org.aspectj.lang.reflect.AjType#isInterface()
1097     */

1098    public boolean isInterface() {
1099        return clazz.isInterface();
1100    }
1101
1102    /* (non-Javadoc)
1103     * @see org.aspectj.lang.reflect.AjType#isLocalClass()
1104     */

1105    public boolean isLocalClass() {
1106        return clazz.isLocalClass() && !isAspect();
1107    }
1108
1109    /* (non-Javadoc)
1110     * @see org.aspectj.lang.reflect.AjType#isMemberClass()
1111     */

1112    public boolean isMemberClass() {
1113        return clazz.isMemberClass() && !isAspect();
1114    }
1115
1116    /* (non-Javadoc)
1117     * @see org.aspectj.lang.reflect.AjType#isArray()
1118     */

1119    public boolean isArray() {
1120        return clazz.isArray();
1121    }
1122
1123    /* (non-Javadoc)
1124     * @see org.aspectj.lang.reflect.AjType#isPrimitive()
1125     */

1126    public boolean isPrimitive() {
1127        return clazz.isPrimitive();
1128    }
1129
1130    /* (non-Javadoc)
1131     * @see org.aspectj.lang.reflect.AjType#isAspect()
1132     */

1133    public boolean isAspect() {
1134        return clazz.getAnnotation(Aspect.class) != null;
1135    }
1136
1137    /* (non-Javadoc)
1138     * @see org.aspectj.lang.reflect.AjType#isMemberAspect()
1139     */

1140    public boolean isMemberAspect() {
1141        return clazz.isMemberClass() && isAspect();
1142    }
1143
1144    public boolean isPrivileged() {
1145        return isAspect() && clazz.isAnnotationPresent(ajcPrivileged.class);
1146    }
1147    
1148    @Override JavaDoc
1149    public boolean equals(Object JavaDoc obj) {
1150        if (!(obj instanceof AjTypeImpl)) return false;
1151        AjTypeImpl other = (AjTypeImpl) obj;
1152        return other.clazz.equals(clazz);
1153    }
1154    
1155    @Override JavaDoc
1156    public int hashCode() {
1157        return clazz.hashCode();
1158    }
1159    
1160    private AjType<?>[] toAjTypeArray(Class JavaDoc<?>[] classes) {
1161        AjType<?>[] ajtypes = new AjType<?>[classes.length];
1162        for (int i = 0; i < ajtypes.length; i++) {
1163            ajtypes[i] = AjTypeSystem.getAjType(classes[i]);
1164        }
1165        return ajtypes;
1166    }
1167    
1168    private Class JavaDoc<?>[] toClassArray(AjType<?>[] ajTypes) {
1169        Class JavaDoc<?>[] classes = new Class JavaDoc<?>[ajTypes.length];
1170        for (int i = 0; i < classes.length; i++) {
1171            classes[i] = ajTypes[i].getJavaClass();
1172        }
1173        return classes;
1174    }
1175    
1176    public String JavaDoc toString() { return getName(); }
1177
1178}
1179
Popular Tags