Summary: | Cannot pass middle argument to pointcut | ||
---|---|---|---|
Product: | [Tools] AspectJ | Reporter: | z z <boraldomaster> |
Component: | Compiler | Assignee: | aspectj inbox <aspectj-inbox> |
Status: | RESOLVED WONTFIX | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | CC: | aclement, sergey.kadaner |
Version: | 1.6.11 | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | All | ||
Whiteboard: |
Description
z z
2012-11-01 07:59:41 EDT
We don't support multiple '..' in args. So typically you use '*' to stand in for an argument: args(*,object,..) - the 2nd argument args(*,*,object,..) - the 3rd argument will that work for you? This is obviously not suitable. I want to pass argument that is anywhere among parameters. It can be 1st,2nd, 3rd. How can I do it ? Create pointcuts for any number of parameters from 1 to 1000 ? Here is how my pointcut looks now: args(..,criteria) || args(criteria,..) || args(*,criteria,..) || args(..,criteria,*) Do you really suppose this to be quite elegantly (besides it handles just 4 cases) ? (In reply to comment #2) > This is obviously not suitable. I want to pass argument that is anywhere > among parameters. It can be 1st,2nd, 3rd. > How can I do it ? Create pointcuts for any number of parameters from 1 to > 1000 ? I completely agree that it is not elegant. We have an open enhancement request to handle this situation which comes up a lot with parameter annotations (@NotNull being a prime example). Unfortunately the design and implementation of supporting this is quite tricky to get right, and whilst a workaround exists we tend to focus more on the problems which have no workaround.
> Create pointcuts for any number of parameters from 1 to 1000 ?
I haven't really seen methods with more than 10 parameters - but yes you would have to create a variant pointcut or pointcut comopnent for each you want to match. I'm not 100% sure it will behave if you merge them all into one clause:
args(..,criteria) || args(criteria,..) || args(*,criteria,..) || args(..,criteria,*)
because if your criteria matches two of them at one call location, what would it bind? This is the pattern I've seen:
before(Object arg): somepcd() && args(arg,..) { callsomething(); }
before(Object arg): somepcd() && args(*,arg,..) { callsomething(); }
before(Object arg): somepcd() && args(*,*,arg,..) { callsomething(); }
before(Object arg): somepcd() && args(*,*,*,arg,..) { callsomething(); }
before(Object arg): somepcd() && args(*,*,*,*,arg,..) { callsomething(); }
...
Closing as known limitation for now. Periodically raised as something to look into but it is a lot of work to implement nicely when there exists a crude workaround. |