AspectJ Quick Reference Pointcuts Methods and Constructors call(Signature) every call to any method or constructor matching Signature at the call site execution(Signature) every execution of any method or constructor matching Signature Fields get(Signature) every reference to any field matching Signature set(Signature) every assignment to any field matching Signature. The assigned value can be exposed with an args pointcut Exception Handlers handler(TypePattern) every exception handler for any Throwable type in TypePattern. The exception value can be exposed with an args pointcut Advice adviceexecution() every execution of any piece of advice Initialization staticinitialization(TypePattern) every execution of a static initializer for any type in TypePattern initialization(Signature) every initialization of an object when the first constructor called in the type matches Signature, encompassing the return from the super constructor call to the return of the first-called constructor preinitialization(Signature) every pre-initialization of an object when the first constructor called in the type matches Signature, encompassing the entry of the first-called constructor to the call to the super constructor Lexical within(TypePattern) every join point from code defined in a type in TypePattern withincode(Signature) every join point from code defined in a method or constructor matching Signature Instanceof checks and context exposure this(Type or Id) every join point when the currently executing object is an instance of Type or Id's type target(Type or Id) every join point when the target executing object is an instance of Type or Id's type args(Type or Id, ...) every join point when the arguments are instances of Types or the types of the Ids Control Flow cflow(Pointcut) every join point in the control flow of each join point P picked out by Pointcut, including P itself cflowbelow(Pointcut) every join point below the control flow of each join point P picked out by Pointcut; does not include P itself Conditional if(Expression) every join point when the boolean Expression is true Combination ! Pointcut every join point not picked out by Pointcut Pointcut0 Pointcut1 each join point picked out by both Pointcut0 and Pointcut1 Pointcut0 || Pointcut1 each join point picked out by either Pointcut0 or Pointcut1 ( Pointcut ) each join point picked out by Pointcut Type Patterns A type pattern is one of 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 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 a Throwable of the type of Formal, and Formal gives access to the Throwable 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 extend Type. declare parents : TypePattern implements TypeList ; the types in TypePattern implement the types in TypeList. declare warning : Pointcut : String ; if any of the join points in Pointcut possibly exist in the program, the compiler emits the warning String. declare error : Pointcut : String ; if any of the join points in Pointcut could possibly exist in the program, the compiler emits the error String. declare soft : Type : Pointcut ; any Type exception that gets thrown at any join point picked out by Pointcut is wrapped in org.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 [ 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)
id='n561' href='#n561'>561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773