AspectJ
index
如何使用AspectJ Compiler開發AspectJ程式
AspectJ: A general-purpose, aspect-oriented extension to the Java programming language.
- Language specification: Defines the language in which you write the code.
- Language implementation: Provides tools for compiling, debugging, and integration with popular integrated development environments (IDEs).
Crosscutting elements
- Join point: An identifiable point in the execution of a program.
- Pointcut: A program construct that selects join points and collects context at those points.
- join points: situations satisfying those rules.
- pointcut: specifying the weaving rules.
- Advice: The code to be executed at a join point that has been selected by a pointcut.
- Introduction: A static crosscutting instruction that introduces changes to the classed, interfaces, and aspects of the system.
- Compile-time declaration: A static crosscutting instruction that allows you to add compile-time warnings and errors upon detecting certain usage patterns.
- Aspect: The central unit of AspectJ.
All functions together
Design:
- Identify the join points at which you want to augment or modify the behavior.
- Design what that new behavior will be.
Implement:
- Write an aspect that serves as a module to contain the overall implementation.
- Write pointcuts to capture the desired join points.
- Create advice for each pointcut and encode within its body the action that needs to happen upon reaching the join points.
Pointcuts
Pointcuts capture, or identify, join points in the program flow.
- aspect∼class
- pointcut∼method declaration
- advice∼method implementation
pointcut可宣告於aspect、class、interface
- named pointcut:
[access specifier] pointcut pointcut-name([args]) : pointcut-definition
- anonymous pointcut:
advice-specification : pointcut-definition
Wildcards and pointcut operators
* any number of characters except the period.
.. any number of characters including any number of periods.
+ any subclass or subinterface of a given type.
! allows the matching of all join points except those sepcified by the pointcut.
|| combine pointcuts - the selection of join points that match either of the pointcuts.
&& combine pointcuts - the selection of join points that match both of the pointcuts.