You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Pavel (JIRA)" <ji...@apache.org> on 2017/12/03 19:20:01 UTC

[jira] [Commented] (GROOVY-7087) @TupleConstructor and @Builder should be able to use defined setters rather than the field directly

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

Pavel commented on GROOVY-7087:
-------------------------------

Thank you, [~paulk]!

> @TupleConstructor and @Builder should be able to use defined setters rather than the field directly
> ---------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-7087
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7087
>             Project: Groovy
>          Issue Type: Bug
>          Components: xforms
>    Affects Versions: 2.3.6
>            Reporter: Pavel
>            Assignee: Paul King
>             Fix For: 2.5.0-alpha-1
>
>
> {code}
> import groovy.transform.TupleConstructor
> import groovy.transform.ToString
> import groovy.transform.InheritConstructors
> import groovy.transform.builder.Builder
> import groovy.transform.builder.SimpleStrategy
> @Builder(builderStrategy=SimpleStrategy, prefix='with')
> @TupleConstructor
> @ToString
> class Person{
>     String name;
>     void setName(String n){
>         println "Called setName(n=$n)"
>         name = n;
>     }
> }
> println Person.constructors
> println  ( [ new Person(name: 'Map style'), new Person('@TupleConsructor'), new Person().with{ name = 'With style'; it }, new Person().withName('@Builder') ] )
> {code}
> In output we get:
> {noformat}
> Called setName(n=Map style)
> Called setName(n=With style)
> [Person(Map style), Person(@TupleConsructor), Person(With style), Person(@Builder)]
> {noformat}
> So, all forms of new object instatiation like Map-style, With block became different with new methods, defined by AST transformations.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)