Interface AutoValueExtension.BuilderContext
-
- Enclosing class:
- AutoValueExtension
public static interface AutoValueExtension.BuilderContext
Represents aBuilder
associated with an@AutoValue
class.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ExecutableElement
autoBuildMethod()
Returns the abstract build method.Set<ExecutableElement>
builderMethods()
Returns static no-argument methods in the@AutoValue
class that return the builder type.TypeElement
builderType()
Returns the@AutoValue.Builder
interface or abstract class that this object represents.Optional<ExecutableElement>
buildMethod()
Returns the methodbuild()
in the builder class, if it exists and returns the@AutoValue
type.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@AutoValue
class that return the builder type.
-
-
-
Method Detail
-
builderType
TypeElement builderType()
Returns the@AutoValue.Builder
interface or abstract class that this object represents.
-
toBuilderMethods
Set<ExecutableElement> toBuilderMethods()
Returns abstract no-argument methods in the@AutoValue
class that return the builder type.Consider a class like this:
@AutoValue
abstract class Foo { abstract String bar(); abstract Builder toBuilder(); ...@AutoValue.Builder
abstract static class Builder {...} }Here
toBuilderMethods()
will return a set containing the methodFoo.toBuilder()
.
-
builderMethods
Set<ExecutableElement> builderMethods()
Returns static no-argument methods in the@AutoValue
class that return the builder type.Consider a class like this:
@AutoValue
abstract class Foo { abstract String bar(); static Builder builder() { return new AutoValue_Foo.Builder() .setBar("default bar"); }@AutoValue.Builder
abstract 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@AutoValue
type. This is the method that generated code for@AutoValue class Foo
should call in order to get an instance ofFoo
from 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.Builder
class, 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@AutoValue
class 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 propertyfoo
defined byabstract ImmutableList<String> foo();
orabstract ImmutableList<String> getFoo();
in the@AutoValue
class, then there can potentially be a builder defined byabstract ImmutableList.Builder<String> fooBuilder();
in the@AutoValue.Builder
class. This map would then map"foo"
to theExecutableElement
representingfooBuilder()
.
-
-