Community
Participate
Working Groups
I'd like to write a pointcut to match the first String argument in the first two positions, for an API where this is the best rule I can use (see also bug #160509, which is a more general request). Unfortunately this doesn't work: public pointcut firstString(String first) : args(first, ..) || args(!String, first, ..); C:\devel\scratch\args\FirstArg.aj:3 [error] exact type pattern required args(first, ..) || args(!String, first, ..); Nor does this: public pointcut firstString(String first) : args(first, ..) || (!args(String, ..) && args(*, first, ..)); C:\devel\scratch\args\FirstArg.aj:3 [error] ambiguous binding of parameter(s) fi rst across '||' in pointcut Work-around: write advice on args(first, ..) and separate advice on !args(String, ..) && args(*, first, ..)
Sample program: public aspect FirstArg { public pointcut firstString(String first) : args(first, ..) || (!args(String, ..) && args(*, first, ..)); before(String first) : firstString(first) { System.out.println("At "+thisJoinPoint+", first is "+first); } public static void main(String argz[]) { one("test"); two("more", "test"); three("top", "more", "test"); } static void one(String z) {} static void two(String y, String z) {} static void three(String x, String y, String z) {} }