Bug 108895 - Allow Binding in User Pointcuts
Summary: Allow Binding in User Pointcuts
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-06 22:43 EDT by Ron Bodkin CLA
Modified: 2005-09-06 22:43 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 Ron Bodkin CLA 2005-09-06 22:43:04 EDT
See also the AspectJ developer discussion with the subject "Restricting type 
from user defined pointcut" starting on August 31, 2005.

I would like to be able to test if a variable bound in a named pointcut is an 
instance of a subtype. For example, with

public abstract aspect Base {
    public pointcut requestExecution(RequestContext requestContext) :
        execution(* RequestContext.execute(..)) && this(requestContext); }

I'd like to write a pointcut to say "a requestExecution where the bound 
variable is an instance of the subclass DerivedRequestContext." The "natural" 
thing to do fails:

    public pointcut derivedRequestExecution() : 
        requestExecution(DerivedRequestContext);

C:\devel\scratch\inner\Base.aj:9 [error] incompatible type, expected 
RequestContext found DerivedRequestContext requestExecution
(DerivedRequestContext);
                 ^^^^^^^^^^^^

1 error

Now usually people faced with this situation will just hold their nose and 
write redundant code (which needs to be coupled to the details of how the used 
pointcut binds the variable):

    public pointcut derivedRequestExecution() : 
        requestExecution(*) && this(DerivedRequestContext);

It is actually possible to write a modular version of this with AspectJ 
pointcuts, but it's verbose and ugly:

    private pointcut derivedRequestExecutionParam(RequestContext
requestContext) : 
        requestExecution(requestContext) && if(requestContext instanceof 
DerivedRequestContext);

   public pointcut derivedRequestExecutionOk() :
derivedRequestExecutionParam(*);

I think it would be very useful if user defined pointcuts can filter on bound 
values just like the system defined pointcuts for this, target, and args. I 
find the asymmetry troubling, and the existing support for modularly doing this 
kludgely.

The common work-around of repeating the definition when binding gets worse when 
using, e.g., cflow pointcuts.

As Wes pointed out in the mailing list discussion, this proposal would allow 
compile-time type checking, rather than downcasting. Wes notes that if (when) 
this/target/args all have instanceof semantics, implementing this feature will 
be more natural (with better compile-time checking).