groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul King (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-7956) Allow @DelegatesTo on named arguments
Date Thu, 06 Oct 2016 10:57:20 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-7956?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15551617#comment-15551617
] 

Paul King commented on GROOVY-7956:
-----------------------------------

Some really nice ideas here and in Sergei's {{MapArguments}} project:

https://github.com/bsideup/GroovyMapArguments/blob/master/src/test/groovy/ru/trylogic/groovy/mapargs/MapArgumentsTest.groovy

My understanding of where we are:

* We need some way to augment the type information for the Map argument.
We have {{@DelegatesTo(Animal)}}, {{@MapArguments(typeHint=Animal)}} and {{@Properties(Animal)}}
as suggestions for the "prototype/delegate" case.
We might also want to support a self-describing mode: {{@Properties([ x: Integer, y: Integer
])}}. You could imagine making this more elaborate by specifying required args etc.
* We might also want some additional transformations, e.g. Sergei's MapArguments will create
the Map variant given a method with the delegate as first parameter.

The type information is needed when using the method in contexts which are type-checked. If
we don't have Sergei's simple forwarding in play, then it would also be used for type checking
within the method body if needed.

> Allow @DelegatesTo on named arguments
> -------------------------------------
>
>                 Key: GROOVY-7956
>                 URL: https://issues.apache.org/jira/browse/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:
> {code}
> class Farm {
>      void animal(@DelegatesTo(Animal) Map arguments, @DelegatesTo(AnimalBuilder) Closure
callable) {
>              def animal = new Animal(arguments)
>              // handle closure
>     }
> } 
> class Animal { String name }
> {code}
> The following code would then fail to compile :
> {code}
> def farm = new Farm()
> // compilation failure, no name property on Animal
> farm.animal(nam: "Dog")  { 
> }
> {code}
> It would then be down to IDEs to also provide support for code completion etc.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message