Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7087

@TupleConstructor and @Builder should be able to use defined setters rather than the field directly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.6
    • 2.5.0-alpha-1
    • xforms
    • None

    Description

      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') ] )
      

      In output we get:

      Called setName(n=Map style)
      Called setName(n=With style)
      [Person(Map style), Person(@TupleConsructor), Person(With style), Person(@Builder)]
      

      So, all forms of new object instatiation like Map-style, With block became different with new methods, defined by AST transformations.

      Attachments

        Activity

          People

            paulk Paul King
            hubbitus Pavel Alexeev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: