int around () : call(int Foo.m(int)) { ... } runs instead of calls to int Foo.m(int) , and returns an int . In the AspectJ 5 Quick Reference body, continue the call by using proceed (), which has the same Aspects at top-level (or static in types) signature as the around . int around () throws IOException : call(int Foo.m(int)) { ... } aspect A { … } same, but the body is allowed to throw IOException defines the aspect A Object around () : call(int Foo.m(int)) { ... } privileged aspect A { … } same, but the value of proceed () is converted to an Integer , and A can access private fields and methods the body should also return an Integer which will be converted aspect A extends B implements I, J { … } into an int B is a class or abstract aspect, I and J are interfaces aspect A percflow ( call(void Foo.m()) ) { … } general form: an instance of A is instantiated for every control flow through [ strictfp ] AdviceSpec [ throws TypeList ] : { Body } calls to m() where AdviceSpec is one of before ( Formals ) general form: after ( Formals ) [ privileged ] [ Modifiers ] aspect Id after ( Formals ) returning [ ( Formal ) ] [ extends Type ] [ implements TypeList ] [ PerClause ] after ( Formals ) throwing [ ( Formal ) ] { Body } Type around ( Formals ) where PerClause is one of pertarget ( Pointcut ) Special forms in advice perthis ( Pointcut ) percflow ( Pointcut ) thisJoinPoint percflowbelow ( Pointcut ) reflective information about the . pertypewithin ( TypePattern ) thisJoinPointStaticPart issingleton () the equivalent of thisJoinPoint.getStaticPart() , but may use fewer resources. Pointcut definitions in types thisEnclosingJoinPointStaticPart the static part of the join point enclosing this one. private pointcut pc () : call(void Foo.m()) ; a pointcut visible only from the defining type proceed ( Arguments ) pointcut pc (int i ) : set(int Foo.x) && args(i) ; only available in around advice. The Arguments must be the a package-visible pointcut that exposes an int . same number and type as the parameters of the advice. public abstract pointcut pc () ; an abstract pointcut that can be referred to from anywhere. Inter-type Member Declarations in aspects abstract pointcut pc (Object o ) ; an abstract pointcut visible from the defining package. Any int Foo . m ( int i ) { ... } pointcut that implements this must expose an Object . a method int m(int) owned by Foo , visible anywhere in the defining package. In the body, this refers to the instance of Foo , general form: not the aspect. abstract [ Modifiers ] pointcut Id ( Formals ) ; private int Foo . m ( int i ) throws IOException { ... } [Modifiers ] pointcut Id ( Formals ) : Pointcut ; a method int m(int) that is declared to throw IOException, only visible in the defining aspect. In the body, this refers to the Advice declarations in aspects instance of Foo , not the aspect. abstract int Foo . m ( int i ) ; before () : get(int Foo.y) { ... } an abstract method int m(int) owned by Foo runs before reading the field int Foo.y Point . new ( int x, int y ) { ... } after () returning : call(int Foo.m(int)) { ... } a constructor owned by Point . In the body, this refers to the new runs after calls to int Foo.m(int) that return normally Point , not the aspect. after () returning ( int x ) : call(int Foo.m(int)) { ... } private static int Point . x ; same, but the return value is named x in the body a static int field named x owned by Point and visible only in the after () throwing : call(int Foo.m(int)) { ... } declaring aspect runs after calls to m that exit abruptly by throwing an exception private int Point . x = foo() ; after () throwing ( NotFoundException e ) : call(int Foo.m(int)) { ... } a non-static field initialized to the result of calling foo() . In the runs after calls to m that exit abruptly by throwing a initializer, this refers to the instance of Foo , not the aspect. NotFoundException . The exception is named e in the body after () : call(int Foo.m(int)) { ... } general form: runs after calls to m regardless of how they exit [ Modifiers ] Type Type . Id ( Formals ) before (int i ) : set(int Foo.x) && args(i) { ... } [ throws TypeList ] { Body } runs before field assignment to int Foo.x . The value to be abstract [ Modifiers ] Type Type . Id ( Formals ) assigned is named i in the body [ throws TypeList ] ; before (Object o ) : set(* Foo.*) && args(o) { ... } [ Modifiers ] Type . new ( Formals ) runs before field assignment to any field of Foo . The value to be [ throws TypeList ] { Body } assigned is converted to an object type ( int to Integer, for [ Modifiers ] Type Type . Id [ = Expression ] ; example) and named o in the body

Other Inter-type Declarations in aspects when an IOException or its subtype is handled with a catch block adviceexecution() declare parents : C extends D; the execution of all advice bodies declares that the superclass of C is D. This is only legal if D is within ( com.bigboxco.* ) declared to extend the original superclass of C. any join point where the associated code is defined in the declare parents : C implements I, J ; package com.bigboxco C implements I and J withincode ( void Figure.move() ) declare warning : set(* Point.*) && !within(Point) : “bad set” ; any join point where the associated code is defined in the method the compiler warns “bad set” if it finds a set to any field of void Figure.move() Point outside of the code for Point withincode ( com.bigboxco.*.new(..) ) declare error : call(Singleton.new(..)) : “bad construction” ; any join point where the associated code is defined in any the compiler signals an error “bad construction” if it finds a call constructor in the package com.bigoxco. to any constructor of Singleton cflow ( call(void Figure.move()) ) declare soft : IOException : execution(Foo.new(..)) ; any join point in the control flow of each call to void any IOException thrown from executions of the constructors of Figure.move(). This includes the call itself. Foo are wrapped in org..SoftException cflowbelow ( call(void Figure.move()) ) declare precedence : Security, Logging, * ; any join point below the control flow of each call to void at each join point, advice from Security has precedence over Figure.move(). This does not include the call. advice from Logging , which has precedence over other advice. if ( Tracing.isEnabled() ) declare @type : C : @SomeAnnotation; any join point where Tracing.isEnabled() is true . The boolean declares the annotation “@SomeAnnotation” on the type C. expression used can only access static members, variables bound declare @method : * C.foo*(..) : @SomeAnnotation; in the same pointcut, and thisJoinPoint forms. declares the annotation “@SomeAnnotation” on all methods declared in C starting with “foo”. this ( Point ) declare @constructor : C.new(..) : @SomeAnnotation; any join point where the currently executing object is an instance declares the annotation “@SomeAnnotation” on all constructors of Point declared in C. target ( java.io.InputPort ) declare @field : * C.* : @SomeAnnotation; any join point where the target object is an instance of declares the annotation “@SomeAnnotation” on all fields java.io.InputPort declared in C. args ( java.io.InputPort, int ) any join point where there are two arguments, the first an general form instance of java.io.InputPort, and the second an int declare parents : TypePat extends Type ; args ( *, int ) declare parents : TypePat implements TypeList ; any join point where there are two arguments, the second of declare warning : Pointcut : String ; which is an int. declare error : Pointcut : String ; args ( short, .., short ) declare soft : Type : Pointcut ; any join point with at least two arguments, the first and last of declare precedence : TypePatList ; which are short s declare @type : TypePat : Annotation; Note: any position in this , target , and args can be replaced with a declare @method : MethodPat : Annotation; variable bound in the advice or pointcut. declare @constructor : ConstructorPat : Annotation; declare @field : FieldPat : Annotation; @this ( SomeAnnotation ) any join point where the type of the currently executing object Primitive has an annotation of type SomeAnnotation @target ( SomeAnnotation ) call ( void Foo.m(int) ) any join point where the type of the target object has an a call to the method void Foo.m(int) annotation of type SomeAnnotation call ( Foo.new(..) ) @args (SomeAnnotation ) a call to any constructor of Foo any join point where there is one argument, and the type of the execution ( * Foo.*(..) throws IOException ) argument has an annotation of type SomeAnnotation the execution of any method of Foo that is declared to throw @args (*, SomeAnnotation ) IOException any join point where there are two arguments, the type of the execution ( !public Foo .new(..) ) second having an annotation of type SomeAnnotation the execution of any non-public constructor of Foo @args (SomeAnnotation ,.., SomeOtherAnnotation ) initialization ( Foo.new(int) ) any join point with at least three arguments, the type of the first the initialization of any Foo object that is started with the having an annotation of type SomeAnnotation , and the type of the constructor Foo(int) last having an annotation of type SomeOtherAnnotation preinitialization ( Foo.new(int) ) @within (SomeAnnotation ) the pre-initialization (before the super constructor is called) that any join point where the associated code is defined in a type with is started with the constructor Foo(int) an annotation of type SomeAnnotation staticinitialization ( Foo ) @withincode (SomeAnnotation ) when the type Foo is initialized, after loading any join point where the associated code is defined in a method get ( int Point.x ) or constructor with an annotation of type SomeAnnotation when int Point.x is read @annotation (SomeAnnotation ) set ( !private * Point.* ) any join point where the subject has an annotation of type when any non-private field of Point is assigned SomeAnnotation handler ( IOException+ )

Note: any position in an “ @xxx ” pointcut can be replaced with a Pointcut definitions in types variable bound in the advice or pointcut. @Pointcut( “call(void Foo.m()) ”) private void pc() {} ; general form: a pointcut visible only from the defining type call (MethodPat ) @Pointcut (“ set(int Foo.x) && args(i) ”) call (ConstructorPat ) void pc (int i ) {} ; execution (MethodPat ) a package-visible pointcut that exposes an int . execution (ConstructorPat ) @Pointcut (“”) initialization (ConstructorPat ) public abstract void pc () {}; preinitialization (ConstructorPat ) an abstract pointcut that can be referred to from anywhere. staticinitialization (TypePat ) @Pointcut (“”) get (FieldPat ) abstract void pc (Object o ) {} ; set (FieldPat ) an abstract pointcut visible from the defining package. Any handler (TypePat ) pointcut that implements this must expose an Object . adviceexecution() @Pointcut (“args(s) && if()”) within (TypePat ) public static boolean pc (String s) { withincode (MethodPat ) return (s.startsWith(“xyz”)); withincode (ConstructorPat ) } cflow (Pointcut ) a pointcut with an if expression that matches a join point with a cflowbelow (Pointcut ) single String argument that starts with “xyz”. if (Expression ) this (Type | Var ) target (Type | Var ) Advice declarations in aspects args (Type | Var , …) @this (Type|Var) @Before (“ get(int Foo.y)”) @target (Type|Var) public void doSomething() { ... } @args (Type|Var, …) runs before reading the field int Foo.y @within (Type|Var) @withincode (Type|Var) @AfterReturning (“ call(int Foo.m(int))”) @annotation (Type|Var) public void doSomething() { ... } runs after calls to int Foo.m(int) that return normally where MethodPat is: [ModifiersPat ] TypePat [ TypePat . ] IdPat ( TypePat | .., … ) @AfterReturning (pointcut=“call(int Foo.m(int))”, [ throws ThrowsPat ] returning=” x”) ConstructorPat is: public void doSomething(int x){ ... } [ModifiersPat ] [ TypePat . ] new ( TypePat | .. , …) same, but the return value is named x in the body [ throws ThrowsPat ] FieldPat is: @AfterThrowing (“ call(int Foo.m(int))”) [ModifiersPat ] TypePat [ TypePat . ] IdPat public void doSomething() { ... } TypePat is one of: runs after calls to m that exit abruptly by throwing an exception IdPat [ + ] [ [] … ] ! TypePat @AfterThrowing (pointcut=“call(int Foo.m(int)) ”, TypePat && TypePat throwing=” e”) TypePat || TypePat public void doSomething( NotFoundException e) { ... } ( TypePat ) runs after calls to m that exit abruptly by throwing a NotFoundException . The exception is named e in the body

@After (“ call(int Foo.m(int)) ”) @AspectJ style public void doSomething{ ... } Aspects at top level (or static in types) runs after calls to m regardless of how they exit

@Aspect @Before (”set(int Foo.x) && args(i) ”) public class C {…} public void doSomething(int i, JoinPoint thisJoinPoint ) { ... } declares that the type C is an aspect runs before field assignment to int Foo.x . The value to be assigned is named i in the body, and the thisJoinPoint object is @Aspect (“percflow( call(void Foo.m()))” ) made available to the advice body public class C {…} declares that the type C is an aspect and an instance of C is @Around (“ call(int Foo.m(int)) ”) instantiated for every control flow through calls to m() public int doSomething(ProceedingJoinPoint pjp) { ... } runs instead of calls to int Foo.m(int) , and returns an int . In the general form: body, continue the call by using pjp.proceed (), which takes the @Aspect same signature as the around advice, excepting the @Aspect (“PerClause”) ProceedingJoinPoint itself.

Inter-type Member Declarations in aspects

@DeclareParents (“org.xyz..*”) private I anInterface; all types matching the pattern “ org.xyz..* ” implement I

@DeclareParents (value=” org.xyz..* ”, defaultImpl= MyImpl.class ) all types matching the pattern “ org.xyz..* ” implement I and acquire the default implementation of the operations in I as defined by MyImpl .

@DeclareWarning (“ set(* Point.*) && !within(Point)”) static final String message = “bad set” ; the weaver warns “bad set” if it finds a set to any field of Point outside of the code for Point

@DeclareError (“ call(Singleton.new(..)) ”) static final String message = “bad construction” ; the weaver signals an error “bad construction” if it finds a call to any constructor of Singleton

@Aspect @DeclarePrecedence (“ Security, Logging, * ”) public class A {…} at each join point, advice from Security has precedence over advice from Logging , which has precedence over other advice. general form: @DeclareParents (“ PointcutExpression ”) private InterfaceType fieldName ;

@DeclareParents (value=“ PointcutExpression ”, defaultImpl= Class ) private InterfaceType fieldName ;

@DeclareWarning (“ PointcutExpression ”) static final String fieldName = “ warning message ”;

@DeclareError (“ PointcutExpression ”) static final String fieldName = “ error message ”;

@Aspect @DeclarePrecedence (“ TypePatList ”)