You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AjTypeImpl.java 37KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  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. import java.lang.annotation.Annotation;
  14. import java.lang.reflect.Constructor;
  15. import java.lang.reflect.Field;
  16. import java.lang.reflect.Method;
  17. import java.lang.reflect.Modifier;
  18. import java.lang.reflect.Type;
  19. import java.lang.reflect.TypeVariable;
  20. import java.util.ArrayList;
  21. import java.util.Arrays;
  22. import java.util.EnumSet;
  23. import java.util.List;
  24. import java.util.Set;
  25. import org.aspectj.internal.lang.annotation.ajcDeclareAnnotation;
  26. import org.aspectj.internal.lang.annotation.ajcDeclareEoW;
  27. import org.aspectj.internal.lang.annotation.ajcDeclareParents;
  28. import org.aspectj.internal.lang.annotation.ajcDeclarePrecedence;
  29. import org.aspectj.internal.lang.annotation.ajcDeclareSoft;
  30. import org.aspectj.internal.lang.annotation.ajcITD;
  31. import org.aspectj.internal.lang.annotation.ajcPrivileged;
  32. import org.aspectj.lang.annotation.After;
  33. import org.aspectj.lang.annotation.AfterReturning;
  34. import org.aspectj.lang.annotation.AfterThrowing;
  35. import org.aspectj.lang.annotation.Around;
  36. import org.aspectj.lang.annotation.Aspect;
  37. import org.aspectj.lang.annotation.Before;
  38. import org.aspectj.lang.annotation.DeclareError;
  39. import org.aspectj.lang.annotation.DeclareWarning;
  40. import org.aspectj.lang.reflect.Advice;
  41. import org.aspectj.lang.reflect.AdviceKind;
  42. import org.aspectj.lang.reflect.AjType;
  43. import org.aspectj.lang.reflect.AjTypeSystem;
  44. import org.aspectj.lang.reflect.DeclareAnnotation;
  45. import org.aspectj.lang.reflect.DeclareErrorOrWarning;
  46. import org.aspectj.lang.reflect.DeclareParents;
  47. import org.aspectj.lang.reflect.DeclarePrecedence;
  48. import org.aspectj.lang.reflect.DeclareSoft;
  49. import org.aspectj.lang.reflect.InterTypeConstructorDeclaration;
  50. import org.aspectj.lang.reflect.InterTypeFieldDeclaration;
  51. import org.aspectj.lang.reflect.InterTypeMethodDeclaration;
  52. import org.aspectj.lang.reflect.NoSuchAdviceException;
  53. import org.aspectj.lang.reflect.NoSuchPointcutException;
  54. import org.aspectj.lang.reflect.PerClause;
  55. import org.aspectj.lang.reflect.PerClauseKind;
  56. import org.aspectj.lang.reflect.Pointcut;
  57. /**
  58. * @author colyer
  59. *
  60. */
  61. public class AjTypeImpl<T> implements AjType<T> {
  62. private static final String ajcMagic = "ajc$";
  63. private Class<T> clazz;
  64. private Pointcut[] declaredPointcuts = null;
  65. private Pointcut[] pointcuts = null;
  66. private Advice[] declaredAdvice = null;
  67. private Advice[] advice = null;
  68. private InterTypeMethodDeclaration[] declaredITDMethods = null;
  69. private InterTypeMethodDeclaration[] itdMethods = null;
  70. private InterTypeFieldDeclaration[] declaredITDFields = null;
  71. private InterTypeFieldDeclaration[] itdFields = null;
  72. private InterTypeConstructorDeclaration[] itdCons = null;
  73. private InterTypeConstructorDeclaration[] declaredITDCons = null;
  74. public AjTypeImpl(Class<T> fromClass) {
  75. this.clazz = fromClass;
  76. }
  77. /* (non-Javadoc)
  78. * @see org.aspectj.lang.reflect.AjType#getName()
  79. */
  80. public String getName() {
  81. return clazz.getName();
  82. }
  83. /* (non-Javadoc)
  84. * @see org.aspectj.lang.reflect.AjType#getPackage()
  85. */
  86. public Package getPackage() {
  87. return clazz.getPackage();
  88. }
  89. /* (non-Javadoc)
  90. * @see org.aspectj.lang.reflect.AjType#getInterfaces()
  91. */
  92. public AjType<?>[] getInterfaces() {
  93. Class<?>[] baseInterfaces = clazz.getInterfaces();
  94. return toAjTypeArray(baseInterfaces);
  95. }
  96. /* (non-Javadoc)
  97. * @see org.aspectj.lang.reflect.AjType#getModifiers()
  98. */
  99. public int getModifiers() {
  100. return clazz.getModifiers();
  101. }
  102. public Class<T> getJavaClass() {
  103. return clazz;
  104. }
  105. /* (non-Javadoc)
  106. * @see org.aspectj.lang.reflect.AjType#getSupertype()
  107. */
  108. public AjType<? super T> getSupertype() {
  109. Class<? super T> superclass = clazz.getSuperclass();
  110. return superclass==null ? null : (AjType<? super T>) new AjTypeImpl(superclass);
  111. }
  112. /* (non-Javadoc)
  113. * @see org.aspectj.lang.reflect.AjType#getGenericSupertype()
  114. */
  115. public Type getGenericSupertype() {
  116. return clazz.getGenericSuperclass();
  117. }
  118. /* (non-Javadoc)
  119. * @see org.aspectj.lang.reflect.AjType#getEnclosingMethod()
  120. */
  121. public Method getEnclosingMethod() {
  122. return clazz.getEnclosingMethod();
  123. }
  124. /* (non-Javadoc)
  125. * @see org.aspectj.lang.reflect.AjType#getEnclosingConstructor()
  126. */
  127. public Constructor getEnclosingConstructor() {
  128. return clazz.getEnclosingConstructor();
  129. }
  130. /* (non-Javadoc)
  131. * @see org.aspectj.lang.reflect.AjType#getEnclosingType()
  132. */
  133. public AjType<?> getEnclosingType() {
  134. Class<?> enc = clazz.getEnclosingClass();
  135. return enc != null ? new AjTypeImpl(enc) : null;
  136. }
  137. /* (non-Javadoc)
  138. * @see org.aspectj.lang.reflect.AjType#getDeclaringType()
  139. */
  140. public AjType<?> getDeclaringType() {
  141. Class dec = clazz.getDeclaringClass();
  142. return dec != null ? new AjTypeImpl(dec) : null;
  143. }
  144. public PerClause getPerClause() {
  145. if (isAspect()) {
  146. Aspect aspectAnn = clazz.getAnnotation(Aspect.class);
  147. String perClause = aspectAnn.value();
  148. if (perClause.equals("")) {
  149. if (getSupertype().isAspect()) {
  150. return getSupertype().getPerClause();
  151. }
  152. return new PerClauseImpl(PerClauseKind.SINGLETON);
  153. } else if (perClause.startsWith("perthis(")) {
  154. return new PointcutBasedPerClauseImpl(PerClauseKind.PERTHIS,perClause.substring("perthis(".length(),perClause.length() - 1));
  155. } else if (perClause.startsWith("pertarget(")) {
  156. return new PointcutBasedPerClauseImpl(PerClauseKind.PERTARGET,perClause.substring("pertarget(".length(),perClause.length() - 1));
  157. } else if (perClause.startsWith("percflow(")) {
  158. return new PointcutBasedPerClauseImpl(PerClauseKind.PERCFLOW,perClause.substring("percflow(".length(),perClause.length() - 1));
  159. } else if (perClause.startsWith("percflowbelow(")) {
  160. return new PointcutBasedPerClauseImpl(PerClauseKind.PERCFLOWBELOW,perClause.substring("percflowbelow(".length(),perClause.length() - 1));
  161. } else if (perClause.startsWith("pertypewithin")) {
  162. return new TypePatternBasedPerClauseImpl(PerClauseKind.PERTYPEWITHIN,perClause.substring("pertypewithin(".length(),perClause.length() - 1));
  163. } else {
  164. throw new IllegalStateException("Per-clause not recognized: " + perClause);
  165. }
  166. } else {
  167. return null;
  168. }
  169. }
  170. /* (non-Javadoc)
  171. * @see org.aspectj.lang.reflect.AjType#isAnnotationPresent(java.lang.Class)
  172. */
  173. public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
  174. return clazz.isAnnotationPresent(annotationType);
  175. }
  176. public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
  177. return clazz.getAnnotation(annotationType);
  178. }
  179. /* (non-Javadoc)
  180. * @see org.aspectj.lang.reflect.AjType#getAnnotations()
  181. */
  182. public Annotation[] getAnnotations() {
  183. return clazz.getAnnotations();
  184. }
  185. /* (non-Javadoc)
  186. * @see org.aspectj.lang.reflect.AjType#getDeclaredAnnotations()
  187. */
  188. public Annotation[] getDeclaredAnnotations() {
  189. return clazz.getDeclaredAnnotations();
  190. }
  191. /* (non-Javadoc)
  192. * @see org.aspectj.lang.reflect.AjType#getAspects()
  193. */
  194. public AjType<?>[] getAjTypes() {
  195. Class[] classes = clazz.getClasses();
  196. return toAjTypeArray(classes);
  197. }
  198. /* (non-Javadoc)
  199. * @see org.aspectj.lang.reflect.AjType#getDeclaredAspects()
  200. */
  201. public AjType<?>[] getDeclaredAjTypes() {
  202. Class[] classes = clazz.getDeclaredClasses();
  203. return toAjTypeArray(classes);
  204. }
  205. /* (non-Javadoc)
  206. * @see org.aspectj.lang.reflect.AjType#getConstructor(java.lang.Class...)
  207. */
  208. public Constructor getConstructor(AjType<?>... parameterTypes) throws NoSuchMethodException {
  209. return clazz.getConstructor(toClassArray(parameterTypes));
  210. }
  211. /* (non-Javadoc)
  212. * @see org.aspectj.lang.reflect.AjType#getConstructors()
  213. */
  214. public Constructor[] getConstructors() {
  215. return clazz.getConstructors();
  216. }
  217. /* (non-Javadoc)
  218. * @see org.aspectj.lang.reflect.AjType#getDeclaredConstructor(java.lang.Class...)
  219. */
  220. public Constructor getDeclaredConstructor(AjType<?>... parameterTypes) throws NoSuchMethodException {
  221. return clazz.getDeclaredConstructor(toClassArray(parameterTypes));
  222. }
  223. /* (non-Javadoc)
  224. * @see org.aspectj.lang.reflect.AjType#getDeclaredConstructors()
  225. */
  226. public Constructor[] getDeclaredConstructors() {
  227. return clazz.getDeclaredConstructors();
  228. }
  229. /* (non-Javadoc)
  230. * @see org.aspectj.lang.reflect.AjType#getDeclaredField(java.lang.String)
  231. */
  232. public Field getDeclaredField(String name) throws NoSuchFieldException {
  233. Field f = clazz.getDeclaredField(name);
  234. if (f.getName().startsWith(ajcMagic)) throw new NoSuchFieldException(name);
  235. return f;
  236. }
  237. /* (non-Javadoc)
  238. * @see org.aspectj.lang.reflect.AjType#getDeclaredFields()
  239. */
  240. public Field[] getDeclaredFields() {
  241. Field[] fields = clazz.getDeclaredFields();
  242. List<Field> filteredFields = new ArrayList<Field>();
  243. for (Field field : fields)
  244. if (!field.getName().startsWith(ajcMagic)
  245. && !field.isAnnotationPresent(DeclareWarning.class)
  246. && !field.isAnnotationPresent(DeclareError.class)) {
  247. filteredFields.add(field);
  248. }
  249. Field[] ret = new Field[filteredFields.size()];
  250. filteredFields.toArray(ret);
  251. return ret;
  252. }
  253. /* (non-Javadoc)
  254. * @see org.aspectj.lang.reflect.AjType#getField(java.lang.String)
  255. */
  256. public Field getField(String name) throws NoSuchFieldException {
  257. Field f = clazz.getField(name);
  258. if (f.getName().startsWith(ajcMagic)) throw new NoSuchFieldException(name);
  259. return f;
  260. }
  261. /* (non-Javadoc)
  262. * @see org.aspectj.lang.reflect.AjType#getFields()
  263. */
  264. public Field[] getFields() {
  265. Field[] fields = clazz.getFields();
  266. List<Field> filteredFields = new ArrayList<Field>();
  267. for (Field field : fields)
  268. if (!field.getName().startsWith(ajcMagic)
  269. && !field.isAnnotationPresent(DeclareWarning.class)
  270. && !field.isAnnotationPresent(DeclareError.class)) {
  271. filteredFields.add(field);
  272. }
  273. Field[] ret = new Field[filteredFields.size()];
  274. filteredFields.toArray(ret);
  275. return ret;
  276. }
  277. /* (non-Javadoc)
  278. * @see org.aspectj.lang.reflect.AjType#getDeclaredMethod(java.lang.String, java.lang.Class...)
  279. */
  280. public Method getDeclaredMethod(String name, AjType<?>... parameterTypes) throws NoSuchMethodException {
  281. Method m = clazz.getDeclaredMethod(name,toClassArray(parameterTypes));
  282. if (!isReallyAMethod(m)) throw new NoSuchMethodException(name);
  283. return m;
  284. }
  285. /* (non-Javadoc)
  286. * @see org.aspectj.lang.reflect.AjType#getMethod(java.lang.String, java.lang.Class...)
  287. */
  288. public Method getMethod(String name, AjType<?>... parameterTypes) throws NoSuchMethodException {
  289. Method m = clazz.getMethod(name,toClassArray(parameterTypes));
  290. if (!isReallyAMethod(m)) throw new NoSuchMethodException(name);
  291. return m;
  292. }
  293. /* (non-Javadoc)
  294. * @see org.aspectj.lang.reflect.AjType#getDeclaredMethods()
  295. */
  296. public Method[] getDeclaredMethods() {
  297. Method[] methods = clazz.getDeclaredMethods();
  298. List<Method> filteredMethods = new ArrayList<Method>();
  299. for (Method method : methods) {
  300. if (isReallyAMethod(method)) filteredMethods.add(method);
  301. }
  302. Method[] ret = new Method[filteredMethods.size()];
  303. filteredMethods.toArray(ret);
  304. return ret;
  305. }
  306. /* (non-Javadoc)
  307. * @see org.aspectj.lang.reflect.AjType#getMethods()
  308. */
  309. public Method[] getMethods() {
  310. Method[] methods = clazz.getMethods();
  311. List<Method> filteredMethods = new ArrayList<Method>();
  312. for (Method method : methods) {
  313. if (isReallyAMethod(method)) filteredMethods.add(method);
  314. }
  315. Method[] ret = new Method[filteredMethods.size()];
  316. filteredMethods.toArray(ret);
  317. return ret;
  318. }
  319. private boolean isReallyAMethod(Method method) {
  320. if (method.getName().startsWith(ajcMagic)) return false;
  321. if (method.getAnnotations().length==0) return true;
  322. if (method.isAnnotationPresent(org.aspectj.lang.annotation.Pointcut.class)) return false;
  323. if (method.isAnnotationPresent(Before.class)) return false;
  324. if (method.isAnnotationPresent(After.class)) return false;
  325. if (method.isAnnotationPresent(AfterReturning.class)) return false;
  326. if (method.isAnnotationPresent(AfterThrowing.class)) return false;
  327. if (method.isAnnotationPresent(Around.class)) return false;
  328. return true;
  329. }
  330. /* (non-Javadoc)
  331. * @see org.aspectj.lang.reflect.AjType#getDeclaredPointcut(java.lang.String)
  332. */
  333. public Pointcut getDeclaredPointcut(String name) throws NoSuchPointcutException {
  334. Pointcut[] pcs = getDeclaredPointcuts();
  335. for (Pointcut pc : pcs)
  336. if (pc.getName().equals(name)) return pc;
  337. throw new NoSuchPointcutException(name);
  338. }
  339. /* (non-Javadoc)
  340. * @see org.aspectj.lang.reflect.AjType#getPointcut(java.lang.String)
  341. */
  342. public Pointcut getPointcut(String name) throws NoSuchPointcutException {
  343. Pointcut[] pcs = getPointcuts();
  344. for (Pointcut pc : pcs)
  345. if (pc.getName().equals(name)) return pc;
  346. throw new NoSuchPointcutException(name);
  347. }
  348. /* (non-Javadoc)
  349. * @see org.aspectj.lang.reflect.AjType#getDeclaredPointcuts()
  350. */
  351. public Pointcut[] getDeclaredPointcuts() {
  352. if (declaredPointcuts != null) return declaredPointcuts;
  353. List<Pointcut> pointcuts = new ArrayList<Pointcut>();
  354. Method[] methods = clazz.getDeclaredMethods();
  355. for (Method method : methods) {
  356. Pointcut pc = asPointcut(method);
  357. if (pc != null) pointcuts.add(pc);
  358. }
  359. Pointcut[] ret = new Pointcut[pointcuts.size()];
  360. pointcuts.toArray(ret);
  361. declaredPointcuts = ret;
  362. return ret;
  363. }
  364. /* (non-Javadoc)
  365. * @see org.aspectj.lang.reflect.AjType#getPointcuts()
  366. */
  367. public Pointcut[] getPointcuts() {
  368. if (pointcuts != null) return pointcuts;
  369. List<Pointcut> pcuts = new ArrayList<Pointcut>();
  370. Method[] methods = clazz.getMethods();
  371. for (Method method : methods) {
  372. Pointcut pc = asPointcut(method);
  373. if (pc != null) pcuts.add(pc);
  374. }
  375. Pointcut[] ret = new Pointcut[pcuts.size()];
  376. pcuts.toArray(ret);
  377. pointcuts = ret;
  378. return ret;
  379. }
  380. private Pointcut asPointcut(Method method) {
  381. org.aspectj.lang.annotation.Pointcut pcAnn = method.getAnnotation(org.aspectj.lang.annotation.Pointcut.class);
  382. if (pcAnn != null) {
  383. String name = method.getName();
  384. if (name.startsWith(ajcMagic)) {
  385. // extract real name
  386. int nameStart = name.indexOf("$$");
  387. name = name.substring(nameStart +2,name.length());
  388. int nextDollar = name.indexOf("$");
  389. if (nextDollar != -1) name = name.substring(0,nextDollar);
  390. }
  391. return new PointcutImpl(name,pcAnn.value(),method,AjTypeSystem.getAjType(method.getDeclaringClass()),pcAnn.argNames());
  392. } else {
  393. return null;
  394. }
  395. }
  396. public Advice[] getDeclaredAdvice(AdviceKind... ofType) {
  397. Set<AdviceKind> types;
  398. if (ofType.length == 0) {
  399. types = EnumSet.allOf(AdviceKind.class);
  400. } else {
  401. types = EnumSet.noneOf(AdviceKind.class);
  402. types.addAll(Arrays.asList(ofType));
  403. }
  404. return getDeclaredAdvice(types);
  405. }
  406. public Advice[] getAdvice(AdviceKind... ofType) {
  407. Set<AdviceKind> types;
  408. if (ofType.length == 0) {
  409. types = EnumSet.allOf(AdviceKind.class);
  410. } else {
  411. types = EnumSet.noneOf(AdviceKind.class);
  412. types.addAll(Arrays.asList(ofType));
  413. }
  414. return getAdvice(types);
  415. }
  416. /* (non-Javadoc)
  417. * @see org.aspectj.lang.reflect.AjType#getDeclaredAdvice(org.aspectj.lang.reflect.AdviceType)
  418. */
  419. private Advice[] getDeclaredAdvice(Set ofAdviceTypes) {
  420. if (declaredAdvice == null) initDeclaredAdvice();
  421. List<Advice> adviceList = new ArrayList<Advice>();
  422. for (Advice a : declaredAdvice) {
  423. if (ofAdviceTypes.contains(a.getKind())) adviceList.add(a);
  424. }
  425. Advice[] ret = new Advice[adviceList.size()];
  426. adviceList.toArray(ret);
  427. return ret;
  428. }
  429. private void initDeclaredAdvice() {
  430. Method[] methods = clazz.getDeclaredMethods();
  431. List<Advice> adviceList = new ArrayList<Advice>();
  432. for (Method method : methods) {
  433. Advice advice = asAdvice(method);
  434. if (advice != null) adviceList.add(advice);
  435. }
  436. declaredAdvice = new Advice[adviceList.size()];
  437. adviceList.toArray(declaredAdvice);
  438. }
  439. /* (non-Javadoc)
  440. * @see org.aspectj.lang.reflect.AjType#getDeclaredAdvice(org.aspectj.lang.reflect.AdviceType)
  441. */
  442. private Advice[] getAdvice(Set ofAdviceTypes) {
  443. if (advice == null) initAdvice();
  444. List<Advice> adviceList = new ArrayList<Advice>();
  445. for (Advice a : advice) {
  446. if (ofAdviceTypes.contains(a.getKind())) adviceList.add(a);
  447. }
  448. Advice[] ret = new Advice[adviceList.size()];
  449. adviceList.toArray(ret);
  450. return ret;
  451. }
  452. private void initAdvice() {
  453. Method[] methods = clazz.getMethods();
  454. List<Advice> adviceList = new ArrayList<Advice>();
  455. for (Method method : methods) {
  456. Advice advice = asAdvice(method);
  457. if (advice != null) adviceList.add(advice);
  458. }
  459. advice = new Advice[adviceList.size()];
  460. adviceList.toArray(advice);
  461. }
  462. public Advice getAdvice(String name) throws NoSuchAdviceException {
  463. if (name.equals("")) throw new IllegalArgumentException("use getAdvice(AdviceType...) instead for un-named advice");
  464. if (advice == null) initAdvice();
  465. for (Advice a : advice) {
  466. if (a.getName().equals(name)) return a;
  467. }
  468. throw new NoSuchAdviceException(name);
  469. }
  470. public Advice getDeclaredAdvice(String name) throws NoSuchAdviceException {
  471. if (name.equals("")) throw new IllegalArgumentException("use getAdvice(AdviceType...) instead for un-named advice");
  472. if (declaredAdvice == null) initDeclaredAdvice();
  473. for (Advice a : declaredAdvice) {
  474. if (a.getName().equals(name)) return a;
  475. }
  476. throw new NoSuchAdviceException(name);
  477. }
  478. private Advice asAdvice(Method method) {
  479. if (method.getAnnotations().length == 0) return null;
  480. Before beforeAnn = method.getAnnotation(Before.class);
  481. if (beforeAnn != null) return new AdviceImpl(method,beforeAnn.value(),AdviceKind.BEFORE);
  482. After afterAnn = method.getAnnotation(After.class);
  483. if (afterAnn != null) return new AdviceImpl(method,afterAnn.value(),AdviceKind.AFTER);
  484. AfterReturning afterReturningAnn = method.getAnnotation(AfterReturning.class);
  485. if (afterReturningAnn != null) {
  486. String pcExpr = afterReturningAnn.pointcut();
  487. if (pcExpr.equals("")) pcExpr = afterReturningAnn.value();
  488. return new AdviceImpl(method,pcExpr,AdviceKind.AFTER_RETURNING,afterReturningAnn.returning());
  489. }
  490. AfterThrowing afterThrowingAnn = method.getAnnotation(AfterThrowing.class);
  491. if (afterThrowingAnn != null) {
  492. String pcExpr = afterThrowingAnn.pointcut();
  493. if (pcExpr == null) pcExpr = afterThrowingAnn.value();
  494. return new AdviceImpl(method,pcExpr,AdviceKind.AFTER_THROWING,afterThrowingAnn.throwing());
  495. }
  496. Around aroundAnn = method.getAnnotation(Around.class);
  497. if (aroundAnn != null) return new AdviceImpl(method,aroundAnn.value(),AdviceKind.AROUND);
  498. return null;
  499. }
  500. /* (non-Javadoc)
  501. * @see org.aspectj.lang.reflect.AjType#getDeclaredITDMethod(java.lang.String, java.lang.Class, java.lang.Class...)
  502. */
  503. public InterTypeMethodDeclaration getDeclaredITDMethod(String name,
  504. AjType<?> target, AjType<?>... parameterTypes) throws NoSuchMethodException {
  505. InterTypeMethodDeclaration[] itdms = getDeclaredITDMethods();
  506. outer: for (InterTypeMethodDeclaration itdm : itdms) {
  507. try {
  508. if (!itdm.getName().equals(name)) continue;
  509. AjType<?> itdTarget = itdm.getTargetType();
  510. if (itdTarget.equals(target)) {
  511. AjType<?>[] ptypes = itdm.getParameterTypes();
  512. if (ptypes.length == parameterTypes.length) {
  513. for (int i = 0; i < ptypes.length; i++) {
  514. if (!ptypes[i].equals(parameterTypes[i]))
  515. continue outer;
  516. }
  517. return itdm;
  518. }
  519. }
  520. } catch (ClassNotFoundException cnf) {
  521. // just move on to the next one
  522. }
  523. }
  524. throw new NoSuchMethodException(name);
  525. }
  526. /* (non-Javadoc)
  527. * @see org.aspectj.lang.reflect.AjType#getDeclaredITDMethods()
  528. */
  529. public InterTypeMethodDeclaration[] getDeclaredITDMethods() {
  530. if (this.declaredITDMethods == null) {
  531. List<InterTypeMethodDeclaration> itdms = new ArrayList<InterTypeMethodDeclaration>();
  532. Method[] baseMethods = clazz.getDeclaredMethods();
  533. for (Method m : baseMethods) {
  534. if (!m.getName().contains("ajc$interMethodDispatch1$")) continue;
  535. if (m.isAnnotationPresent(ajcITD.class)) {
  536. ajcITD ann = m.getAnnotation(ajcITD.class);
  537. InterTypeMethodDeclaration itdm =
  538. new InterTypeMethodDeclarationImpl(
  539. this,ann.targetType(),ann.modifiers(),
  540. ann.name(),m);
  541. itdms.add(itdm);
  542. }
  543. }
  544. addAnnotationStyleITDMethods(itdms,false);
  545. this.declaredITDMethods = new InterTypeMethodDeclaration[itdms.size()];
  546. itdms.toArray(this.declaredITDMethods);
  547. }
  548. return this.declaredITDMethods;
  549. }
  550. public InterTypeMethodDeclaration getITDMethod(String name, AjType<?> target,
  551. AjType<?>... parameterTypes)
  552. throws NoSuchMethodException {
  553. InterTypeMethodDeclaration[] itdms = getITDMethods();
  554. outer: for (InterTypeMethodDeclaration itdm : itdms) {
  555. try {
  556. if (!itdm.getName().equals(name)) continue;
  557. AjType<?> itdTarget = itdm.getTargetType();
  558. if (itdTarget.equals(target)) {
  559. AjType<?>[] ptypes = itdm.getParameterTypes();
  560. if (ptypes.length == parameterTypes.length) {
  561. for (int i = 0; i < ptypes.length; i++) {
  562. if (!ptypes[i].equals(parameterTypes[i]))
  563. continue outer;
  564. }
  565. return itdm;
  566. }
  567. }
  568. } catch (ClassNotFoundException cnf) {
  569. // just move on to the next one
  570. }
  571. }
  572. throw new NoSuchMethodException(name);
  573. }
  574. public InterTypeMethodDeclaration[] getITDMethods() {
  575. if (this.itdMethods == null) {
  576. List<InterTypeMethodDeclaration> itdms = new ArrayList<InterTypeMethodDeclaration>();
  577. Method[] baseMethods = clazz.getDeclaredMethods();
  578. for (Method m : baseMethods) {
  579. if (!m.getName().contains("ajc$interMethod$")) continue;
  580. if (m.isAnnotationPresent(ajcITD.class)) {
  581. ajcITD ann = m.getAnnotation(ajcITD.class);
  582. if (!Modifier.isPublic(ann.modifiers())) continue;
  583. InterTypeMethodDeclaration itdm =
  584. new InterTypeMethodDeclarationImpl(
  585. this,ann.targetType(),ann.modifiers(),
  586. ann.name(),m);
  587. itdms.add(itdm);
  588. }
  589. }
  590. addAnnotationStyleITDMethods(itdms,true);
  591. this.itdMethods = new InterTypeMethodDeclaration[itdms.size()];
  592. itdms.toArray(this.itdMethods);
  593. }
  594. return this.itdMethods;
  595. }
  596. private void addAnnotationStyleITDMethods(List<InterTypeMethodDeclaration> toList, boolean publicOnly) {
  597. if (isAspect()) {
  598. for (Field f : clazz.getDeclaredFields()) {
  599. if (!f.getType().isInterface()) continue;
  600. if (f.isAnnotationPresent(org.aspectj.lang.annotation.DeclareParents.class)) {
  601. Class<org.aspectj.lang.annotation.DeclareParents> decPAnnClass = org.aspectj.lang.annotation.DeclareParents.class;
  602. org.aspectj.lang.annotation.DeclareParents decPAnn = f.getAnnotation(decPAnnClass);
  603. if (decPAnn.defaultImpl() == decPAnnClass) continue; // doesn't contribute members...
  604. for (Method itdM : f.getType().getDeclaredMethods()) {
  605. if (!Modifier.isPublic(itdM.getModifiers()) && publicOnly) continue;
  606. InterTypeMethodDeclaration itdm = new InterTypeMethodDeclarationImpl(
  607. this, AjTypeSystem.getAjType(f.getType()), itdM,
  608. Modifier.PUBLIC
  609. );
  610. toList.add(itdm);
  611. }
  612. }
  613. }
  614. }
  615. }
  616. private void addAnnotationStyleITDFields(List<InterTypeFieldDeclaration> toList, boolean publicOnly) {
  617. //AV: I think it is meaningless
  618. //@AJ decp is interface driven ie no field
  619. return;
  620. }
  621. public InterTypeConstructorDeclaration getDeclaredITDConstructor(
  622. AjType<?> target, AjType<?>... parameterTypes) throws NoSuchMethodException {
  623. InterTypeConstructorDeclaration[] itdcs = getDeclaredITDConstructors();
  624. outer: for (InterTypeConstructorDeclaration itdc : itdcs) {
  625. try {
  626. AjType<?> itdTarget = itdc.getTargetType();
  627. if (itdTarget.equals(target)) {
  628. AjType<?>[] ptypes = itdc.getParameterTypes();
  629. if (ptypes.length == parameterTypes.length) {
  630. for (int i = 0; i < ptypes.length; i++) {
  631. if (!ptypes[i].equals(parameterTypes[i]))
  632. continue outer;
  633. }
  634. return itdc;
  635. }
  636. }
  637. } catch (ClassNotFoundException cnf) {
  638. // just move on to the next one
  639. }
  640. }
  641. throw new NoSuchMethodException();
  642. }
  643. public InterTypeConstructorDeclaration[] getDeclaredITDConstructors() {
  644. if (this.declaredITDCons == null) {
  645. List<InterTypeConstructorDeclaration> itdcs = new ArrayList<InterTypeConstructorDeclaration>();
  646. Method[] baseMethods = clazz.getDeclaredMethods();
  647. for (Method m : baseMethods) {
  648. if (!m.getName().contains("ajc$postInterConstructor")) continue;
  649. if (m.isAnnotationPresent(ajcITD.class)) {
  650. ajcITD ann = m.getAnnotation(ajcITD.class);
  651. InterTypeConstructorDeclaration itdc =
  652. new InterTypeConstructorDeclarationImpl(this,ann.targetType(),ann.modifiers(),m);
  653. itdcs.add(itdc);
  654. }
  655. }
  656. this.declaredITDCons = new InterTypeConstructorDeclaration[itdcs.size()];
  657. itdcs.toArray(this.declaredITDCons);
  658. }
  659. return this.declaredITDCons;
  660. }
  661. public InterTypeConstructorDeclaration getITDConstructor(AjType<?> target,
  662. AjType<?>... parameterTypes) throws NoSuchMethodException {
  663. InterTypeConstructorDeclaration[] itdcs = getITDConstructors();
  664. outer: for (InterTypeConstructorDeclaration itdc : itdcs) {
  665. try {
  666. AjType<?> itdTarget = itdc.getTargetType();
  667. if (itdTarget.equals(target)) {
  668. AjType<?>[] ptypes = itdc.getParameterTypes();
  669. if (ptypes.length == parameterTypes.length) {
  670. for (int i = 0; i < ptypes.length; i++) {
  671. if (!ptypes[i].equals(parameterTypes[i]))
  672. continue outer;
  673. }
  674. return itdc;
  675. }
  676. }
  677. } catch (ClassNotFoundException cnf) {
  678. // just move on to the next one
  679. }
  680. }
  681. throw new NoSuchMethodException();
  682. }
  683. public InterTypeConstructorDeclaration[] getITDConstructors() {
  684. if (this.itdCons == null) {
  685. List<InterTypeConstructorDeclaration> itdcs = new ArrayList<InterTypeConstructorDeclaration>();
  686. Method[] baseMethods = clazz.getMethods();
  687. for (Method m : baseMethods) {
  688. if (!m.getName().contains("ajc$postInterConstructor")) continue;
  689. if (m.isAnnotationPresent(ajcITD.class)) {
  690. ajcITD ann = m.getAnnotation(ajcITD.class);
  691. if (!Modifier.isPublic(ann.modifiers())) continue;
  692. InterTypeConstructorDeclaration itdc =
  693. new InterTypeConstructorDeclarationImpl(this,ann.targetType(),ann.modifiers(),m);
  694. itdcs.add(itdc);
  695. }
  696. }
  697. this.itdCons = new InterTypeConstructorDeclaration[itdcs.size()];
  698. itdcs.toArray(this.itdCons);
  699. }
  700. return this.itdCons; }
  701. public InterTypeFieldDeclaration getDeclaredITDField(String name,
  702. AjType<?> target) throws NoSuchFieldException {
  703. InterTypeFieldDeclaration[] itdfs = getDeclaredITDFields();
  704. for (InterTypeFieldDeclaration itdf : itdfs) {
  705. if (itdf.getName().equals(name)) {
  706. try {
  707. AjType<?> itdTarget = itdf.getTargetType();
  708. if (itdTarget.equals(target)) return itdf;
  709. } catch (ClassNotFoundException cnfEx) {
  710. // move on to next field
  711. }
  712. }
  713. }
  714. throw new NoSuchFieldException(name);
  715. }
  716. public InterTypeFieldDeclaration[] getDeclaredITDFields() {
  717. List<InterTypeFieldDeclaration> itdfs = new ArrayList<InterTypeFieldDeclaration>();
  718. if (this.declaredITDFields == null) {
  719. Method[] baseMethods = clazz.getDeclaredMethods();
  720. for(Method m : baseMethods) {
  721. if (m.isAnnotationPresent(ajcITD.class)) {
  722. if (!m.getName().contains("ajc$interFieldInit")) continue;
  723. ajcITD ann = m.getAnnotation(ajcITD.class);
  724. String interFieldInitMethodName = m.getName();
  725. String interFieldGetDispatchMethodName =
  726. interFieldInitMethodName.replace("FieldInit","FieldGetDispatch");
  727. try {
  728. Method dispatch = clazz.getDeclaredMethod(interFieldGetDispatchMethodName, m.getParameterTypes());
  729. InterTypeFieldDeclaration itdf = new InterTypeFieldDeclarationImpl(
  730. this,ann.targetType(),ann.modifiers(),ann.name(),
  731. AjTypeSystem.getAjType(dispatch.getReturnType()),
  732. dispatch.getGenericReturnType());
  733. itdfs.add(itdf);
  734. } catch (NoSuchMethodException nsmEx) {
  735. throw new IllegalStateException("Can't find field get dispatch method for " + m.getName());
  736. }
  737. }
  738. }
  739. addAnnotationStyleITDFields(itdfs, false);
  740. this.declaredITDFields = new InterTypeFieldDeclaration[itdfs.size()];
  741. itdfs.toArray(this.declaredITDFields);
  742. }
  743. return this.declaredITDFields;
  744. }
  745. public InterTypeFieldDeclaration getITDField(String name, AjType<?> target)
  746. throws NoSuchFieldException {
  747. InterTypeFieldDeclaration[] itdfs = getITDFields();
  748. for (InterTypeFieldDeclaration itdf : itdfs) {
  749. if (itdf.getName().equals(name)) {
  750. try {
  751. AjType<?> itdTarget = itdf.getTargetType();
  752. if (itdTarget.equals(target)) return itdf;
  753. } catch (ClassNotFoundException cnfEx) {
  754. // move on to next field
  755. }
  756. }
  757. }
  758. throw new NoSuchFieldException(name);
  759. }
  760. public InterTypeFieldDeclaration[] getITDFields() {
  761. List<InterTypeFieldDeclaration> itdfs = new ArrayList<InterTypeFieldDeclaration>();
  762. if (this.itdFields == null) {
  763. Method[] baseMethods = clazz.getMethods();
  764. for(Method m : baseMethods) {
  765. if (m.isAnnotationPresent(ajcITD.class)) {
  766. ajcITD ann = m.getAnnotation(ajcITD.class);
  767. if (!m.getName().contains("ajc$interFieldInit")) continue;
  768. if (!Modifier.isPublic(ann.modifiers())) continue;
  769. String interFieldInitMethodName = m.getName();
  770. String interFieldGetDispatchMethodName =
  771. interFieldInitMethodName.replace("FieldInit","FieldGetDispatch");
  772. try {
  773. Method dispatch = m.getDeclaringClass().getDeclaredMethod(interFieldGetDispatchMethodName, m.getParameterTypes());
  774. InterTypeFieldDeclaration itdf = new InterTypeFieldDeclarationImpl(
  775. this,ann.targetType(),ann.modifiers(),ann.name(),
  776. AjTypeSystem.getAjType(dispatch.getReturnType()),
  777. dispatch.getGenericReturnType());
  778. itdfs.add(itdf);
  779. } catch (NoSuchMethodException nsmEx) {
  780. throw new IllegalStateException("Can't find field get dispatch method for " + m.getName());
  781. }
  782. }
  783. }
  784. addAnnotationStyleITDFields(itdfs, true);
  785. this.itdFields = new InterTypeFieldDeclaration[itdfs.size()];
  786. itdfs.toArray(this.itdFields);
  787. }
  788. return this.itdFields;
  789. }
  790. public DeclareErrorOrWarning[] getDeclareErrorOrWarnings() {
  791. List<DeclareErrorOrWarning> deows = new ArrayList<DeclareErrorOrWarning>();
  792. for (Field field : clazz.getDeclaredFields()) {
  793. try {
  794. if (field.isAnnotationPresent(DeclareWarning.class)) {
  795. DeclareWarning dw = field.getAnnotation(DeclareWarning.class);
  796. if (Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers())) {
  797. String message = (String) field.get(null);
  798. DeclareErrorOrWarningImpl deow = new DeclareErrorOrWarningImpl(dw.value(),message,false,this);
  799. deows.add(deow);
  800. }
  801. } else if (field.isAnnotationPresent(DeclareError.class)) {
  802. DeclareError de = field.getAnnotation(DeclareError.class);
  803. if (Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers())) {
  804. String message = (String) field.get(null);
  805. DeclareErrorOrWarningImpl deow = new DeclareErrorOrWarningImpl(de.value(),message,true,this);
  806. deows.add(deow);
  807. }
  808. }
  809. } catch (IllegalArgumentException e) {
  810. // just move on to the next field
  811. } catch (IllegalAccessException e) {
  812. // just move on to the next field
  813. }
  814. }
  815. for (Method method : clazz.getDeclaredMethods()) {
  816. if (method.isAnnotationPresent(ajcDeclareEoW.class)) {
  817. ajcDeclareEoW deowAnn = method.getAnnotation(ajcDeclareEoW.class);
  818. DeclareErrorOrWarning deow = new DeclareErrorOrWarningImpl(deowAnn.pointcut(),deowAnn.message(),deowAnn.isError(),this);
  819. deows.add(deow);
  820. }
  821. }
  822. DeclareErrorOrWarning[] ret = new DeclareErrorOrWarning[deows.size()];
  823. deows.toArray(ret);
  824. return ret;
  825. }
  826. public DeclareParents[] getDeclareParents() {
  827. List<DeclareParents> decps = new ArrayList<DeclareParents>();
  828. for (Method method : clazz.getDeclaredMethods()) {
  829. if (method.isAnnotationPresent(ajcDeclareParents.class)) {
  830. ajcDeclareParents decPAnn = method.getAnnotation(ajcDeclareParents.class);
  831. DeclareParentsImpl decp = new DeclareParentsImpl(
  832. decPAnn.targetTypePattern(),
  833. decPAnn.parentTypes(),
  834. decPAnn.isExtends(),
  835. this
  836. );
  837. decps.add(decp);
  838. }
  839. }
  840. addAnnotationStyleDeclareParents(decps);
  841. if (getSupertype().isAspect()) {
  842. decps.addAll(Arrays.asList(getSupertype().getDeclareParents()));
  843. }
  844. DeclareParents[] ret = new DeclareParents[decps.size()];
  845. decps.toArray(ret);
  846. return ret;
  847. }
  848. private void addAnnotationStyleDeclareParents(List<DeclareParents> toList) {
  849. for (Field f : clazz.getDeclaredFields()) {
  850. if (f.isAnnotationPresent(org.aspectj.lang.annotation.DeclareParents.class)) {
  851. if (!f.getType().isInterface()) continue;
  852. org.aspectj.lang.annotation.DeclareParents ann = f.getAnnotation(org.aspectj.lang.annotation.DeclareParents.class);
  853. String parentType = f.getType().getName();
  854. DeclareParentsImpl decp = new DeclareParentsImpl(
  855. ann.value(),
  856. parentType,
  857. false,
  858. this
  859. );
  860. toList.add(decp);
  861. }
  862. }
  863. }
  864. public DeclareSoft[] getDeclareSofts() {
  865. List<DeclareSoft> decs = new ArrayList<DeclareSoft>();
  866. for (Method method : clazz.getDeclaredMethods()) {
  867. if (method.isAnnotationPresent(ajcDeclareSoft.class)) {
  868. ajcDeclareSoft decSAnn = method.getAnnotation(ajcDeclareSoft.class);
  869. DeclareSoftImpl ds = new DeclareSoftImpl(
  870. this,
  871. decSAnn.pointcut(),
  872. decSAnn.exceptionType()
  873. );
  874. decs.add(ds);
  875. }
  876. }
  877. if (getSupertype().isAspect()) {
  878. decs.addAll(Arrays.asList(getSupertype().getDeclareSofts()));
  879. }
  880. DeclareSoft[] ret = new DeclareSoft[decs.size()];
  881. decs.toArray(ret);
  882. return ret;
  883. }
  884. public DeclareAnnotation[] getDeclareAnnotations() {
  885. List<DeclareAnnotation> decAs = new ArrayList<DeclareAnnotation>();
  886. for (Method method : clazz.getDeclaredMethods()) {
  887. if (method.isAnnotationPresent(ajcDeclareAnnotation.class)) {
  888. ajcDeclareAnnotation decAnn = method.getAnnotation(ajcDeclareAnnotation.class);
  889. // the target annotation is on this method...
  890. Annotation targetAnnotation = null;
  891. Annotation[] anns = method.getAnnotations();
  892. for (Annotation ann: anns) {
  893. if (ann.annotationType() != ajcDeclareAnnotation.class) {
  894. // this must be the one...
  895. targetAnnotation = ann;
  896. break;
  897. }
  898. }
  899. DeclareAnnotationImpl da = new DeclareAnnotationImpl(
  900. this,
  901. decAnn.kind(),
  902. decAnn.pattern(),
  903. targetAnnotation,
  904. decAnn.annotation()
  905. );
  906. decAs.add(da);
  907. }
  908. }
  909. if (getSupertype().isAspect()) {
  910. decAs.addAll(Arrays.asList(getSupertype().getDeclareAnnotations()));
  911. }
  912. DeclareAnnotation[] ret = new DeclareAnnotation[decAs.size()];
  913. decAs.toArray(ret);
  914. return ret;
  915. }
  916. public DeclarePrecedence[] getDeclarePrecedence() {
  917. List<DeclarePrecedence> decps = new ArrayList<DeclarePrecedence>();
  918. // @AspectJ Style
  919. if (clazz.isAnnotationPresent(org.aspectj.lang.annotation.DeclarePrecedence.class)) {
  920. org.aspectj.lang.annotation.DeclarePrecedence ann =
  921. clazz.getAnnotation(org.aspectj.lang.annotation.DeclarePrecedence.class);
  922. DeclarePrecedenceImpl decp = new DeclarePrecedenceImpl(
  923. ann.value(),
  924. this
  925. );
  926. decps.add(decp);
  927. }
  928. // annotated code-style
  929. for (Method method : clazz.getDeclaredMethods()) {
  930. if (method.isAnnotationPresent(ajcDeclarePrecedence.class)) {
  931. ajcDeclarePrecedence decPAnn = method.getAnnotation(ajcDeclarePrecedence.class);
  932. DeclarePrecedenceImpl decp = new DeclarePrecedenceImpl(
  933. decPAnn.value(),
  934. this
  935. );
  936. decps.add(decp);
  937. }
  938. }
  939. if (getSupertype().isAspect()) {
  940. decps.addAll(Arrays.asList(getSupertype().getDeclarePrecedence()));
  941. }
  942. DeclarePrecedence[] ret = new DeclarePrecedence[decps.size()];
  943. decps.toArray(ret);
  944. return ret;
  945. }
  946. public T[] getEnumConstants() {
  947. return clazz.getEnumConstants();
  948. }
  949. public TypeVariable<Class<T>>[] getTypeParameters() {
  950. return clazz.getTypeParameters();
  951. }
  952. public boolean isEnum() {
  953. return clazz.isEnum();
  954. }
  955. public boolean isInstance(Object o) {
  956. return clazz.isInstance(o);
  957. }
  958. public boolean isInterface() {
  959. return clazz.isInterface();
  960. }
  961. public boolean isLocalClass() {
  962. return clazz.isLocalClass() && !isAspect();
  963. }
  964. public boolean isMemberClass() {
  965. return clazz.isMemberClass() && !isAspect();
  966. }
  967. public boolean isArray() {
  968. return clazz.isArray();
  969. }
  970. public boolean isPrimitive() {
  971. return clazz.isPrimitive();
  972. }
  973. public boolean isAspect() {
  974. return clazz.getAnnotation(Aspect.class) != null;
  975. }
  976. public boolean isMemberAspect() {
  977. return clazz.isMemberClass() && isAspect();
  978. }
  979. public boolean isPrivileged() {
  980. return isAspect() && clazz.isAnnotationPresent(ajcPrivileged.class);
  981. }
  982. @Override
  983. public boolean equals(Object obj) {
  984. if (!(obj instanceof AjTypeImpl)) return false;
  985. AjTypeImpl other = (AjTypeImpl) obj;
  986. return other.clazz.equals(clazz);
  987. }
  988. @Override
  989. public int hashCode() {
  990. return clazz.hashCode();
  991. }
  992. private AjType<?>[] toAjTypeArray(Class<?>[] classes) {
  993. AjType<?>[] ajtypes = new AjType<?>[classes.length];
  994. for (int i = 0; i < ajtypes.length; i++) {
  995. ajtypes[i] = AjTypeSystem.getAjType(classes[i]);
  996. }
  997. return ajtypes;
  998. }
  999. private Class<?>[] toClassArray(AjType<?>[] ajTypes) {
  1000. Class<?>[] classes = new Class<?>[ajTypes.length];
  1001. for (int i = 0; i < classes.length; i++) {
  1002. classes[i] = ajTypes[i].getJavaClass();
  1003. }
  1004. return classes;
  1005. }
  1006. public String toString() { return getName(); }
  1007. }