I'm afraid I don't have a pretty answer for you (I should but we don't have the syntax for it right now). Or at least I can't think of a pretty answer right now..
For now you need to exploit what happens in the bytecode when you compile that kind of code.
The inner class has two characteristics when compiled like this:
- it has a new field called this$0 that maps to the outer class
- the constructor takes an additional argument that is the outer instance (which is then places in this$0).
We can grab the this$0:
before(): execution(boolean B+.someFunc()) {
Object t = thisJoinPoint.getTarget();
try {
Object outerInstance = t.getClass().getDeclaredField("this$0").get(t);
} catch (Exception e) {}
}
We can grab it on the way into the constructor and remember it:
before(A a,B b): execution(B+.new(..)) && args(a) && this(b) { // this pointcut will vary if your inner takes params on the ctor
mymap.put(b,a);
}
before(): execution(boolean B+.someFunc()) {
Object t = thisJoinPoint.getTarget();
Object outerInstance = mymap.get(t);
}
Neither are ideal, I'll agree...
cheers
Andy