Pointcuts
Methods and Constructors | |
---|---|
|
every call to any method or constructor matching
|
|
every execution of any method or constructor
matching |
Fields |
|
|
every reference to any field matching |
|
every assignment to any field matching |
Exception Handlers |
|
|
every exception handler for any |
Advice |
|
|
every execution of any piece of advice |
Initialization |
|
|
every execution of a static
initializer for any type in |
|
every initialization of an object when the
first constructor called in the type matches |
|
every pre-initialization of an object
when the first constructor called in the type matches |
Lexical |
|
|
every join point from code defined in a type in
|
|
every join point from code defined in a method
or constructor matching |
Type Patterns
A type pattern is one of
Type pattern | |
---|---|
|
all types in |
|
all types in |
|
all types in |
|
all types not in |
|
all types in both |
|
all types in either |
|
all types in |
where TypeNamePattern
can either be a plain type name, the wildcard
*
(indicating all types), or an identifier with embedded *
and ..
wildcards.
An embedded *
in an identifier matches any sequence of characters, but
does not match the package (or inner-type) separator .
.
An embedded ..
in an identifier matches any sequence of characters
that starts and ends with the package (or inner-type) separator .
.
Advice
Each piece of advice is of the form
[ strictfp ] AdviceSpec [ throws TypeList ] : Pointcut { Body }
where AdviceSpec
is one of
before( Formals )
-
runs before each join point
after( Formals ) returning [ ( Formal ) ]
-
runs after each join point that returns normally. The optional formal gives access to the returned value
after( Formals ) throwing [ ( Formal ) ]
-
runs after each join point that throws a
Throwable
. If the optional formal is present, runs only after each join point that throws aThrowable
of the type ofFormal
, andFormal
gives access to theThrowable
exception value after( Formals )
-
runs after each join point regardless of whether it returns normally or throws a
Throwable
Type around( Formals )
-
runs in place of each join point. The join point can be executed by calling
proceed
, which takes the same number and types of arguments as the around advice.
Three special variables are available inside of advice bodies:
thisJoinPoint
-
an object of type
org.aspectj.lang.JoinPoint
representing the join point at which the advice is executing thisJoinPointStaticPart
-
equivalent to
thisJoinPoint.getStaticPart()
, but may use fewer runtime resources thisEnclosingJoinPointStaticPart
-
the static part of the dynamically enclosing join point
Inter-type member declarations
Each inter-type member is one of
Modifiers ReturnType OnType . Id ( Formals ) [ throws TypeList ] { Body }
-
a method on
OnType
abstract Modifiers ReturnType OnType . Id ( Formals ) [ throws TypeList ] ;
-
an abstract method on
OnType
Modifiers OnType . new ( Formals ) [ throws TypeList ] { Body }
-
a constructor on
OnType
Modifiers Type OnType . Id [ = Expression ] ;
-
a field on
OnType
Other declarations
declare parents : TypePattern extends Type ;
-
the types in
TypePattern
extendType
declare parents : TypePattern implements TypeList ;
-
the types in
TypePattern
implement the types inTypeList
declare warning : Pointcut : String ;
-
if any of the join points in
Pointcut
possibly exist in the program, the compiler emits the warningString
declare error : Pointcut : String ;
-
if any of the join points in
Pointcut
could possibly exist in the program, the compiler emits the errorString
declare soft : Type : Pointcut ;
-
any
Type
exception that gets thrown at any join point picked out byPointcut
is wrapped inorg.aspectj.lang.SoftException
declare precedence : TypePatternList ;
-
at any join point where multiple pieces of advice apply, the advice precedence at that join point is in
TypePatternList
order
Aspects
Each aspect is of the form
[ privileged ] Modifiers aspect Id [ extends Type ] [ implements TypeList ] [ PerClause ] { Body }
where PerClause
defines how the aspect is instantiated and associated
(issingleton()
by default):
PerClause | Description | Accessor |
---|---|---|
[ |
One instance of the aspect is made. This is the default. |
|
|
An instance is associated with each object that is
the currently executing object at any join point in |
|
|
An instance is associated with each object that
is the target object at any join point in |
|
|
The aspect is defined for each entrance to the
control flow of the join points defined by |
|
|
The aspect is defined for each entrance to
the control flow below the join points defined by |
|