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.

joinpointsignatures.adoc 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. [[jpsigs]]
  2. = Join Point Signatures
  3. Many of the extensions to the AspectJ language to address the new
  4. features of Java 5 are derived from a simple set of principles for join
  5. point matching. In this section, we outline these principles as a
  6. foundation for understanding the matching rules in the presence of
  7. annotations, generics, covariance, varargs, and autoboxing.
  8. == Join Point Matching
  9. AspectJ supports 11 different kinds of join points. These are the
  10. `method call, method execution, constructor call, constructor execution, field get,
  11. field set, pre-initialization, initialization, static initialization, handler,`
  12. and `advice execution` join points.
  13. The _kinded_ pointcut designators match based on the kind of a join
  14. point. These are the `call, execution, get, set, preinitialization, initialization,
  15. staticinitialization, handler,` and `adviceexecution` designators.
  16. A kinded pointcut is written using patterns, some of which match based
  17. on _signature_, and some of which match based on _modifiers_. For
  18. example, in the `call` pointcut designator:
  19. [source, text]
  20. ....
  21. call(ModifierPattern TypePattern TypePattern.IdPattern(TypePatternList) ThrowsPattern)
  22. ....
  23. the modifiers matching patterns are `ModifierPattern` and
  24. `ThrowsPattern`, and the signature matching patterns are
  25. `TypePattern TypePattern.IdPattern(TypePatternList)`.
  26. A join point has potentially multiple signatures, but only one set of
  27. modifiers. _A kinded primitive pointcut matches a particular join point
  28. if and only if_:
  29. [arabic]
  30. . They are of the same kind
  31. . The signature pattern (exactly) matches at least one signature of the
  32. join point
  33. . The modifiers pattern matches the modifiers of the subject of the join
  34. point
  35. These rules make it very easily to quickly determine whether a given
  36. pointcut matches a given join point. In the next two sections, we
  37. describe what the signature(s) of a join point are, and what the
  38. subjects of join points are.
  39. [[join-point-signatures]]
  40. == Join Point Signatures
  41. Call, execution, get, and set join points may potentially have multiple
  42. signatures. All other join points have exactly one signature. The
  43. following table summarizes the constituent parts of a join point
  44. signature for the different kinds of join point.
  45. [cols=",,,,,,",options="header",]
  46. |===
  47. |Join Point Kind |Return Type |Declaring Type |Id |Parameter Types
  48. |Field Type |Exception Type
  49. |Method call |+ |+ |+ |+ | |
  50. |Method execution |+ |+ |+ |+ | |
  51. |Constructor call | |+ | |+ | |
  52. |Constructor execution | |+ | |+ | |
  53. |Field get | |+ |+ | |+ |
  54. |Field set | |+ |+ | |+ |
  55. |Pre-initialization | |+ | |+ | |
  56. |Initialization | |+ | |+ | |
  57. |Static initialization | |+ | | | |
  58. |Handler | | | | | |+
  59. |Advice execution | |+ | |+ | |
  60. |===
  61. Note that whilst an advice execution join point has a signature
  62. comprising the declaring type of the advice and the advice parameter
  63. types, the `adviceexecution` pointcut designator does not support
  64. matching based on this signature.
  65. The signatures for most of the join point kinds should be
  66. self-explanatory, except for field get and set, and method call and
  67. execution join points, which can have multiple signatures. Each
  68. signature of a method call or execution join point has the same id and
  69. parameter types, but the declaring type and return type (with
  70. covariance) may vary. Each signature of a field get or set join point
  71. has the same id and field type, but the declaring type may vary.
  72. The following sections examine signatures for these join points in more
  73. detail.
  74. === Method call join point signatures
  75. For a call join point where a call is made to a method
  76. `m(parameter_types)` on a target type `T` (where `T` is the static type
  77. of the target):
  78. [source, java]
  79. ....
  80. T t = new T();
  81. t.m("hello"); // <= call join point occurs when this line is executed
  82. ....
  83. Then the signature `R(T) T.m(parameter_types)` is a signature of the
  84. call join point, where `R(T)` is the return type of `m` in `T`, and
  85. `parameter_types` are the parameter types of `m`. If `T` itself does not
  86. declare a definition of `m(parameter_types)`, then `R(T)` is the return
  87. type in the definition of `m` that `T` inherits. Given the call above,
  88. and the definition of `T.m`:
  89. [source, java]
  90. ....
  91. interface Q {
  92. R m(String s);
  93. }
  94. class P implements Q {
  95. R m(String s) {...}
  96. }
  97. class S extends P {
  98. R' m(String s) {...}
  99. }
  100. class T extends S {}
  101. ....
  102. Then `R' T.m(String)` is a signature of the call join point for
  103. `t.m("hello")`.
  104. For each ancestor (super-type) `A` of `T`, if `m(parameter_types)` is
  105. defined for that super-type, then `R(A) A.m(parameter_types)` is a
  106. signature of the call join point, where `R(A)` is the return type of `
  107. m(parameter_types)` as defined in `A`, or as inherited by
  108. `A` if `A` itself does not provide a definition of `m(parameter_types)`.
  109. Continuing the example from above,we can deduce that
  110. [source, java]
  111. ....
  112. R' S.m(String)
  113. R P.m(String)
  114. R Q.m(String)
  115. ....
  116. are all additional signatures for the call join point arising from the
  117. call `t.m("hello")`. Thus this call join point has four signatures in
  118. total. Every signature has the same id and parameter types, and a
  119. different declaring type.
  120. === Method execution join point signatures
  121. Join point signatures for execution join points are defined in a similar
  122. manner to signatures for call join points. Given the hierarchy:
  123. [source, java]
  124. ....
  125. interface Q {
  126. R m(String s);
  127. }
  128. class P implements Q {
  129. R m(String s) {...}
  130. }
  131. class S extends P {
  132. R' m(String s) {...}
  133. }
  134. class T extends S { }
  135. class U extends T {
  136. R' m(String s) {...}
  137. }
  138. ....
  139. Then the execution join point signatures arising as a result of the call
  140. to `u.m("hello")` are:
  141. [source, java]
  142. ....
  143. R' U.m(String)
  144. R' S.m(String)
  145. R P.m(String)
  146. R Q.m(String)
  147. ....
  148. Each signature has the same id and parameter types, and a different
  149. declaring type. There is one signature for each type that provides its
  150. own declaration of the method. Hence in this example there is no
  151. signature `R' T.m(String)` as `T` does not provide its own declaration
  152. of the method.
  153. === Field get and set join point signatures
  154. For a field get join point where an access is made to a field `f` of
  155. type `F` on a object with declared type `T`, then `F T.f` is a signature
  156. of the get join point.
  157. If `T` does not directly declare a member `f`, then for each super type
  158. `S` of `T`, up to and including the most specific super type of `T` that
  159. does declare the member `f`, `F S.f` is a signature of the join point.
  160. For example, given the hierarchy:
  161. [source, java]
  162. ....
  163. class P {
  164. F f;
  165. }
  166. class S extends P {
  167. F f;
  168. }
  169. class T extends S { }
  170. ....
  171. Then the join point signatures for a field get join point of the field
  172. `f` on an object with declared type `T` are:
  173. [source, java]
  174. ....
  175. F S.f
  176. F T.f
  177. ....
  178. The signatures for a field set join point are derived in an identical
  179. manner.
  180. == Join Point Modifiers
  181. Every join point has a single set of modifiers - these include the
  182. standard Java modifiers such as `public`, `private`, `static`, `abstract` etc.,
  183. any annotations, and the `throws` clauses of methods and constructors.
  184. These modifiers are the modifiers of the _subject_ of the join point.
  185. The following table defines the join point subject for each kind of join
  186. point.
  187. [cols=",",options="header",]
  188. |===
  189. |Join Point Kind |Subject
  190. |Method call |The method picked out by Java as the static target of the
  191. method call.
  192. |Method execution |The method that is executing.
  193. |Constructor call |The constructor being called.
  194. |Constructor execution |The constructor executing.
  195. |Field get |The field being accessed.
  196. |Field set |The field being set.
  197. |Pre-initialization |The first constructor executing in this constructor
  198. chain.
  199. |Initialization |The first constructor executing in this constructor
  200. chain.
  201. |Static initialization |The type being initialized.
  202. |Handler |The declared type of the exception being handled.
  203. |Advice execution |The advice being executed.
  204. |===
  205. For example, given the following types
  206. [source, java]
  207. ....
  208. public class X {
  209. @Foo
  210. protected void doIt() {...}
  211. }
  212. public class Y extends X {
  213. public void doIt() {...}
  214. }
  215. ....
  216. Then the modifiers for a call to `(Y y) y.doIt()` are simply `{ public }`.
  217. The modifiers for a call to `(X x) x.doIt()` are `{ @Foo, protected }`.
  218. [[join-point-matching-summary]]
  219. == Summary of Join Point Matching
  220. A join point has potentially multiple signatures, but only one set of
  221. modifiers. _A kinded primitive pointcut matches a particular join point
  222. if and only if_:
  223. [arabic]
  224. . They are of the same kind
  225. . The signature pattern (exactly) matches at least one signature of the
  226. join point
  227. . The modifiers pattern matches the modifiers of the subject of the join
  228. point
  229. Given the hierarchy
  230. [source, java]
  231. ....
  232. interface Q {
  233. R m(String s);
  234. }
  235. class P implements Q {
  236. @Foo
  237. public R m(String s) {...}
  238. }
  239. class S extends P {
  240. @Bar
  241. public R' m(String s) {...}
  242. }
  243. class T extends S {}
  244. ....
  245. and the program fragment:
  246. [source, java]
  247. ....
  248. P p = new P();
  249. S s = new S();
  250. T t = new T();
  251. ...
  252. p.m("hello");
  253. s.m("hello");
  254. t.m("hello");
  255. ....
  256. The the pointcut `call(@Foo R P.m(String))` matches the call
  257. `p.m("hello")` since both the signature and the modifiers match. It does
  258. not match the call `s.m("hello")` because even though the signature
  259. pattern matches one of the signatures of the join point, the modifiers
  260. pattern does not match the modifiers of the method m in S which is the
  261. static target of the call.
  262. The pointcut `call(R' m(String))` matches the calls `t.m("hello")` and
  263. `s.m("hello")`. It does not match the call `p.m("hello")` since the
  264. signature pattern does not match any signature for the call join point
  265. of m in P.