groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Graeme Rocher (JIRA)" <>
Subject [jira] [Created] (GROOVY-7956) Allow @DelegatesTo on named arguments
Date Tue, 04 Oct 2016 12:52:20 GMT
Graeme Rocher created GROOVY-7956:

             Summary: Allow @DelegatesTo on named arguments
                 Key: GROOVY-7956
             Project: Groovy
          Issue Type: New Feature
          Components: GEP
            Reporter: Graeme Rocher

In order to aid static compilation for builders we have {{@DelegatesTo}} which allows statically
compiled code to know what the delegate of a closure is.

This proposal is to allow {{@DelegatesTo}} on {{Map}} types such that IDEs and the static
compiler can resolve the target type the named arguments are to be used on.

For example:

class Farm {
     void animal(@DelegatesTo(Animal) Map arguments, @DelegatesTo(AnimalBuilder) Closure callable)
             def animal = new Animal(arguments)
             // handle closure

class Animal { String name }

The following code would then fail to compile :

def farm = new Farm()
// compilation failure, no name property on Animal
farm.animal(nam: "Dog")  { 

It would then be down to IDEs to also provide support for code completion etc.

This message was sent by Atlassian JIRA

View raw message