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

Paul King commented on GROOVY-7860:
-----------------------------------

PR added:
https://github.com/apache/groovy/pull/348

> Groovy could implement an @AutoImplement transform
> --------------------------------------------------
>
>                 Key: GROOVY-7860
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7860
>             Project: Groovy
>          Issue Type: New Feature
>            Reporter: Paul King
>            Assignee: Paul King
>
> Groovy provides numerous facilities for dynamically creating 'Proxy' 
> implementations of interfaces, e.g.:
> {code}
> def emptyIterator = [hasNext: { false }] as Iterator
> {code}
> There is special support for Closures, maps of Closures, SAM method coercion 
> and various proxy generator classes. Typically such dynamic creation is 
> exactly what is required, e.g. a one-off usage object or a testing stub of 
> some kind. But other times, compile time creation of such classes would be 
> useful. This proposal suggests a transform to reduce boilerplate code for a 
> number of common scenarios where code can be created. The proposal has 
> numerous configuration options but doesn't try to support everything that the 
> dynamic options provide. E.g. no map of Closures is supported; you _can_ just 
> create a class manually in that case.
> The transform allows the above example to be as follows:
> {code}
> @AutoImplement
> class EmptyStringIterator implements Iterator<String> {
>     boolean hasNext() { false }
> }
> {code}
> which provides a method having signature '{{String next()}}' with an 
> implementation that returns the default value for the return type ({{null}} 
> for {{String}}).
> Alternatively, we can make it throw an exception as follows:
> {code}
> @AutoImplement(exception=UnsupportedOperationException)
> class EmptyStringIterator implements Iterator<String> {
>     boolean hasNext() { false }
> }
> {code}
> This would in fact be a closer match to the initial dynamic case shown above.



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

Reply via email to