[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] advice precedence
|
A good question to start the new year with :)
> 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 ?
> 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:
As you quote from the user guide:
> "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. "
On the "way in" to a join point, the advice with the highest precedence
executes first, and on the "way out" the advice with the highest
precedence executes last.
Here "later in the aspect" means "later in the source file" - ie. exactly
that the order depends on the order of the advice declarations in the
source file.
> "before, around, after" in source leads to
> before
> around -->
> hello
> around --<
> after
This order is derived as follows:
given the pair (before, around) then by the second clause the one that
appears earlier in the source has precedence:
before -> around
given the pair(around, after) the by the first clause the after advice has
precedence so we get:
after -> around
on the "way in" the highest precedence goes first so we see "before,
around-entry" and on the way out the highest precedence goes last so we
see "around-exit, after". Giving:
before
around-entry
hello
around-exit
after
> "around, before, after" in source leads to
> around -->
> before
> hello
> around --<
> after
This order is derived as follows:
given the pair (around, before) then by the second clause the one that
appears earlier in the source has precedence:
around -> before
given the pair (around, after) then by the first clause the after advice
has precedence:
after -> around
on the "way in" this gives us "around-entry, before" and on the "way-out"
this gives us "around-exit, after". Giving:
around-entry
before
hello
around-exit
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())"
Applying the first rule to the pair (before, after) we see that the after
advice has precedence:
after -> before
Applying the first rule to the pair (after, around) we see that the around
advice has precedence:
around -> after
Applying the second rule to the pair (before, around), we see that the
before advice has precedence:
before -> around
If we put these together we get: around -> after -> before -> around ->
...
In previous versions of AspectJ I recall this being reported as a
"circular precedence error" or some similar wording - but the error
message has subsequently been improved to give the one that you witnessed.
-- Adrian
Adrian_Colyer@xxxxxxxxxx
Alexandre Vasseur <avasseur@xxxxxxxxx>
Sent by: aspectj-users-admin@xxxxxxxxxxx
03/01/2005 10:17
Please respond to
aspectj-users@xxxxxxxxxxx
To
aspectj-users@xxxxxxxxxxx
cc
Subject
[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");
}
}
}
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users