Skip to content

Renaming nested builders #1435

Open
Open
@perceptron8

Description

@perceptron8

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.

@AutoValue
public abstract class Animal {
	public abstract String name();
	public abstract int numberOfLegs();
	public abstract ImmutableSet<String> 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<String> 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<String> 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions