Cheatography
https://cheatography.com
AspectJ for Fortgeschrittene Java Programmierung, THI
Terminology
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 |
Aspect
public aspect LogAspect { ... }
|
Holds Introductions, Advices and Pointcuts
Introduction
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) {
...
}
}
|
Can Introduce new Methods and Declarations
Advice
|
|
alternative: after returning
, after throwing
|
|
use proceed()
to execute wrapped joinpoint |
Pointcut Args
target(p) |
bind cut target |
args(vals) |
bind Pointcut arguments |
pointcut setter(Point p, int newval):
target(p) &&args(newval)
|
|
Joinpoint
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!" );
}
}
|
Pointcut Syntax
Wildcards |
|
any characters, but not "." |
|
any characters, also "." |
|
Any Subclass / Interface |
Logical |
|
Primitive Pointcuts
|
call of a Method |
execution(Foo.(..) throws IOException)
|
execution of any Method throwing an Exception |
|
|
initialization(Foo.new(int))
|
initialisation by a special constructor |
handler(IOException+)
|
handling of any IOException |
get(int Foo.bar)
or set(int Foo.bar)
|
|
limit to foo class |
* call
vs execution
: think of "caller" vs "executing Object"
thisJoinPoint
thisJoinPointStaticPart
equals jp.getStaticPart()
thisJoinPoint
is available inside the Advice
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
More Cheat Sheets by cs8898