AspectJ Quick Reference AspectJsemantics quick reference Pointcut Designators Pointcut Designators Methods and Constructors call(Signature) Method or constructor call join points when the signature matches Signature execution(Signature) Method or constructor execution join points when the signature matches Signature initialization(Signature) Object initialization join point when the first constructor called in the type matches Signature Exception Handlers handler(TypePattern) Exception handler execution join points when try handlers for the throwable types in TypePattern are executed. The exception object can be accessed with an args pointcut. Fields get(Signature) Field reference join points when the field matches Signature set(Signature) Field assignment join points when the field matches Signature. The new value can be accessed with an args pointcut. Static Initializers staticinitialization(TypePattern) Static initializer execution join points for the types in TypePattern. Objects this(TypePattern) Join points when the currently executing object is an instance of a type in TypePattern target(TypePattern) Join points when the target object is an instance of a type in TypePattern args(TypePattern, ...) Join points when the argument objects are instances of the TypePatterns Lexical Extents within(TypePattern) Join points when the code executing is defined in the types in TypePattern withincode(Signature) Join points when the code executing is defined in the method or constructor with signature Signature Control Flow cflow(Pointcut) Join points in the control flow of the join points specified by Pointcut cflowbelow(Pointcut) Join points in the control flow below the join points specified by Pointcut Conditional if(Expression) Join points when the boolean Expression evaluates to true Combination ! Pointcut Join points that are not picked out by Pointcut Pointcut0 Pointcut1 Join points that are picked out by both Pointcut0 and Pointcut1 Pointcut0 || Pointcut1 Join points that are picked out by either Pointcut0 or Pointcut1 ( Pointcut ) Join points that are picked out by the parenthesized Pointcut
Type Patterns Type Name Patterns * alone all types * in an identifier any sequence of characters, not including "." .. in an identifier any sequence of characters starting and ending with "."
The + wildcard can be appended to a type name pattern to indicate all subtypes. Any number of []s can be put on a type name or subtype pattern to indicate array types. Type Patterns TypeNamePattern all types in TypeNamePattern SubtypePattern all types in SubtypePattern, a pattern with a +. ArrayTypePattern all types in ArrayTypePattern, a pattern with one or more []s. !TypePattern all types not in TypePattern TypePattern0 TypePattern1 all types in both TypePattern0 and TypePattern1 TypePattern0 || TypePattern1 all types in either TypePattern0 or TypePattern1 ( TypePattern ) all types in TypePattern
Advice Advice before(Formals) : Run before the join point. after(Formals) returning [ (Formal) ] : Run after the join point if it returns normally. The optional formal gives access to the returned value. after(Formals) throwing [ (Formal) ] : Run after the join point if it throws an exception. The optional formal gives access to the Throwable exception value. after(Formals) : Run after the join point both when it returns normally and when it throws an exception. Type around(Formals) [ throws TypeList ] : Run instead of the join point. The join point can be executed by calling proceed.
Static Crosscutting Introduction Modifiers Type TypePattern.Id(Formals) { Body } Defines a method on the types in TypePattern. abstract Modifiers Type TypePattern.Id(Formals); Defines an abstract method on the types in TypePattern. Modifiers TypePattern.new(Formals) { Body } Defines a a constructor on the types in TypePattern. Modifiers Type TypePattern.Id [ = Expression ]; Defines a field on the types in TypePattern.
Other declarations declare parents: TypePattern extends TypeList; Declares that the types in TypePattern extend the types of TypeList. declare parents: TypePattern implements TypeList; Declares that the types in TypePattern implement the types of TypeList. declare warning: Pointcut: String; Declares that if any of the join points in Pointcut possibly exist in the program, the compiler should emit a warning of String. declare error: Pointcut: String; Declares that if any of the join points in Pointcut possibly exist in the program, the compiler should emit an error of String. declare soft: TypePattern: Pointcut; Declares that any exception of a type in TypePattern that gets thrown at any join point picked out by Pointcut will be wrapped in org.aspectj.lang.SoftException.
Aspect Associations Associations modifier Description Accessor [ issingleton ] One instance of the aspect is made. This is the default. aspectOf() at all join points perthis(Pointcut) An instance is associated with each object that is the currently executing object at any join point in Pointcut. aspectOf(Object) at all join points pertarget(Pointcut) An instance is associated with each object that is the target object at any join point in Pointcut. aspectOf(Object) at all join points percflow(Pointcut) The aspect is defined for each entrance to the control flow of the join points defined by Pointcut. aspectOf() at join points in cflow(Pointcut) percflowbelow(Pointcut) The aspect is defined for each entrance to the control flow below the join points defined by Pointcut. aspectOf() at join points in cflowbelow(Pointcut)