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

@groovy.transform.builder.Builder should generate @Generated annotations for build(), builder() and setter methods

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.5.7
    • 2.5.8, 3.0.0-beta-2
    • Compiler
    • None

    Description

      Using the @groovy.transform.builder.Builder with SimpleStrategy yields the following problems.

      Groovy input

      @groovy.transform.builder.Builder
      class GroovyBuilderClassTarget {
      
          @groovy.transform.builder.Builder(builderStrategy= SimpleStrategy)
          class Person {
              String first
              String last
              Integer born
          }
          static void main(String[] args) {
              new GroovyBuilderClassTarget()
          }
      }
      

      Groovy output:

      @Builder
      public class GroovyBuilderClassTarget implements GroovyObject {
          @Generated
          public GroovyBuilderClassTarget() {
              CallSite[] var1 = $getCallSiteArray();
              super();
              MetaClass var2 = this.$getStaticMetaClass();
              this.metaClass = var2;
          }
          public static void main(String... args) {
              CallSite[] var1 = $getCallSiteArray();
              var1[0].callConstructor(GroovyBuilderClassTarget.class);
          }
          @Generated
          public static GroovyBuilderClassTarget.GroovyBuilderClassTargetBuilder builder() {
              CallSite[] var0 = $getCallSiteArray();
              return (GroovyBuilderClassTarget.GroovyBuilderClassTargetBuilder)ScriptBytecodeAdapter.castToType(var0[1].callConstructor(GroovyBuilderClassTarget.GroovyBuilderClassTargetBuilder.class), GroovyBuilderClassTarget.GroovyBuilderClassTargetBuilder.class);
          }
      
          @Builder(
              builderStrategy = SimpleStrategy.class
          )
          public class Person implements GroovyObject {
              private String first;
              private String last;
              private Integer born;
      
              @Generated
              public Person() {
                  CallSite[] var2 = $getCallSiteArray();
                  super();
                  MetaClass var4 = this.$getStaticMetaClass();
                  this.metaClass = var4;
              }
      
              @Generated
              public GroovyBuilderClassTarget.Person setFirst(String first) {
                  CallSite[] var2 = $getCallSiteArray();
                  this.first = first;
                  return this;
              }
              @Generated
              public GroovyBuilderClassTarget.Person setLast(String last) {
                  CallSite[] var2 = $getCallSiteArray();
                  this.last = last;
                  return this;
              }
      
              @Generated
              public GroovyBuilderClassTarget.Person setBorn(Integer born) {
                  CallSite[] var2 = $getCallSiteArray();
                  this.born = born;
                  return this;
              }
      
              @Generated
              public String getFirst() {
                  return this.first;
              }
      
              @Generated
              public String getLast() {
                  return this.last;
              }
      
              @Generated
              public Integer getBorn() {
                  return this.born;
              }
          }
      
          @Generated
          public static class GroovyBuilderClassTargetBuilder implements GroovyObject {
              @Generated
              public GroovyBuilderClassTargetBuilder() {
                  CallSite[] var1 = $getCallSiteArray();
                  super();
                  MetaClass var2 = this.$getStaticMetaClass();
                  this.metaClass = var2;
              }
      
              @Generated
              public GroovyBuilderClassTarget build() {
                  CallSite[] var1 = $getCallSiteArray();
                  GroovyBuilderClassTarget _theGroovyBuilderClassTarget = (GroovyBuilderClassTarget)ScriptBytecodeAdapter.castToType(var1[0].callConstructor(GroovyBuilderClassTarget.class), GroovyBuilderClassTarget.class);
                  return _theGroovyBuilderClassTarget;
              }
          }
      }
      

      I'd expect the following methods to have an @Generated annotation:
      public static GroovyBuilderClassTarget.GroovyBuilderClassTargetBuilder builder()
      public GroovyBuilderClassTarget.Person setFirst(String first)
      public GroovyBuilderClassTarget.Person setLast(String last)
      public GroovyBuilderClassTarget.Person setBorn(Integer born)
      public GroovyBuilderClassTarget build()

      Found during Hackergarten Zurich.

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              jwloka Jan Wloka
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m