Community
Participate
Working Groups
Bug 68603 discusses why/that we use the instanceof semantics we do for this(), target(), and args(), and the special exception for null values. This bug is to request variants sthis, starget, and sargs for staticly-determinable {variable} binding. In many cases, users want the pointcut to always match (even when context values are null), and would like to get the context values without using thisJoinPoint and downcasting. Also, if variables are not bound but one would like to match different kinds of join points with a certain type, one has to write pointcuts for each kind of join point. e.g., execution(* T.*(..)) || call(* T.*(..)) || initialization(T.new(..)) ... While static variants might seem like semantic sugar, requiring a downcast tangles the binding with the advice implementation and reduces the reusability and testability of the pointcut. Even when there is no binding, requiring each join point kind be specified is unclear and error-prone. Using staticly-determinable variants enables the bindings to reside in the pointcut declaration and eliminates the possibility of ClassCastException's. Also, this can be used not only in advice, but also in declare-error. Here's a token definition: ---- sthis(T), starget(T), and sargs({...}} specify staticly-determinable target types. The join point matches if the declared type of the corresponding join point component is staticly determinable to be a subtype of T. When a bound variable is used for T, the resulting value may be null. The join point component for each of this(), starget(), and sargs() is the same as it is for this(), target(), and args() (respectively). ---- A related request is to define a sreturn() PCD which matches when the result of a join point is staticly-determinable to be a subtype of the given type. A use-case for that is to enforce a return type for a given pointcut: abstract aspect Iteration { abstract protected pointcut iterating(); void around() : iterating() && sreturns(void) { iterate(new Runnable() { public void run() { proceed(); } }); } protected void iterate(Runnable r) { r.run(); } } In before or around advice, any value bound to sreturns would be null. (For sreturns purposes, we would declare that void is "returned" from constructor-execution, initializers, handlers, etc.) I'd hope this could be implemented as a refactoring of the existing context-binding PCD's. I'm not happy with the names, but would prefer the names to be a short as possible. thisT(T)? thistype(*)? staticthis()?