Hi Mouna,
I think this is an area where the AspectJ
compiler is limited but it should work. You'd like a program like this to work:
public aspect BindingOr {
pointcut a(String o, int x) :
execution(* foo(..)) && args(o, x);
pointcut b(String o) :
execution(!static * *(..)) && args(o);
pointcut aOrB(String o): a(o, *) ||
b(o);
public static void main(String args[])
{
aspectOf().foo("woof",
1);
aspectOf().bar("zip");
}
void foo(String o, int x) {}
void bar(String o) {}
after(String o) returning: aOrB(o) {
System.out.println("executed
"+o);
}
}
Unforunately this fails even though there
could never be any ambiguity:
C:\devel\scratch\BindingOr.aj:3 [error]
ambiguous binding of parameter(s) o across '||' in pointcut
The best you can do is something like
this:
…
after(String o) returning: a(o) {
common(o);
}
after(String o) returning: b(*, o) {
common(o);
}
private void common(String o) {
System.out.println("executed
"+o);
}
In your case, you might also be able to
use this approach of binding separately:
after(String o) returning: (a(*) ||
b(*, *)) && args(o, ..) {
System.out.println("executed
"+o);
}
Subject: Re: [aspectj-users]
COmbining pointcuts in the same advice