While aspects define types that crosscut, the AspectJ system does not
allow completely arbitrary crosscutting. Rather, aspects define types
that cut across principled points in a program's execution. These
principled points are called join points.
A join point is a well-defined point in the execution of a
program. The join points defined by AspectJ are:
- Method call
-
When a method is called, not including super calls of
non-static methods.
- Method execution
-
When the body of code for an actual method executes.
- Constructor call
-
When an object is built and that object's initial constructor is
called (i.e., not for "super" or "this" constructor calls). The
object being constructed is returned at a constructor call join
point, so its return type is considered to be the type of the
object, and the object itself may be accessed with after
returning advice.
- Constructor execution
-
When the body of code for an actual constructor executes, after
its this or super constructor call. The object being constructed
is the currently executing object, and so may be accessed with
the this pointcut. The constructor execution
join point for a constructor that calls a super constructor also
includes any non-static initializers of enclosing class. No
value is returned from a constructor execution join point, so its
return type is considered to be void.
- Static initializer execution
-
When the static initializer for a class executes. No value is
returned from a static initializer execution join point, so its
return type is considered to be void.
- Object pre-initialization
-
Before the object initialization code for a particular class runs.
This encompasses the time between the start of its first called
constructor and the start of its parent's constructor. Thus, the
execution of these join points encompass the join points of the
evaluation of the arguments of this() and
super() constructor calls. No value is
returned from an object pre-initialization join point, so its
return type is considered to be void.
- Object initialization
-
When the object initialization code for a particular class runs.
This encompasses the time between the return of its parent's
constructor and the return of its first called constructor. It
includes all the dynamic initializers and constructors used to
create the object. The object being constructed is the currently
executing object, and so may be accessed with the
this pointcut. No value is returned from a
constructor execution join point, so its return type is
considered to be void.
- Field reference
-
When a non-constant field is referenced. [Note that references
to constant fields (static final fields bound to a constant
string object or primitive value) are not join points, since Java
requires them to be inlined.]
- Field set
-
When a field is assigned to.
Field set join points are considered to have one argument,
the value the field is being set to.
No value is returned from a field set join point, so
its return type is considered to be void.
[Note that the initializations of constant fields (static
final fields where the initializer is a constant string object or
primitive value) are not join points, since Java requires their
references to be inlined.]
- Handler execution
-
When an exception handler executes.
Handler execution join points are considered to have one argument,
the exception being handled.
No value is returned from a field set join point, so
its return type is considered to be void.
- Advice execution
-
When the body of code for a piece of advice executes.
Each join point potentially has three pieces of state associated
with it: the currently executing object, the target object, and
an object array of arguments. These are exposed by the three
state-exposing pointcuts, this,
target, and args,
respectively.
Informally, the currently executing object is the object that a
this expression would pick out at the join
point. The target object is where control or attention is
transferred to by the join point. The arguments are those
values passed for that transfer of control or attention.
* There is no executing object in static contexts such as
static method bodies or static initializers.
** There is no target object for join points associated
with static methods or fields.