danielnorberg/auto-matter

Record methods are not ignored

Closed this issue · 4 comments

cykl commented

Documentation says it's possible to add behavior to a value type and give an example using an interface definition.

I tried to do the same using a record definition without success. Let's use this dumb example:

@AutoMatter
public record IntString(String asString) {

    int asInt() {
        return Integer.parseInt( asString() );
    }
}

AutoMatter generates following code:

  private IntStringBuilder(IntString v) {
    this.asInt = v.asInt();
    this.asString = v.asString();
  }

  private IntStringBuilder(IntStringBuilder v) {
    this.asInt = v.asInt();
    this.asString = v.asString();
  }

  public IntString build() {
    if (asString == null) {
      throw new NullPointerException("asString");
    }
    return new IntString(asInt, asString);
  }

I think that any methods which is not a record component must be ignored by the builder.

Good catch, that definitely looks like a bug. Will take a look asap.

Fixed by #259

cykl commented

Thanks @danielnorberg! I just tested the latest master, it now works as expected.

@cykl Good to hear, thanks for letting me know about the issue!