Community
Participate
Working Groups
The construction of thisJoinPoint is an expensive operation which should be avoided when possible. If the aspect is oinly needed a small percentage of the time depending on state in the this() instance, it would be great to have access to this() or the current aspect instance in an if().
I am guessing this is more about optimizing if(), since you can already get access to either. Right? For example, you may access this() using something like: pointcut pc(MyClass mc) : execution(* *(..)) && this(mc) && if(mc.someCondition()); And the aspect instance using something like: pointcut pc() : execution(* *(..)) && if(MyAspect.aspectOf().someCondition());
Yes, this is about optimizing if()
Now implemented access to aspect instance with the special name 'thisAspectInstance' available in the if clause(): aspect X { boolean doit() { System.out.println("In instance check method doit()"); return true; } before():execution(* m(..)) && if(thisAspectInstance.doit()){ System.out.println(thisJoinPoint); } } It only works for singletons right now - I'll address others as use cases come up. It guards the creation of the tjp object. It works for subclassing too: abstract aspect X { abstract pointcut p(); boolean doit() { return true; } before():p() && if(thisAspectInstance.doit()){ System.out.println(thisJoinPoint); } } aspect Y extends X { pointcut p(): execution(* m(..)); } When doit() runs the instance will be of type Y.
unsetting the target field which is currently set for something already released