Interface AutoValueExtension.BuilderContext
-
- Enclosing class:
- AutoValueExtension
public static interface AutoValueExtension.BuilderContextRepresents aBuilderassociated with an@AutoValueclass.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ExecutableElementautoBuildMethod()Returns the abstract build method.Set<ExecutableElement>builderMethods()Returns static no-argument methods in the@AutoValueclass that return the builder type.TypeElementbuilderType()Returns the@AutoValue.Builderinterface or abstract class that this object represents.Optional<ExecutableElement>buildMethod()Returns the methodbuild()in the builder class, if it exists and returns the@AutoValuetype.Map<String,ExecutableElement>propertyBuilders()Returns a map from property names to property builders.Map<String,Set<ExecutableElement>>setters()Returns a map from property names to the corresponding setters.Set<ExecutableElement>toBuilderMethods()Returns abstract no-argument methods in the@AutoValueclass that return the builder type.
-
-
-
Method Detail
-
builderType
TypeElement builderType()
Returns the@AutoValue.Builderinterface or abstract class that this object represents.
-
toBuilderMethods
Set<ExecutableElement> toBuilderMethods()
Returns abstract no-argument methods in the@AutoValueclass that return the builder type.Consider a class like this:
@AutoValueabstract class Foo { abstract String bar(); abstract Builder toBuilder(); ...@AutoValue.Builderabstract static class Builder {...} }Here
toBuilderMethods()will return a set containing the methodFoo.toBuilder().
-
builderMethods
Set<ExecutableElement> builderMethods()
Returns static no-argument methods in the@AutoValueclass that return the builder type.Consider a class like this:
@AutoValueabstract class Foo { abstract String bar(); static Builder builder() { return new AutoValue_Foo.Builder() .setBar("default bar"); }@AutoValue.Builderabstract class Builder { abstract Builder setBar(String x); abstract Foo build(); } }Here
builderMethods()will return a set containing the methodFoo.builder(). Generated code should usually call this method in preference to constructingAutoValue_Foo.Builder()directly, because this method can establish default values for properties, as it does here.
-
buildMethod
Optional<ExecutableElement> buildMethod()
Returns the methodbuild()in the builder class, if it exists and returns the@AutoValuetype. This is the method that generated code for@AutoValue class Fooshould call in order to get an instance ofFoofrom its builder. The returned method is calledbuild(); if the builder uses some other name then extensions have no good way to guess how they should build.A common convention is for
build()to be a concrete method in the@AutoValue.Builderclass, which calls an abstract methodautoBuild()that is implemented in the generated subclass. Thebuild()method can then do validation, defaulting, and so on.
-
autoBuildMethod
ExecutableElement autoBuildMethod()
Returns the abstract build method. If the@AutoValueclass isFoo, this is an abstract no-argument method in the builder class that returnsFoo. This might be calledbuild(), or, following a common convention, it might be calledautoBuild()and used in the implementation of abuild()method that is defined in the builder class.Extensions should call the
build()method in preference to this one. But they should override this one if they want to customize build-time behaviour.
-
setters
Map<String,Set<ExecutableElement>> setters()
Returns a map from property names to the corresponding setters. A property may have more than one setter. For example, anImmutableList<String>might be set bysetFoo(ImmutableList<String>)andsetFoo(String[]).
-
propertyBuilders
Map<String,ExecutableElement> propertyBuilders()
Returns a map from property names to property builders. For example, if there is a propertyfoodefined byabstract ImmutableList<String> foo();orabstract ImmutableList<String> getFoo();in the@AutoValueclass, then there can potentially be a builder defined byabstract ImmutableList.Builder<String> fooBuilder();in the@AutoValue.Builderclass. This map would then map"foo"to theExecutableElementrepresentingfooBuilder().
-
-