[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] advice precedence
|
Hi
I discovered today that one of my assumption seems to be wrong.
What is the rule for precedence between lets say a before, around and
an after advice defined in one single aspect and affecting the same
joinpoint ?
In both Manning and Wiley books on AspectJ, I understood that it would
happen like this:
"before, around, after".
But when trying some with AJDT / AJ 1.2.0 on Eclipse 3.0.1 I have some
results that depends on the source code order of my advices:
"before, around, after" in source leads to
before
around -->
hello
around --<
after
"around, before, after" in source leads to [ see the before nested
within the around' proceed() ]
around -->
before
hello
around --<
after
"before, after, around" in source leads to a compilation error that
says "can't determine precedence between two or more pieces of advice
that apply to the same join point: method-execution(void
preced.Preced.hello())"
Reading the AspectJ Programming guide did not give me a clue except perhaps:
"If the two pieces of advice are defined in the same aspect, then
there are two cases:
* If either are after advice, then the one that appears later in
the aspect has precedence over the one that appears earlier.
* Otherwise, then the one that appears earlier in the aspect has
precedence over the one that appears later. "
Does that means that there is no implicit rule that say that a before
advice will execute before the around advice (as long as those are in
the same aspect).
Why the 3rd source order leads to a compilation error ?
Below the little code snip
Alex
package preced;
public class Preced {
public void hello() {
System.out.println(" hello");
}
public static void main(String[] args) {
(new Preced()).hello();
}
static aspect MyAspect {
before() : execution(* *Preced.hello()) {
System.out.println("before");
}
Object around() : execution(* *Preced.hello()) {
System.out.println("around -->");
proceed();
System.out.println("around --<");
return null;
}
after() : execution(* *Preced.hello()) {
System.out.println("after");
}
}
}