這幾天在學習JSF / AspectJ / Refactoring, 以及在eclipse下的使用。
AspectJ中的四個概念:
Pointcuts - 切入點(類似於一個動作,一件事情,甚至一組動作或事情等等),具體可以是一個或者幾個方法,實例化,賦值(set,get),異常,block ... 具體有一下這些(後面幾個我的理解也是模糊的,那位高手可以準確這些概念,謝謝先):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 |
each join point picked out by Pointcut
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 |
- 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.
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.