Details
-
Type:
Improvement
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 2.6.0.Release
-
Fix Version/s: 2.6.1.Release
-
Component/s: DSL Support
-
Labels:None
-
Number of attachments :
Description
A common idiom in many a DSL (e.g. the Gradle DSL) is that we have
<keyword> {
}
For some keyword (e.g. repositories, dependencies, etc.). The keyword switches on some DSL feature inside of the closure block by setting the delegate of the closure.
It would be nice to directly support this kind of idiom. I first though that is what 'delegatesTo' did... but it doesn't.
Right now the 'delegate' is assumed to be the same as the 'receiver' of <keyword> method. That is often but not always correct.
A more complex use case in the Gradle DSLD is the 'configure' method.
configure(<something>) {
}
This will set the delegate in the closure not to some specific type, but to a type that is derived from <somethings> type. (E.g. <something> is a Project then the delegate will be that project. If something is a list of Project, it will be invoking the closure repeatedly for each project in the list.
This is probably hard/impossible to support, but at least we could support the more easy case where the delegate has a specific and well known type.
Issue Links
- is depended upon by
-
GRECLIPSE-1322
Update wiki documentation to include setDelegateType
-
- is related to
-
GRECLIPSE-1323
Implement the closestEnclosingCallName pointcut
-
If you are trying to achieve something like grail's resources.groovy where you have single file that assigns a closure to a binding variable, the easiest way of "prescribing required methods/properties within a closure" is to simply use enclosingCallName("method"). You can use this in conjunction with fileName("my-file.groovy") to limit the scope of the pointcut.
One thing I find annoying is that, from what I understand, one cannot limit the call to the top-level scope of closure body. What this means is that if you have a structure like:
reports = { report { params { param(...) } } }You cannot limit the applicability of the param call to the params body unless you do something like the following in your DSLD file:
As you can see, you have to exclude all other scopes to achieve the desired effect. It would be nice if there were a pointcut like enclosingScopeCallName that provided this capability since it is often what is required for builder-based DSLs.