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.

quickreference.adoc 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. [[quick]]
  2. = AspectJ Quick Reference
  3. [[quick-pointcuts]]
  4. == Pointcuts
  5. [cols=",",]
  6. |===
  7. |*Methods and Constructors* |
  8. |`call(Signature)` |every call to any method or constructor matching
  9. `Signature` at the call site
  10. |`execution(Signature)` |every execution of any method or constructor
  11. matching `Signature`
  12. |*Fields* |
  13. |`get(Signature)` |every reference to any field matching `Signature`
  14. |`set(Signature)` |every assignment to any field matching `Signature`.
  15. The assigned value can be exposed with an `args` pointcut
  16. |*Exception Handlers* |
  17. |`handler(TypePattern)` |every exception handler for any `Throwable`
  18. type in `TypePattern`. The exception value can be exposed with an `args`
  19. pointcut
  20. |*Advice* |
  21. |`adviceexecution()` |every execution of any piece of advice
  22. |*Initialization* |
  23. |`staticinitialization(TypePattern)` |every execution of a static
  24. initializer for any type in `TypePattern`
  25. |`initialization(Signature)` |every initialization of an object when the
  26. first constructor called in the type matches `Signature`, encompassing
  27. the return from the super constructor call to the return of the
  28. first-called constructor
  29. |`preinitialization(Signature)` |every pre-initialization of an object
  30. when the first constructor called in the type matches `Signature`,
  31. encompassing the entry of the first-called constructor to the call to
  32. the super constructor
  33. |*Lexical* |
  34. |`within(TypePattern)` |every join point from code defined in a type in
  35. `TypePattern`
  36. |`withincode(Signature)` |every join point from code defined in a method
  37. or constructor matching `Signature`
  38. |===
  39. [[quick-typePatterns]]
  40. == Type Patterns
  41. A type pattern is one of
  42. [cols=",",]
  43. |===
  44. |*Type pattern* |
  45. |`TypeNamePattern` |all types in `TypeNamePattern`
  46. |`SubtypePattern` |all types in `SubtypePattern`, a pattern with a `+`
  47. |`ArrayTypePattern` |all types in `ArrayTypePattern`, a pattern with one or more ``[]``s.
  48. |`!TypePattern` |all types not in `TypePattern`
  49. |`TypePattern0 && TypePattern1` |all types in both `TypePattern0` and `TypePattern1`
  50. |`TypePattern0 \|\| TypePattern1` |all types in either `TypePattern0` or `TypePattern1`
  51. |`( TypePattern )` |all types in `TypePattern`
  52. |===
  53. where `TypeNamePattern` can either be a plain type name, the wildcard
  54. `\*` (indicating all types), or an identifier with embedded `*` and `..`
  55. wildcards.
  56. An embedded `*` in an identifier matches any sequence of characters, but
  57. does not match the package (or inner-type) separator `.`.
  58. An embedded `..` in an identifier matches any sequence of characters
  59. that starts and ends with the package (or inner-type) separator `.`.
  60. [[quick-advice]]
  61. == Advice
  62. Each piece of advice is of the form
  63. [source, text]
  64. ....
  65. [ strictfp ] AdviceSpec [ throws TypeList ] : Pointcut { Body }
  66. ....
  67. where `AdviceSpec` is one of
  68. `before( Formals )`::
  69. runs before each join point
  70. `after( Formals ) returning [ ( Formal ) ]`::
  71. runs after each join point that returns normally. The optional formal
  72. gives access to the returned value
  73. `after( Formals ) throwing [ ( Formal ) ]`::
  74. runs after each join point that throws a `Throwable`.
  75. If the optional formal is present, runs only after each join point
  76. that throws a `Throwable` of the type of `Formal`, and `Formal` gives access to the
  77. `Throwable` exception value
  78. `after( Formals )`::
  79. runs after each join point regardless of whether it returns normally
  80. or throws a `Throwable`
  81. `Type around( Formals )`::
  82. runs in place of each join point. The join point can be executed by
  83. calling `proceed`, which takes the same number and types of arguments as the around
  84. advice.
  85. Three special variables are available inside of advice bodies:
  86. `thisJoinPoint`::
  87. an object of type `org.aspectj.lang.JoinPoint` representing the join point
  88. at which the advice is executing
  89. `thisJoinPointStaticPart`::
  90. equivalent to `thisJoinPoint.getStaticPart()`, but may use fewer runtime resources
  91. `thisEnclosingJoinPointStaticPart`::
  92. the static part of the dynamically enclosing join point
  93. [[quick-interType]]
  94. == Inter-type member declarations
  95. Each inter-type member is one of
  96. `Modifiers ReturnType OnType . Id ( Formals ) [ throws TypeList ] { Body }`::
  97. a method on `OnType`
  98. `abstract Modifiers ReturnType OnType . Id ( Formals ) [ throws TypeList ] ;`::
  99. an abstract method on `OnType`
  100. `Modifiers OnType . new ( Formals ) [ throws TypeList ] { Body }`::
  101. a constructor on `OnType`
  102. `Modifiers Type OnType . Id [ = Expression ] ;`::
  103. a field on `OnType`
  104. [[quick-other]]
  105. == Other declarations
  106. `declare parents : TypePattern extends Type ;`::
  107. the types in `TypePattern` extend `Type`
  108. `declare parents : TypePattern implements TypeList ;`::
  109. the types in `TypePattern` implement the types in `TypeList`
  110. `declare warning : Pointcut : String ;`::
  111. if any of the join points in `Pointcut` possibly exist in the program,
  112. the compiler emits the warning `String`
  113. `declare error : Pointcut : String ;`::
  114. if any of the join points in `Pointcut` could possibly exist in the program,
  115. the compiler emits the error `String`
  116. `declare soft : Type : Pointcut ;`::
  117. any `Type` exception that gets thrown at any join point picked out by `Pointcut`
  118. is wrapped in `org.aspectj.lang.SoftException`
  119. `declare precedence : TypePatternList ;`::
  120. at any join point where multiple pieces of advice apply, the advice
  121. precedence at that join point is in `TypePatternList` order
  122. [[quick-aspectAssociations]]
  123. == Aspects
  124. Each aspect is of the form
  125. [source, text]
  126. ....
  127. [ privileged ] Modifiers aspect Id [ extends Type ] [ implements TypeList ] [ PerClause ] { Body }
  128. ....
  129. where `PerClause` defines how the aspect is instantiated and associated
  130. (`issingleton()` by default):
  131. [cols=",,",options="header",]
  132. |===
  133. |PerClause |Description |Accessor
  134. |[ `issingleton()` ] |One instance of the aspect is made. This is the
  135. default. |`aspectOf()` at all join points
  136. |`perthis(Pointcut)` |An instance is associated with each object that is
  137. the currently executing object at any join point in `Pointcut`.
  138. |`aspectOf(Object)` at all join points
  139. |`pertarget(Pointcut)` |An instance is associated with each object that
  140. is the target object at any join point in `Pointcut`.
  141. |`aspectOf(Object)` at all join points
  142. |`percflow(Pointcut)` |The aspect is defined for each entrance to the
  143. control flow of the join points defined by `Pointcut`. |`aspectOf()` at
  144. join points in `cflow(Pointcut)`
  145. |`percflowbelow(Pointcut)` |The aspect is defined for each entrance to
  146. the control flow below the join points defined by `Pointcut`.
  147. |`aspectOf()` at join points in `cflowbelow(Pointcut)`
  148. |===