public static interface AutoValueExtension.BuilderContext
Builder associated with an @AutoValue class.| Modifier and Type | Method and Description |
|---|---|
javax.lang.model.element.ExecutableElement |
autoBuildMethod()
Returns the abstract build method.
|
java.util.Set<javax.lang.model.element.ExecutableElement> |
builderMethods()
Returns static no-argument methods in the
@AutoValue class that return the builder
type. |
javax.lang.model.element.TypeElement |
builderType()
Returns the
@AutoValue.Builder interface or abstract class that this object
represents. |
java.util.Optional<javax.lang.model.element.ExecutableElement> |
buildMethod()
Returns the method
build() in the builder class, if it exists and returns the
@AutoValue type. |
java.util.Map<java.lang.String,javax.lang.model.element.ExecutableElement> |
propertyBuilders()
Returns a map from property names to property builders.
|
java.util.Map<java.lang.String,java.util.Set<javax.lang.model.element.ExecutableElement>> |
setters()
Returns a map from property names to the corresponding setters.
|
java.util.Set<javax.lang.model.element.ExecutableElement> |
toBuilderMethods()
Returns abstract no-argument methods in the
@AutoValue class that return the builder
type. |
javax.lang.model.element.TypeElement builderType()
@AutoValue.Builder interface or abstract class that this object
represents.java.util.Set<javax.lang.model.element.ExecutableElement> toBuilderMethods()
@AutoValue class 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 method
Foo.toBuilder().
java.util.Set<javax.lang.model.element.ExecutableElement> builderMethods()
@AutoValue class 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 method
Foo.builder(). Generated code should usually call this method in preference to
constructing AutoValue_Foo.Builder() directly, because this method can establish
default values for properties, as it does here.
java.util.Optional<javax.lang.model.element.ExecutableElement> buildMethod()
build() 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 of Foo from its
builder. The returned method is called build(); 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 method autoBuild() that is
implemented in the generated subclass. The build() method can then do validation,
defaulting, and so on.
javax.lang.model.element.ExecutableElement autoBuildMethod()
@AutoValue class is Foo, this is an
abstract no-argument method in the builder class that returns Foo. This might be
called build(), or, following a common convention, it might be called
autoBuild() and used in the implementation of a build() 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.
java.util.Map<java.lang.String,java.util.Set<javax.lang.model.element.ExecutableElement>> setters()
ImmutableList<String> might be set by
setFoo(ImmutableList<String>) and setFoo(String[]).java.util.Map<java.lang.String,javax.lang.model.element.ExecutableElement> propertyBuilders()
foo defined by abstract ImmutableList<String> foo(); or
abstract ImmutableList<String> getFoo(); in the @AutoValue class,
then there can potentially be a builder defined by
abstract ImmutableList.Builder<String> fooBuilder(); in the
@AutoValue.Builder class. This map would then map "foo" to the
ExecutableElement representing fooBuilder().Copyright © 2020 Google LLC. All Rights Reserved.