avaje / avaje-record-builder

Apache License 2.0
8 stars 1 forks source link

handle generic records #26

Closed SentryMan closed 1 year ago

SentryMan commented 1 year ago

fixes #24

given

@RecordBuilder(getters=true)
record Tuple2<T1 extends SomeInterface & SomeInterface2, T2>(T1 t1, T2 t2) {}

will generate:

/** Builder class for {@link Tuple2} */
@Generated("avaje-record-builder")
public class Tuple2Builder<T1 extends SomeInterface & SomeInterface2, T2> {
  private T1 t1;
  private T2 t2;

  private Tuple2Builder() {
  }

  private Tuple2Builder(T1 t1, T2 t2) {
    this.t1 = t1;
    this.t2 = t2;
  }

  /**
   * Return a new builder with all fields set to default Java values
   */
  public static <T1 extends SomeInterface & SomeInterface2, T2> Tuple2Builder<T1, T2> builder() {
      return new Tuple2Builder<T1, T2>();
  }

  /**
   * Return a new builder with all fields set to the values taken from the given record instance
   */
  public static <T1 extends SomeInterface & SomeInterface2, T2> Tuple2Builder<T1, T2> builder(Tuple2<T1, T2> from) {
      return new Tuple2Builder<T1, T2>(from.t1(), from.t2());
  }

  /**
   * Return a new Tuple2 instance with all fields set to the current values in this builder
   */
  public Tuple2<T1, T2> build() {
      return new Tuple2<T1, T2>(t1, t2);
  }

  /** Set a new value for {@code t1}. */
  public Tuple2Builder<T1, T2> t1(T1 t1) {
      this.t1 = t1;
      return this;
  }
  /** Return the current value for {@code t1}. */
  public T1 t1() {
      return t1;
  }
  /** Set a new value for {@code t2}. */
  public Tuple2Builder<T1, T2> t2(T2 t2) {
      this.t2 = t2;
      return this;
  }
  /** Return the current value for {@code t2}. */
  public T2 t2() {
      return t2;
  }
}