Bug 160509 - Allow matching args by type not position
Summary: Allow matching args by type not position
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: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-11 13:04 EDT by Ron Bodkin CLA
Modified: 2006-10-11 13:04 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 2006-10-11 13:04:59 EDT
Often it's important to be able to bind an argument by type rather than position, since reasonable API's often will change the position of an argument type.

This enhancement request is to provide a way to bind args by type rather than writing code like the example below or using thisJoinPoint.getArgs(). 

One approach would be allowing the use of args(.., arg, ..); There are two options for resolving the question of ambiguity:
1) making ambiguous bindings an error, as with binding across a || disjunction (probably the least work/surprise but still quite useful..)
2) matching on the *first* matching argument with an Xlint warning when there is ambiguity 

Matching the first argument would be more powerful and useful, e.g.,

pointcut first(Type arg) : args(.., arg, ..); 
pointcut second(Type arg) : args(.., Type, .., arg, ..); 
pointcut exactlyOneArgOfType(Type arg) : 
   args(.., arg, ..) && !args(.., Type, .., Type, ..);
pointcut exactlyOneArgOfTypeAndItsASubType(SubType arg) : 
   args(.., arg, ..) && !args(.., Type, .., Type, ..);

Another idea would be adding a new pointcut designator:
argtype(FilterTypePattern, id or type1 or .., ...)

Example:
pointcut first(Type arg) : argtype(Type, arg, ..);
pointcut second(Type arg) : argtype(Type, *, arg, ..);
pointcut exactlyOneArgOfTypeAndItsASubType(SubType arg) : argtype(Type, arg);

These are just a couple of straw man approaches, but it would be very helpful to add support for this kind of binding in AspectJ 1.6, if it would be a reasonable amount of work to implement. A related use case that this rfe doesn't address is being able to bind to any argument in any position (e.g., to do null checks). That one seems hard to handle while preserving the rule that a given pointcut will match and bind a given join point zero or one times.

Existing example (working with commons httpclient):
    protected pointcut executeOnMethod() :
        execution(* HttpClient.executeMethod(..));
        
    protected pointcut executeOnMethod1(HttpMethod httpMethod) :
        executeOnMethod() && args(httpMethod, ..);

    protected pointcut executeOnMethod2(HttpMethod httpMethod) :
        executeOnMethod() && args(HostConfiguration, httpMethod, ..);