Bug 113184 - staticly-determinable this, target, args (and returns) to pick out types, nulls
Summary: staticly-determinable this, target, args (and returns) to pick out types, nulls
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P5 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-10-19 23:37 EDT by Wes Isberg CLA
Modified: 2007-10-23 11:23 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wes Isberg CLA 2005-10-19 23:37:00 EDT
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()?