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.

AjType.java 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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.lang.reflect;
  13. import java.lang.reflect.AnnotatedElement;
  14. import java.lang.reflect.Constructor;
  15. import java.lang.reflect.Field;
  16. import java.lang.reflect.Method;
  17. import java.lang.reflect.Type;
  18. import java.lang.reflect.TypeVariable;
  19. /**
  20. * The runtime representation of a type (Aspect, Class, Interface, Annotation, Enum, or Array) in an AspectJ
  21. * program.
  22. */
  23. public interface AjType<T> extends Type, AnnotatedElement {
  24. /**
  25. * @return the name of this type, in the same format as returned by Class.getName()
  26. */
  27. public String getName();
  28. /**
  29. * @return the package in which this type is declared
  30. */
  31. public Package getPackage();
  32. /**
  33. * @return the interfaces implemented by this type
  34. */
  35. public AjType<?>[] getInterfaces();
  36. /**
  37. * @return the modifiers declared for this type. The return value can be interpreted
  38. * using java.lang.reflect.Modifier
  39. */
  40. public int getModifiers();
  41. /**
  42. * @return the java.lang.Class that corresponds to this AjType
  43. */
  44. public Class<T> getJavaClass();
  45. // scope
  46. /**
  47. * @return the supertype of this type. If this type represents Object or a primitive type
  48. * then null is returned.
  49. */
  50. public AjType<?> getSupertype();
  51. /**
  52. * @return the generic supertype of this type, as defined by Class.getGenericSupertype
  53. */
  54. public Type getGenericSupertype();
  55. /**
  56. * @return the enclosing Method if this type represents a local or anonymous type declared within a method
  57. */
  58. public Method getEnclosingMethod();
  59. /**
  60. * @return the enclosing Method if this type represents a local or anonymous type declared within a constructor
  61. */
  62. public Constructor getEnclosingConstructor();
  63. /**
  64. * @return the immediately enclosing type of this type.
  65. */
  66. public AjType<?> getEnclosingType();
  67. /**
  68. * @return the AjType representing the typei n which it was declared (if this type is a member of another type)
  69. */
  70. public AjType<?> getDeclaringType();
  71. /**
  72. * @return the per-clause if this is an aspect, otherwise null
  73. */
  74. public PerClause getPerClause();
  75. // inner types
  76. /**
  77. * @return an array containing all the public types that are members of this type
  78. */
  79. public AjType<?>[] getAjTypes();
  80. /**
  81. * @return an array containing all the types declared by this type
  82. */
  83. public AjType<?>[] getDeclaredAjTypes();
  84. // constructors
  85. /**
  86. * @param parameterTypes the types of the constructor parameters
  87. * @return the constructor object for the specified public constructor of this type
  88. * @throws NoSuchMethodException if constructor not found
  89. */
  90. public Constructor getConstructor(AjType<?>... parameterTypes) throws NoSuchMethodException;
  91. /**
  92. * @return all of the public constructors of this type
  93. */
  94. public Constructor[] getConstructors();
  95. /**
  96. * @param parameterTypes the types of the constructor parameters
  97. * @return the constructor object for the specified constructor of this type
  98. * @throws NoSuchMethodException if constructor not found
  99. */
  100. public Constructor getDeclaredConstructor(AjType<?>... parameterTypes) throws NoSuchMethodException;
  101. /**
  102. * @return all the constructors declared in this type
  103. */
  104. public Constructor[] getDeclaredConstructors();
  105. // fields
  106. /**
  107. * @param name the field name
  108. * @return the declared field
  109. * @throws NoSuchFieldException if no field of that name is found
  110. */
  111. public Field getDeclaredField(String name) throws NoSuchFieldException;
  112. /**
  113. * @return all the fields declared in this type
  114. */
  115. public Field[] getDeclaredFields();
  116. /**
  117. * @param name the field name
  118. * @return the public field with the given name
  119. * @throws NoSuchFieldException if field not found
  120. */
  121. public Field getField(String name) throws NoSuchFieldException;
  122. /**
  123. * @return the public fields declared by this type
  124. */
  125. public Field[] getFields();
  126. // methods
  127. /**
  128. * @param name the method name
  129. * @param parameterTypes the types of the method parameters
  130. * @return the method object for the specified method declared in this type
  131. * @throws NoSuchMethodException if the method cannot be found
  132. */
  133. public Method getDeclaredMethod(String name, AjType<?>... parameterTypes) throws NoSuchMethodException;
  134. /**
  135. * @param name the method name
  136. * @param parameterTypes the types of the method parameters
  137. * @return the method object for the specified public method declared in this type
  138. * @throws NoSuchMethodException if the method cannot be found
  139. */
  140. public Method getMethod(String name, AjType<?>... parameterTypes) throws NoSuchMethodException;
  141. /**
  142. * @return all the methods declared by this type
  143. */
  144. public Method[] getDeclaredMethods();
  145. /**
  146. * @return all the public methods of this type
  147. */
  148. public Method[] getMethods();
  149. // pointcuts
  150. /**
  151. * @param name the pointcut name
  152. * @return the pointcut object representing the specified pointcut declared by this type
  153. * @throws NoSuchPointcutException if no pointcut of that name can be found
  154. */
  155. public Pointcut getDeclaredPointcut(String name) throws NoSuchPointcutException;
  156. /**
  157. * @param name the pointcut name
  158. * @return the pointcut object representing the specified public pointcut
  159. * @throws NoSuchPointcutException if no pointcut of that name can be found
  160. */
  161. public Pointcut getPointcut(String name) throws NoSuchPointcutException;
  162. /**
  163. * @return all of the pointcuts declared by this type
  164. */
  165. public Pointcut[] getDeclaredPointcuts();
  166. /**
  167. * @return all of the public pointcuts of this type
  168. */
  169. public Pointcut[] getPointcuts();
  170. // advice
  171. /**
  172. * @param ofTypes the {@link AdviceKind}s of interest
  173. * @return all of the advice declared by this type, of an advice kind contained in the
  174. * parameter list.
  175. */
  176. public Advice[] getDeclaredAdvice(AdviceKind... ofTypes);
  177. /**
  178. * @param ofTypes the {@link AdviceKind}s of interest
  179. * @return all of the advice for this type, of an advice kind contained in the parameter
  180. * list.
  181. */
  182. public Advice[] getAdvice(AdviceKind... ofTypes);
  183. /**
  184. * For an annotation style advice member,
  185. * this is the name of the annotated method. For a code-style advice declaration, this
  186. * is the name given in the @AdviceName annotation if present.
  187. *
  188. * @param name the advice name
  189. * @return the advice with the given name.
  190. * @throws NoSuchAdviceException if no advice can be found with that name
  191. */
  192. public Advice getAdvice(String name) throws NoSuchAdviceException;
  193. /** For an annotation style advice member,
  194. * this is the name of the annotated method. For a code-style advice declaration, this
  195. * is the name given in the @AdviceName annotation if present.
  196. *
  197. * @param name the advice name
  198. * @return the advice declared in this type with the given name.
  199. * @throws NoSuchAdviceException if no advice can be found with that name
  200. */
  201. public Advice getDeclaredAdvice(String name) throws NoSuchAdviceException;
  202. // inter-type declarations
  203. /**
  204. * @param name the method name
  205. * @param target the target of the inter-type declaration
  206. * @param parameterTypes the types of the inter-type method declaration
  207. * @return the inter-type method declared by this type matching the given specification
  208. * @throws NoSuchMethodException if the inter-type declaration cannot be found
  209. */
  210. public InterTypeMethodDeclaration getDeclaredITDMethod(String name, AjType<?> target, AjType<?>... parameterTypes) throws NoSuchMethodException;
  211. /**
  212. * @return all of the inter-type methods declared by this type
  213. */
  214. public InterTypeMethodDeclaration[] getDeclaredITDMethods();
  215. /**
  216. * @param name the method name
  217. * @param target the target of the inter-type declaration
  218. * @param parameterTypes the types of the inter-type method declaration
  219. * @return the public inter-type method of this type matching the given specification
  220. * @throws NoSuchMethodException if the inter-type declaration cannot be found
  221. */
  222. public InterTypeMethodDeclaration getITDMethod(String name, AjType<?> target, AjType<?>... parameterTypes) throws NoSuchMethodException;
  223. /**
  224. * @return all of the public inter-type declared methods of this type
  225. */
  226. public InterTypeMethodDeclaration[] getITDMethods();
  227. /**
  228. * @param target the target of the inter-type constructor of interest
  229. * @param parameterTypes the types of the parameter of the inter-type constructor of interest
  230. * @return the inter-type constructor declared by this type matching the given specification
  231. * @throws NoSuchMethodException if the inter-type declaration cannot be found
  232. */
  233. public InterTypeConstructorDeclaration getDeclaredITDConstructor(AjType<?> target, AjType<?>... parameterTypes) throws NoSuchMethodException;
  234. /**
  235. * @return all of the inter-type constructors declared by this type
  236. */
  237. public InterTypeConstructorDeclaration[] getDeclaredITDConstructors();
  238. /**
  239. * @param target the target of the inter-type constructor of interest
  240. * @param parameterTypes the types of the parameter of the inter-type constructor of interest
  241. * @return the public inter-type constructor matching the given specification
  242. * @throws NoSuchMethodException if the inter-type declaration cannot be found
  243. */
  244. public InterTypeConstructorDeclaration getITDConstructor(AjType<?> target, AjType<?>... parameterTypes) throws NoSuchMethodException;
  245. /**
  246. * @return all of the public inter-type constructors of this type
  247. */
  248. public InterTypeConstructorDeclaration[] getITDConstructors();
  249. /**
  250. * @param name the field name
  251. * @param target the target type for the inter-type declaration
  252. * @return the inter-type field declared in this type with the given specification
  253. * @throws NoSuchFieldException if the inter-type declaration cannot be found
  254. */
  255. public InterTypeFieldDeclaration getDeclaredITDField(String name, AjType<?> target) throws NoSuchFieldException;
  256. /**
  257. * @return all of the inter-type fields declared in this type
  258. */
  259. public InterTypeFieldDeclaration[] getDeclaredITDFields();
  260. /**
  261. * @param name the field name
  262. * @param target the target type for the inter-type declaration
  263. * @return the public inter-type field matching the given specification
  264. * @throws NoSuchFieldException if the inter-type declaration cannot be found
  265. */
  266. public InterTypeFieldDeclaration getITDField(String name, AjType<?> target) throws NoSuchFieldException;
  267. /**
  268. * @return all of the public inter-type fields for this type
  269. */
  270. public InterTypeFieldDeclaration[] getITDFields();
  271. // declare statements
  272. /**
  273. * @return all of the declare error and declare warning members of this type,
  274. * including declare error/warning members inherited from super-types
  275. */
  276. public DeclareErrorOrWarning[] getDeclareErrorOrWarnings();
  277. /**
  278. * @return all of the declare parents members of this type, including
  279. * declare parent members inherited from super-types
  280. */
  281. public DeclareParents[] getDeclareParents();
  282. /**
  283. * @return all of the declare soft members of this type, including declare
  284. * soft members inherited from super-types
  285. */
  286. public DeclareSoft[] getDeclareSofts();
  287. /**
  288. * @return all of the declare annotation members of this type, including declare
  289. * annotation members inherited from super-types
  290. */
  291. public DeclareAnnotation[] getDeclareAnnotations();
  292. /**
  293. * @return all of the declare precedence members of this type, including declare
  294. * precedence members inherited from super-types
  295. */
  296. public DeclarePrecedence[] getDeclarePrecedence();
  297. // misc
  298. /**
  299. * @return the elements of this enum class, or null if this type does not represent
  300. * an enum type.
  301. */
  302. public T[] getEnumConstants();
  303. /**
  304. * @return an array of TypeVariable objects that represent the type variables declared by
  305. * this type (if any)
  306. */
  307. public TypeVariable<Class<T>>[] getTypeParameters();
  308. /**
  309. * @return true if this is an enum type
  310. */
  311. public boolean isEnum();
  312. /**
  313. * @param o the object to check for assignment compatibility
  314. * @return true if the given object is assignment-compatible with an object of the type represented
  315. * by this AjType
  316. */
  317. public boolean isInstance(Object o);
  318. /**
  319. * @return true if this is an interface type
  320. */
  321. public boolean isInterface();
  322. /**
  323. * @return true if and only if the underlying type is a local class
  324. */
  325. public boolean isLocalClass();
  326. /**
  327. * @return true if and only if the underlying type is a member class
  328. */
  329. public boolean isMemberClass();
  330. /**
  331. * @return true if this is an array type
  332. */
  333. public boolean isArray();
  334. /**
  335. * @return true if this object represents a primitive type
  336. */
  337. public boolean isPrimitive();
  338. /**
  339. * @return true if this is an aspect type
  340. */
  341. public boolean isAspect();
  342. /**
  343. * @return true if and only if the underlying type is a member aspect
  344. */
  345. public boolean isMemberAspect();
  346. /**
  347. * @return true if and only if the underlying type is a privileged aspect
  348. */
  349. public boolean isPrivileged();
  350. }