Skip to content

Add support for Immutables #3157

Open
Open
@requizm

Description

Example:

// User.java
import org.immutables.value.Value;

@Value.Immutable
public interface User {
    @Value.Default
    default String getName() {
        return NameGenerator.random();
    }
}
// ImmutableUser.java
import org.immutables.value.Generated;

@Generated(from = "User", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
public final class ImmutableUser implements User {
  private final String name;

  private ImmutableUser(ImmutableUser.Builder builder) { // What if we ignore this?
    this.name = builder.name != null
        ? builder.name
        : Objects.requireNonNull(User.super.getName(), "name");
  }

  private ImmutableUser(String name) { // Should use this
    this.name = name;
  }

  // ...

  @Generated(from = "User", generator = "Immutables")
  public static final class Builder {
    // ...
  }
}

In this code, it can't find constructor because there is a constructor that uses Builder as a parameter.

I don't want something big like creating constructor using Builder. If the class is auto-generated and the constructor parameter is builder, I want it to ignore it.

I could add @Value.Style(privateNoargConstructor = true) annotation to interface, so there would be noArg constructor but that's just workaround. It's not working with transiant types, etc. I prefer first solution if it's okay.

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions