google / google/auto

Renaming nested builders

Open
#1,435 2 comments 0 reactions 0 assignees View on GitHub
Component: value P3 type=enhancement
Dominant language
Java
Stars
10.6k
Forks
1.2k
Avg merge
6h 32m
Merged PRs (30d)
13

Description

Hi! I'm looking for a way to declare / use nested property builders with names other than default, but can't make it work. I've read https://github.com/google/auto/blob/main/value/userguide/builders-howto.md#accumulate, yet found nothing related.

```java
@AutoValue
public abstract class Animal {
public abstract String name();
public abstract int numberOfLegs();
public abstract ImmutableSet countries();

public static Builder builder() {
return new AutoValue_Animal.Builder();
}

@AutoValue.Builder
public abstract static class Builder {
public abstract Builder setName(String value);
public abstract Builder setNumberOfLegs(int value);
public abstract ImmutableSet.Builder countriesAccumulator(); // <- this doesn't work
public abstract Animal build();
}
}
```

Possibility to use anything other than `fooBuilder()` would be great. This probably means that logic would have to be based entirely on method's return type. This seems to be the way it works in the case of `public static Builder builder()` which can be renamed freely (https://github.com/google/auto/blob/main/value/userguide/builders-howto.md#-use-different-names-besides-builderbuilderbuild).

Ideally, I would like to be able to declare `public abstract ImmutableSet.Builder countries()` with no suffix at all. Currently it leads to name collision with countries getter (as `[AutoValueBuilderReturnType]` nicely explains), but I hope that it is still possible to extend the implementation in a backward compatible way. Distinction between getters and builders seems to be rather unambiguous.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.