Table of Contents
AspectJ extends Java by overlaying a concept of join points onto the existing Java semantics and by adding adds four kinds of program elements to Java:
Join points are well-defined points in the execution of a program. These include method and constructor calls, field accesses and others described below.
A pointcut picks out join points, and exposes some of the values in the execution context of those join points. There are several primitive pointcut designators, new named pointcuts can be defined by the pointcut declaration.
Advice is code that executes at each join point in a pointcut. Advice has access to the values exposed by the pointcut. Advice is defined by before, after, and around declarations.
Introduction and declaration form AspectJ's static crosscutting features, that is, is code that may change the type structure of a program, by adding to or extending interfaces and classes with new fields, constructors, or methods. Introductions are defined through an extension of usual method, field, and constructor declarations, and other declarations are made with a new declare keyword.
An aspect is a crosscutting type, that encapsulates pointcuts, advice, and static crosscutting features. By type, we mean Java's notion: a modular unit of code, with a well-defined interface, about which it is possible to do reasoning at compile time. Aspects are defined by the aspect declaration.
While aspects do define crosscutting types, 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:
When a method is called, not including super calls of non-static methods.
When the body of code for an actual method executes.
When an object is built and a constructor is called, not including this or super constructor calls. The object being constructed is returned at a constructor call join point, so it may be accessed with after returning advice.
When the non-static initializers of a class run.
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. No value is returned from constructor execution join points.
When the static initializer for a class executes.
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 from the code found in this() and super() constructor calls.
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 constructor execution join points.
When a non-final field is referenced.
When a field is assigned to.
When an exception handler executes.