|
Aspect
|
Modularization unit, compareable with Class
|
|
Introduction
|
introduce new method
|
|
Joinpoint
|
Condituion to trigger some action
|
|
Pointcut
|
Collection of Joinpoints
|
|
Advice
|
Behavior introduced at Pointcut
|
|
Weaving
|
Aspects get waved into the result bytecode
|
public aspect LogAspect { ... }
public aspect HashableComplex {
// introduce an interface
declare parents: Complex implements Comparable;
// don’t forget the class name!
public int Complex.compareTo( Object o ) {
...
}
@Override
public boolean Complex.equals(Object obj) {
...
}
}
before |
|
after |
alternative:
after returning, after throwing |
around |
use
proceed() to execute wrapped joinpoint |
|
target(p)
|
bind cut target
|
|
args(vals)
|
bind Pointcut arguments
|
pointcut setter(Point p, int newval):target(p) &&args(newval)
package hello;
public aspect WorldAspect{
public pointcut mainOperation():
execution (void hello.World.main(String[]));
//execution (void*.*(*));
before(): mainOperation() {
println( "Hello aspect world!" );
}
after(): mainOperation() {
println( "Bye aspect world!" );
}
}
|
Wildcards
|
|
* |
any characters, but not "."
|
.. |
any characters, also "."
|
+ |
Any Subclass / Interface
|
|
Logical
|
||, &&, ! |
call(void Foo.m(int)) |
call of a Method
|
execution(Foo.(..) throws IOException) |
execution of any Method throwing an Exception
|
call Foo.new(..) |
any Constructors of
Foo |
initialization(Foo.new(int)) |
initialisation by a special constructor
|
handler(IOException+) |
handling of any IOException
|
get(int Foo.bar) or set(int Foo.bar) |
|
within(Foo) |
limit to foo class
|
call vs execution: think of "caller" vs "executing Object"
getArgs(): Object[] args |
|
getSignature() |
|
getSourceLocation() |
thisJoinPointStaticPart equals jp.getStaticPart()thisJoinPoint is available inside the Advice
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.