Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

AjTypeImpl.java 40KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  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. /* (non-Javadoc)
  551. * @see org.aspectj.lang.reflect.AjType#getITDMethod(java.lang.String, java.lang.Class, java.lang.Class...)
  552. */
  553. public InterTypeMethodDeclaration getITDMethod(String name, AjType<?> target,
  554. AjType<?>... parameterTypes)
  555. throws NoSuchMethodException {
  556. InterTypeMethodDeclaration[] itdms = getITDMethods();
  557. outer: for (InterTypeMethodDeclaration itdm : itdms) {
  558. try {
  559. if (!itdm.getName().equals(name)) continue;
  560. AjType<?> itdTarget = itdm.getTargetType();
  561. if (itdTarget.equals(target)) {
  562. AjType<?>[] ptypes = itdm.getParameterTypes();
  563. if (ptypes.length == parameterTypes.length) {
  564. for (int i = 0; i < ptypes.length; i++) {
  565. if (!ptypes[i].equals(parameterTypes[i]))
  566. continue outer;
  567. }
  568. return itdm;
  569. }
  570. }
  571. } catch (ClassNotFoundException cnf) {
  572. // just move on to the next one
  573. }
  574. }
  575. throw new NoSuchMethodException(name);
  576. }
  577. /* (non-Javadoc)
  578. * @see org.aspectj.lang.reflect.AjType#getITDMethods()
  579. */
  580. public InterTypeMethodDeclaration[] getITDMethods() {
  581. if (this.itdMethods == null) {
  582. List<InterTypeMethodDeclaration> itdms = new ArrayList<InterTypeMethodDeclaration>();
  583. Method[] baseMethods = clazz.getDeclaredMethods();
  584. for (Method m : baseMethods) {
  585. if (!m.getName().contains("ajc$interMethod$")) continue;
  586. if (m.isAnnotationPresent(ajcITD.class)) {
  587. ajcITD ann = m.getAnnotation(ajcITD.class);
  588. if (!Modifier.isPublic(ann.modifiers())) continue;
  589. InterTypeMethodDeclaration itdm =
  590. new InterTypeMethodDeclarationImpl(
  591. this,ann.targetType(),ann.modifiers(),
  592. ann.name(),m);
  593. itdms.add(itdm);
  594. }
  595. }
  596. addAnnotationStyleITDMethods(itdms,true);
  597. this.itdMethods = new InterTypeMethodDeclaration[itdms.size()];
  598. itdms.toArray(this.itdMethods);
  599. }
  600. return this.itdMethods;
  601. }
  602. private void addAnnotationStyleITDMethods(List<InterTypeMethodDeclaration> toList, boolean publicOnly) {
  603. if (isAspect()) {
  604. for (Field f : clazz.getDeclaredFields()) {
  605. if (!f.getType().isInterface()) continue;
  606. if (f.isAnnotationPresent(org.aspectj.lang.annotation.DeclareParents.class)) {
  607. Class<org.aspectj.lang.annotation.DeclareParents> decPAnnClass = org.aspectj.lang.annotation.DeclareParents.class;
  608. org.aspectj.lang.annotation.DeclareParents decPAnn = f.getAnnotation(decPAnnClass);
  609. if (decPAnn.defaultImpl() == decPAnnClass) continue; // doesn't contribute members...
  610. for (Method itdM : f.getType().getDeclaredMethods()) {
  611. if (!Modifier.isPublic(itdM.getModifiers()) && publicOnly) continue;
  612. InterTypeMethodDeclaration itdm = new InterTypeMethodDeclarationImpl(
  613. this, AjTypeSystem.getAjType(f.getType()), itdM,
  614. Modifier.PUBLIC
  615. );
  616. toList.add(itdm);
  617. }
  618. }
  619. }
  620. }
  621. }
  622. private void addAnnotationStyleITDFields(List<InterTypeFieldDeclaration> toList, boolean publicOnly) {
  623. //AV: I think it is meaningless
  624. //@AJ decp is interface driven ie no field
  625. return;
  626. }
  627. /* (non-Javadoc)
  628. * @see org.aspectj.lang.reflect.AjType#getDeclaredITDConstructor(java.lang.Class, java.lang.Class...)
  629. */
  630. public InterTypeConstructorDeclaration getDeclaredITDConstructor(
  631. AjType<?> target, AjType<?>... parameterTypes) throws NoSuchMethodException {
  632. InterTypeConstructorDeclaration[] itdcs = getDeclaredITDConstructors();
  633. outer: for (InterTypeConstructorDeclaration itdc : itdcs) {
  634. try {
  635. AjType<?> itdTarget = itdc.getTargetType();
  636. if (itdTarget.equals(target)) {
  637. AjType<?>[] ptypes = itdc.getParameterTypes();
  638. if (ptypes.length == parameterTypes.length) {
  639. for (int i = 0; i < ptypes.length; i++) {
  640. if (!ptypes[i].equals(parameterTypes[i]))
  641. continue outer;
  642. }
  643. return itdc;
  644. }
  645. }
  646. } catch (ClassNotFoundException cnf) {
  647. // just move on to the next one
  648. }
  649. }
  650. throw new NoSuchMethodException();
  651. }
  652. /* (non-Javadoc)
  653. * @see org.aspectj.lang.reflect.AjType#getDeclaredITDConstructors()
  654. */
  655. public InterTypeConstructorDeclaration[] getDeclaredITDConstructors() {
  656. if (this.declaredITDCons == null) {
  657. List<InterTypeConstructorDeclaration> itdcs = new ArrayList<InterTypeConstructorDeclaration>();
  658. Method[] baseMethods = clazz.getDeclaredMethods();
  659. for (Method m : baseMethods) {
  660. if (!m.getName().contains("ajc$postInterConstructor")) continue;
  661. if (m.isAnnotationPresent(ajcITD.class)) {
  662. ajcITD ann = m.getAnnotation(ajcITD.class);
  663. InterTypeConstructorDeclaration itdc =
  664. new InterTypeConstructorDeclarationImpl(this,ann.targetType(),ann.modifiers(),m);
  665. itdcs.add(itdc);
  666. }
  667. }
  668. this.declaredITDCons = new InterTypeConstructorDeclaration[itdcs.size()];
  669. itdcs.toArray(this.declaredITDCons);
  670. }
  671. return this.declaredITDCons;
  672. }
  673. /* (non-Javadoc)
  674. * @see org.aspectj.lang.reflect.AjType#getITDConstructor(java.lang.Class, java.lang.Class...)
  675. */
  676. public InterTypeConstructorDeclaration getITDConstructor(AjType<?> target,
  677. AjType<?>... parameterTypes) throws NoSuchMethodException {
  678. InterTypeConstructorDeclaration[] itdcs = getITDConstructors();
  679. outer: for (InterTypeConstructorDeclaration itdc : itdcs) {
  680. try {
  681. AjType<?> itdTarget = itdc.getTargetType();
  682. if (itdTarget.equals(target)) {
  683. AjType<?>[] ptypes = itdc.getParameterTypes();
  684. if (ptypes.length == parameterTypes.length) {
  685. for (int i = 0; i < ptypes.length; i++) {
  686. if (!ptypes[i].equals(parameterTypes[i]))
  687. continue outer;
  688. }
  689. return itdc;
  690. }
  691. }
  692. } catch (ClassNotFoundException cnf) {
  693. // just move on to the next one
  694. }
  695. }
  696. throw new NoSuchMethodException();
  697. }
  698. /* (non-Javadoc)
  699. * @see org.aspectj.lang.reflect.AjType#getITDConstructors()
  700. */
  701. public InterTypeConstructorDeclaration[] getITDConstructors() {
  702. if (this.itdCons == null) {
  703. List<InterTypeConstructorDeclaration> itdcs = new ArrayList<InterTypeConstructorDeclaration>();
  704. Method[] baseMethods = clazz.getMethods();
  705. for (Method m : baseMethods) {
  706. if (!m.getName().contains("ajc$postInterConstructor")) continue;
  707. if (m.isAnnotationPresent(ajcITD.class)) {
  708. ajcITD ann = m.getAnnotation(ajcITD.class);
  709. if (!Modifier.isPublic(ann.modifiers())) continue;
  710. InterTypeConstructorDeclaration itdc =
  711. new InterTypeConstructorDeclarationImpl(this,ann.targetType(),ann.modifiers(),m);
  712. itdcs.add(itdc);
  713. }
  714. }
  715. this.itdCons = new InterTypeConstructorDeclaration[itdcs.size()];
  716. itdcs.toArray(this.itdCons);
  717. }
  718. return this.itdCons; }
  719. /* (non-Javadoc)
  720. * @see org.aspectj.lang.reflect.AjType#getDeclaredITDField(java.lang.String, java.lang.Class)
  721. */
  722. public InterTypeFieldDeclaration getDeclaredITDField(String name,
  723. AjType<?> target) throws NoSuchFieldException {
  724. InterTypeFieldDeclaration[] itdfs = getDeclaredITDFields();
  725. for (InterTypeFieldDeclaration itdf : itdfs) {
  726. if (itdf.getName().equals(name)) {
  727. try {
  728. AjType<?> itdTarget = itdf.getTargetType();
  729. if (itdTarget.equals(target)) return itdf;
  730. } catch (ClassNotFoundException cnfEx) {
  731. // move on to next field
  732. }
  733. }
  734. }
  735. throw new NoSuchFieldException(name);
  736. }
  737. /* (non-Javadoc)
  738. * @see org.aspectj.lang.reflect.AjType#getDeclaredITDFields()
  739. */
  740. public InterTypeFieldDeclaration[] getDeclaredITDFields() {
  741. List<InterTypeFieldDeclaration> itdfs = new ArrayList<InterTypeFieldDeclaration>();
  742. if (this.declaredITDFields == null) {
  743. Method[] baseMethods = clazz.getDeclaredMethods();
  744. for(Method m : baseMethods) {
  745. if (m.isAnnotationPresent(ajcITD.class)) {
  746. if (!m.getName().contains("ajc$interFieldInit")) continue;
  747. ajcITD ann = m.getAnnotation(ajcITD.class);
  748. String interFieldInitMethodName = m.getName();
  749. String interFieldGetDispatchMethodName =
  750. interFieldInitMethodName.replace("FieldInit","FieldGetDispatch");
  751. try {
  752. Method dispatch = clazz.getDeclaredMethod(interFieldGetDispatchMethodName, m.getParameterTypes());
  753. InterTypeFieldDeclaration itdf = new InterTypeFieldDeclarationImpl(
  754. this,ann.targetType(),ann.modifiers(),ann.name(),
  755. AjTypeSystem.getAjType(dispatch.getReturnType()),
  756. dispatch.getGenericReturnType());
  757. itdfs.add(itdf);
  758. } catch (NoSuchMethodException nsmEx) {
  759. throw new IllegalStateException("Can't find field get dispatch method for " + m.getName());
  760. }
  761. }
  762. }
  763. addAnnotationStyleITDFields(itdfs, false);
  764. this.declaredITDFields = new InterTypeFieldDeclaration[itdfs.size()];
  765. itdfs.toArray(this.declaredITDFields);
  766. }
  767. return this.declaredITDFields;
  768. }
  769. /* (non-Javadoc)
  770. * @see org.aspectj.lang.reflect.AjType#getITDField(java.lang.String, java.lang.Class)
  771. */
  772. public InterTypeFieldDeclaration getITDField(String name, AjType<?> target)
  773. throws NoSuchFieldException {
  774. InterTypeFieldDeclaration[] itdfs = getITDFields();
  775. for (InterTypeFieldDeclaration itdf : itdfs) {
  776. if (itdf.getName().equals(name)) {
  777. try {
  778. AjType<?> itdTarget = itdf.getTargetType();
  779. if (itdTarget.equals(target)) return itdf;
  780. } catch (ClassNotFoundException cnfEx) {
  781. // move on to next field
  782. }
  783. }
  784. }
  785. throw new NoSuchFieldException(name);
  786. }
  787. /* (non-Javadoc)
  788. * @see org.aspectj.lang.reflect.AjType#getITDFields()
  789. */
  790. public InterTypeFieldDeclaration[] getITDFields() {
  791. List<InterTypeFieldDeclaration> itdfs = new ArrayList<InterTypeFieldDeclaration>();
  792. if (this.itdFields == null) {
  793. Method[] baseMethods = clazz.getMethods();
  794. for(Method m : baseMethods) {
  795. if (m.isAnnotationPresent(ajcITD.class)) {
  796. ajcITD ann = m.getAnnotation(ajcITD.class);
  797. if (!m.getName().contains("ajc$interFieldInit")) continue;
  798. if (!Modifier.isPublic(ann.modifiers())) continue;
  799. String interFieldInitMethodName = m.getName();
  800. String interFieldGetDispatchMethodName =
  801. interFieldInitMethodName.replace("FieldInit","FieldGetDispatch");
  802. try {
  803. Method dispatch = m.getDeclaringClass().getDeclaredMethod(interFieldGetDispatchMethodName, m.getParameterTypes());
  804. InterTypeFieldDeclaration itdf = new InterTypeFieldDeclarationImpl(
  805. this,ann.targetType(),ann.modifiers(),ann.name(),
  806. AjTypeSystem.getAjType(dispatch.getReturnType()),
  807. dispatch.getGenericReturnType());
  808. itdfs.add(itdf);
  809. } catch (NoSuchMethodException nsmEx) {
  810. throw new IllegalStateException("Can't find field get dispatch method for " + m.getName());
  811. }
  812. }
  813. }
  814. addAnnotationStyleITDFields(itdfs, true);
  815. this.itdFields = new InterTypeFieldDeclaration[itdfs.size()];
  816. itdfs.toArray(this.itdFields);
  817. }
  818. return this.itdFields;
  819. }
  820. /* (non-Javadoc)
  821. * @see org.aspectj.lang.reflect.AjType#getDeclareErrorOrWarnings()
  822. */
  823. public DeclareErrorOrWarning[] getDeclareErrorOrWarnings() {
  824. List<DeclareErrorOrWarning> deows = new ArrayList<DeclareErrorOrWarning>();
  825. for (Field field : clazz.getDeclaredFields()) {
  826. try {
  827. if (field.isAnnotationPresent(DeclareWarning.class)) {
  828. DeclareWarning dw = field.getAnnotation(DeclareWarning.class);
  829. if (Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers())) {
  830. String message = (String) field.get(null);
  831. DeclareErrorOrWarningImpl deow = new DeclareErrorOrWarningImpl(dw.value(),message,false,this);
  832. deows.add(deow);
  833. }
  834. } else if (field.isAnnotationPresent(DeclareError.class)) {
  835. DeclareError de = field.getAnnotation(DeclareError.class);
  836. if (Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers())) {
  837. String message = (String) field.get(null);
  838. DeclareErrorOrWarningImpl deow = new DeclareErrorOrWarningImpl(de.value(),message,true,this);
  839. deows.add(deow);
  840. }
  841. }
  842. } catch (IllegalArgumentException e) {
  843. // just move on to the next field
  844. } catch (IllegalAccessException e) {
  845. // just move on to the next field
  846. }
  847. }
  848. for (Method method : clazz.getDeclaredMethods()) {
  849. if (method.isAnnotationPresent(ajcDeclareEoW.class)) {
  850. ajcDeclareEoW deowAnn = method.getAnnotation(ajcDeclareEoW.class);
  851. DeclareErrorOrWarning deow = new DeclareErrorOrWarningImpl(deowAnn.pointcut(),deowAnn.message(),deowAnn.isError(),this);
  852. deows.add(deow);
  853. }
  854. }
  855. DeclareErrorOrWarning[] ret = new DeclareErrorOrWarning[deows.size()];
  856. deows.toArray(ret);
  857. return ret;
  858. }
  859. /* (non-Javadoc)
  860. * @see org.aspectj.lang.reflect.AjType#getDeclareParents()
  861. */
  862. public DeclareParents[] getDeclareParents() {
  863. List<DeclareParents> decps = new ArrayList<DeclareParents>();
  864. for (Method method : clazz.getDeclaredMethods()) {
  865. if (method.isAnnotationPresent(ajcDeclareParents.class)) {
  866. ajcDeclareParents decPAnn = method.getAnnotation(ajcDeclareParents.class);
  867. DeclareParentsImpl decp = new DeclareParentsImpl(
  868. decPAnn.targetTypePattern(),
  869. decPAnn.parentTypes(),
  870. decPAnn.isExtends(),
  871. this
  872. );
  873. decps.add(decp);
  874. }
  875. }
  876. addAnnotationStyleDeclareParents(decps);
  877. if (getSupertype().isAspect()) {
  878. decps.addAll(Arrays.asList(getSupertype().getDeclareParents()));
  879. }
  880. DeclareParents[] ret = new DeclareParents[decps.size()];
  881. decps.toArray(ret);
  882. return ret;
  883. }
  884. private void addAnnotationStyleDeclareParents(List<DeclareParents> toList) {
  885. for (Field f : clazz.getDeclaredFields()) {
  886. if (f.isAnnotationPresent(org.aspectj.lang.annotation.DeclareParents.class)) {
  887. if (!f.getType().isInterface()) continue;
  888. org.aspectj.lang.annotation.DeclareParents ann = f.getAnnotation(org.aspectj.lang.annotation.DeclareParents.class);
  889. String parentType = f.getType().getName();
  890. DeclareParentsImpl decp = new DeclareParentsImpl(
  891. ann.value(),
  892. parentType,
  893. false,
  894. this
  895. );
  896. toList.add(decp);
  897. }
  898. }
  899. }
  900. /* (non-Javadoc)
  901. * @see org.aspectj.lang.reflect.AjType#getDeclareSofts()
  902. */
  903. public DeclareSoft[] getDeclareSofts() {
  904. List<DeclareSoft> decs = new ArrayList<DeclareSoft>();
  905. for (Method method : clazz.getDeclaredMethods()) {
  906. if (method.isAnnotationPresent(ajcDeclareSoft.class)) {
  907. ajcDeclareSoft decSAnn = method.getAnnotation(ajcDeclareSoft.class);
  908. DeclareSoftImpl ds = new DeclareSoftImpl(
  909. this,
  910. decSAnn.pointcut(),
  911. decSAnn.exceptionType()
  912. );
  913. decs.add(ds);
  914. }
  915. }
  916. if (getSupertype().isAspect()) {
  917. decs.addAll(Arrays.asList(getSupertype().getDeclareSofts()));
  918. }
  919. DeclareSoft[] ret = new DeclareSoft[decs.size()];
  920. decs.toArray(ret);
  921. return ret;
  922. }
  923. /* (non-Javadoc)
  924. * @see org.aspectj.lang.reflect.AjType#getDeclareAnnotations()
  925. */
  926. public DeclareAnnotation[] getDeclareAnnotations() {
  927. List<DeclareAnnotation> decAs = new ArrayList<DeclareAnnotation>();
  928. for (Method method : clazz.getDeclaredMethods()) {
  929. if (method.isAnnotationPresent(ajcDeclareAnnotation.class)) {
  930. ajcDeclareAnnotation decAnn = method.getAnnotation(ajcDeclareAnnotation.class);
  931. // the target annotation is on this method...
  932. Annotation targetAnnotation = null;
  933. Annotation[] anns = method.getAnnotations();
  934. for (Annotation ann: anns) {
  935. if (ann.annotationType() != ajcDeclareAnnotation.class) {
  936. // this must be the one...
  937. targetAnnotation = ann;
  938. break;
  939. }
  940. }
  941. DeclareAnnotationImpl da = new DeclareAnnotationImpl(
  942. this,
  943. decAnn.kind(),
  944. decAnn.pattern(),
  945. targetAnnotation,
  946. decAnn.annotation()
  947. );
  948. decAs.add(da);
  949. }
  950. }
  951. if (getSupertype().isAspect()) {
  952. decAs.addAll(Arrays.asList(getSupertype().getDeclareAnnotations()));
  953. }
  954. DeclareAnnotation[] ret = new DeclareAnnotation[decAs.size()];
  955. decAs.toArray(ret);
  956. return ret;
  957. }
  958. /* (non-Javadoc)
  959. * @see org.aspectj.lang.reflect.AjType#getDeclarePrecedence()
  960. */
  961. public DeclarePrecedence[] getDeclarePrecedence() {
  962. List<DeclarePrecedence> decps = new ArrayList<DeclarePrecedence>();
  963. // @AspectJ Style
  964. if (clazz.isAnnotationPresent(org.aspectj.lang.annotation.DeclarePrecedence.class)) {
  965. org.aspectj.lang.annotation.DeclarePrecedence ann =
  966. clazz.getAnnotation(org.aspectj.lang.annotation.DeclarePrecedence.class);
  967. DeclarePrecedenceImpl decp = new DeclarePrecedenceImpl(
  968. ann.value(),
  969. this
  970. );
  971. decps.add(decp);
  972. }
  973. // annotated code-style
  974. for (Method method : clazz.getDeclaredMethods()) {
  975. if (method.isAnnotationPresent(ajcDeclarePrecedence.class)) {
  976. ajcDeclarePrecedence decPAnn = method.getAnnotation(ajcDeclarePrecedence.class);
  977. DeclarePrecedenceImpl decp = new DeclarePrecedenceImpl(
  978. decPAnn.value(),
  979. this
  980. );
  981. decps.add(decp);
  982. }
  983. }
  984. if (getSupertype().isAspect()) {
  985. decps.addAll(Arrays.asList(getSupertype().getDeclarePrecedence()));
  986. }
  987. DeclarePrecedence[] ret = new DeclarePrecedence[decps.size()];
  988. decps.toArray(ret);
  989. return ret;
  990. }
  991. /* (non-Javadoc)
  992. * @see org.aspectj.lang.reflect.AjType#getEnumConstants()
  993. */
  994. public T[] getEnumConstants() {
  995. return clazz.getEnumConstants();
  996. }
  997. /* (non-Javadoc)
  998. * @see org.aspectj.lang.reflect.AjType#getTypeParameters()
  999. */
  1000. public TypeVariable<Class<T>>[] getTypeParameters() {
  1001. return clazz.getTypeParameters();
  1002. }
  1003. /* (non-Javadoc)
  1004. * @see org.aspectj.lang.reflect.AjType#isEnum()
  1005. */
  1006. public boolean isEnum() {
  1007. return clazz.isEnum();
  1008. }
  1009. /* (non-Javadoc)
  1010. * @see org.aspectj.lang.reflect.AjType#isInstance(java.lang.Object)
  1011. */
  1012. public boolean isInstance(Object o) {
  1013. return clazz.isInstance(o);
  1014. }
  1015. /* (non-Javadoc)
  1016. * @see org.aspectj.lang.reflect.AjType#isInterface()
  1017. */
  1018. public boolean isInterface() {
  1019. return clazz.isInterface();
  1020. }
  1021. /* (non-Javadoc)
  1022. * @see org.aspectj.lang.reflect.AjType#isLocalClass()
  1023. */
  1024. public boolean isLocalClass() {
  1025. return clazz.isLocalClass() && !isAspect();
  1026. }
  1027. /* (non-Javadoc)
  1028. * @see org.aspectj.lang.reflect.AjType#isMemberClass()
  1029. */
  1030. public boolean isMemberClass() {
  1031. return clazz.isMemberClass() && !isAspect();
  1032. }
  1033. /* (non-Javadoc)
  1034. * @see org.aspectj.lang.reflect.AjType#isArray()
  1035. */
  1036. public boolean isArray() {
  1037. return clazz.isArray();
  1038. }
  1039. /* (non-Javadoc)
  1040. * @see org.aspectj.lang.reflect.AjType#isPrimitive()
  1041. */
  1042. public boolean isPrimitive() {
  1043. return clazz.isPrimitive();
  1044. }
  1045. /* (non-Javadoc)
  1046. * @see org.aspectj.lang.reflect.AjType#isAspect()
  1047. */
  1048. public boolean isAspect() {
  1049. return clazz.getAnnotation(Aspect.class) != null;
  1050. }
  1051. /* (non-Javadoc)
  1052. * @see org.aspectj.lang.reflect.AjType#isMemberAspect()
  1053. */
  1054. public boolean isMemberAspect() {
  1055. return clazz.isMemberClass() && isAspect();
  1056. }
  1057. public boolean isPrivileged() {
  1058. return isAspect() && clazz.isAnnotationPresent(ajcPrivileged.class);
  1059. }
  1060. @Override
  1061. public boolean equals(Object obj) {
  1062. if (!(obj instanceof AjTypeImpl)) return false;
  1063. AjTypeImpl other = (AjTypeImpl) obj;
  1064. return other.clazz.equals(clazz);
  1065. }
  1066. @Override
  1067. public int hashCode() {
  1068. return clazz.hashCode();
  1069. }
  1070. private AjType<?>[] toAjTypeArray(Class<?>[] classes) {
  1071. AjType<?>[] ajtypes = new AjType<?>[classes.length];
  1072. for (int i = 0; i < ajtypes.length; i++) {
  1073. ajtypes[i] = AjTypeSystem.getAjType(classes[i]);
  1074. }
  1075. return ajtypes;
  1076. }
  1077. private Class<?>[] toClassArray(AjType<?>[] ajTypes) {
  1078. Class<?>[] classes = new Class<?>[ajTypes.length];
  1079. for (int i = 0; i < classes.length; i++) {
  1080. classes[i] = ajTypes[i].getJavaClass();
  1081. }
  1082. return classes;
  1083. }
  1084. public String toString() { return getName(); }
  1085. }