The @DelegatesTo annotation Add comment to Wiki View in Wiki
Edit Wiki page Printable Version  Groovy, DSLs and builders
DSLs made easy  The Groovy language is a platform of choice for
building DSLs. Using closures, it's quite easy to create custom
control structures, as well as it is simple to create builders.
Imagine that you have the following code:  One way of
implementing this is using the builder strategy, which implies a
method, named email which accepts a closure as an argument. The
method may delegate subsequent calls to an object that
implements the fromtosubject and body methods. Again, body is a
method which accepts a closure as an argument and that uses the
builder strategy.  Implementing such a builder is not
complicated:  the Email class implements the fromto, ...
methods. By calling rehydrate, we're creating a copy of the
closure for which we set the delegateowner and thisObject
values. Setting the owner and the "this" object is not very
important here since we will use the DELEGATE_ONLY stra