Top Description Inners Fields Constructors Methods
com.google.auto.value.processor

pack-priv Class BuilderSpec

extends Object
Class Inheritance
Static Imports
com.google.auto.common.MoreElements.getLocalAndInheritedMethods, .MoreStreams.toImmutableSet, com.google.auto.value.processor.AutoValueishProcessor.hasAnnotationMirror, .AutoValueishProcessor.hasVisibleNoArgConstructor, .AutoValueishProcessor.nullableAnnotationFor, .ClassNames.AUTO_VALUE_BUILDER_NAME, com.google.common.collect.Sets.immutableEnumSet, java.util.stream.Collectors.toList, .Collectors.toSet, javax.lang.model.util.ElementFilter.methodsIn, javax.lang.model.util.ElementFilter.typesIn

Support for AutoValue builders.
Author
Éamonn McManus

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
BuilderSpec.Builder

Representation of an AutoValue.Builder class or interface.

pack-priv static class
BuilderSpec.Copier

Specifies how to copy a parameter value into the target type.

public static class
BuilderSpec.PropertyGetter

Information about a builder property getter, referenced from the autovalue.vm template.

public static class
BuilderSpec.PropertySetter

Information about a property setter, referenced from the autovalue.vm template.

Field Summary

Modifier and TypeField and Description
private final javax.lang.model.element.TypeElement
private static final ImmutableSet<javax.lang.model.element.ElementKind>
private final ErrorReporter
private final javax.annotation.processing.ProcessingEnvironment

Constructor Summary

AccessConstructor and Description
pack-priv
BuilderSpec(javax.lang.model.element.TypeElement autoValueClass, javax.annotation.processing.ProcessingEnvironment processingEnv, ErrorReporter errorReporter)

Method Summary

Modifier and TypeMethod and Description
pack-priv static ImmutableSet<javax.lang.model.element.ExecutableElement>
abstractMethods(javax.lang.model.element.TypeElement typeElement, javax.annotation.processing.ProcessingEnvironment processingEnv)

Returns a set of all abstract methods in the given TypeElement or inherited from ancestors.

private Optional<BuilderSpec.Builder>
builderFrom(javax.lang.model.element.TypeElement builderTypeElement)

Returns a representation of the given @AutoValue.Builder class or interface.

private Optional<String>
findBuilderError(javax.lang.model.element.TypeElement builderTypeElement)

Finds why this @AutoValue.Builder class is bad, if it is bad.

pack-priv Optional<BuilderSpec.Builder>
getBuilder()

Determines if the @AutoValue class for this instance has a correct nested @AutoValue.Builder class or interface and return a representation of it in an Optional if so.

private static boolean
sameTypeParameters(javax.lang.model.element.TypeElement a, javax.lang.model.element.TypeElement b)

pack-priv static boolean
sameTypeParameters(List<? extends javax.lang.model.element.TypeParameterElement> aParams, List<? extends javax.lang.model.element.TypeParameterElement> bParams)

private String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

autoValueClassback to summary
private final javax.lang.model.element.TypeElement autoValueClass
CLASS_OR_INTERFACEback to summary
private static final ImmutableSet<javax.lang.model.element.ElementKind> CLASS_OR_INTERFACE
errorReporterback to summary
private final ErrorReporter errorReporter
processingEnvback to summary
private final javax.annotation.processing.ProcessingEnvironment processingEnv

Constructor Detail

BuilderSpecback to summary
pack-priv BuilderSpec(javax.lang.model.element.TypeElement autoValueClass, javax.annotation.processing.ProcessingEnvironment processingEnv, ErrorReporter errorReporter)

Method Detail

abstractMethodsback to summary
pack-priv static ImmutableSet<javax.lang.model.element.ExecutableElement> abstractMethods(javax.lang.model.element.TypeElement typeElement, javax.annotation.processing.ProcessingEnvironment processingEnv)

Returns a set of all abstract methods in the given TypeElement or inherited from ancestors. If any of the abstract methods has a return type or parameter type that is not currently defined then this method will throw an exception that will cause us to defer processing of the current class until a later annotation-processing round.

builderFromback to summary
private Optional<BuilderSpec.Builder> builderFrom(javax.lang.model.element.TypeElement builderTypeElement)

Returns a representation of the given @AutoValue.Builder class or interface. If the class or interface has abstract methods that could not be part of any builder, emits error messages and returns Optional.empty().

findBuilderErrorback to summary
private Optional<String> findBuilderError(javax.lang.model.element.TypeElement builderTypeElement)

Finds why this @AutoValue.Builder class is bad, if it is bad.

getBuilderback to summary
pack-priv Optional<BuilderSpec.Builder> getBuilder()

Determines if the @AutoValue class for this instance has a correct nested @AutoValue.Builder class or interface and return a representation of it in an Optional if so.

sameTypeParametersback to summary
private static boolean sameTypeParameters(javax.lang.model.element.TypeElement a, javax.lang.model.element.TypeElement b)
sameTypeParametersback to summary
pack-priv static boolean sameTypeParameters(List<? extends javax.lang.model.element.TypeParameterElement> aParams, List<? extends javax.lang.model.element.TypeParameterElement> bParams)
typeParamsStringback to summary
private String typeParamsString()
com.google.auto.value.processor back to summary

pack-priv Class BuilderSpec.Builder

extends Object
implements BuilderContext
Class Inheritance
All Implemented Interfaces
com.google.auto.value.extension.AutoValueExtension.BuilderContext

Representation of an AutoValue.Builder class or interface.

Field Summary

Modifier and TypeField and Description
private final javax.lang.model.element.TypeElement
private javax.lang.model.element.ExecutableElement
private BuilderMethodClassifier<?>
private ImmutableSet<javax.lang.model.element.ExecutableElement>

Constructor Summary

AccessConstructor and Description
pack-priv
Builder(javax.lang.model.element.TypeElement builderTypeElement)

Method Summary

Modifier and TypeMethod and Description
public javax.lang.model.element.ExecutableElement
public Set<javax.lang.model.element.ExecutableElement>
builderMethods()

Implements com.google.auto.value.extension.AutoValueExtension.BuilderContext.builderMethods.

Returns static no-argument methods in the @AutoValue class that return the builder type.

public javax.lang.model.element.TypeElement
builderType()

Implements com.google.auto.value.extension.AutoValueExtension.BuilderContext.builderType.

Returns the @AutoValue.Builder interface or abstract class that this object represents.

public Optional<javax.lang.model.element.ExecutableElement>
buildMethod()

Implements com.google.auto.value.extension.AutoValueExtension.BuilderContext.buildMethod.

Returns the method build() in the builder class, if it exists and returns the @AutoValue type.

pack-priv void
pack-priv void
defineVarsForAutoValue(AutoValueOrBuilderTemplateVars vars, ImmutableBiMap<javax.lang.model.element.ExecutableElement, String> getterToPropertyName, Nullables nullables)

private boolean
erasedTypeIs(javax.lang.model.type.TypeMirror type, javax.lang.model.element.TypeElement baseType)

public Map<String, javax.lang.model.element.ExecutableElement>
propertyBuilders()

Implements com.google.auto.value.extension.AutoValueExtension.BuilderContext.propertyBuilders.

Returns a map from property names to property builders.

public Map<String, Set<javax.lang.model.element.ExecutableElement>>
setters()

Implements com.google.auto.value.extension.AutoValueExtension.BuilderContext.setters.

Returns a map from property names to the corresponding setters.

public Set<javax.lang.model.element.ExecutableElement>
toBuilderMethods()

Implements com.google.auto.value.extension.AutoValueExtension.BuilderContext.toBuilderMethods.

Returns abstract no-argument methods in the @AutoValue class that return the builder type.

pack-priv ImmutableSet<javax.lang.model.element.ExecutableElement>
toBuilderMethods(javax.lang.model.util.Types typeUtils, javax.lang.model.element.TypeElement autoValueType, Set<javax.lang.model.element.ExecutableElement> abstractMethods)

Finds any methods in the set that return the builder type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

builderTypeElementback to summary
private final javax.lang.model.element.TypeElement builderTypeElement
buildMethodback to summary
private javax.lang.model.element.ExecutableElement buildMethod
classifierback to summary
private BuilderMethodClassifier<?> classifier
toBuilderMethodsback to summary
private ImmutableSet<javax.lang.model.element.ExecutableElement> toBuilderMethods

Constructor Detail

Builderback to summary
pack-priv Builder(javax.lang.model.element.TypeElement builderTypeElement)

Method Detail

autoBuildMethodback to summary
public javax.lang.model.element.ExecutableElement autoBuildMethod()

Implements com.google.auto.value.extension.AutoValueExtension.BuilderContext.autoBuildMethod.

Doc from com.google.auto.value.extension.AutoValueExtension.BuilderContext.autoBuildMethod.

Returns the abstract build method. If the @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.

Annotations
@Override
builderMethodsback to summary
public Set<javax.lang.model.element.ExecutableElement> builderMethods()

Implements com.google.auto.value.extension.AutoValueExtension.BuilderContext.builderMethods.

Doc from com.google.auto.value.extension.AutoValueExtension.BuilderContext.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 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.

Annotations
@Override
builderTypeback to summary
public javax.lang.model.element.TypeElement builderType()

Implements com.google.auto.value.extension.AutoValueExtension.BuilderContext.builderType.

Doc from com.google.auto.value.extension.AutoValueExtension.BuilderContext.builderType.

Returns the @AutoValue.Builder interface or abstract class that this object represents.

Annotations
@Override
buildMethodback to summary
public Optional<javax.lang.model.element.ExecutableElement> buildMethod()

Implements com.google.auto.value.extension.AutoValueExtension.BuilderContext.buildMethod.

Doc from com.google.auto.value.extension.AutoValueExtension.BuilderContext.buildMethod.

Returns the method 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.

Annotations
@Override
defineVarsback to summary
pack-priv void defineVars(AutoValueOrBuilderTemplateVars vars, BuilderMethodClassifier<?> classifier)
defineVarsForAutoValueback to summary
pack-priv void defineVarsForAutoValue(AutoValueOrBuilderTemplateVars vars, ImmutableBiMap<javax.lang.model.element.ExecutableElement, String> getterToPropertyName, Nullables nullables)
erasedTypeIsback to summary
private boolean erasedTypeIs(javax.lang.model.type.TypeMirror type, javax.lang.model.element.TypeElement baseType)
propertyBuildersback to summary
public Map<String, javax.lang.model.element.ExecutableElement> propertyBuilders()

Implements com.google.auto.value.extension.AutoValueExtension.BuilderContext.propertyBuilders.

Doc from com.google.auto.value.extension.AutoValueExtension.BuilderContext.propertyBuilders.

Returns a map from property names to property builders. For example, if there is a property 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().

Annotations
@Override
settersback to summary
public Map<String, Set<javax.lang.model.element.ExecutableElement>> setters()

Implements com.google.auto.value.extension.AutoValueExtension.BuilderContext.setters.

Doc from com.google.auto.value.extension.AutoValueExtension.BuilderContext.setters.

Returns a map from property names to the corresponding setters. A property may have more than one setter. For example, an ImmutableList<String> might be set by setFoo(ImmutableList<String>) and setFoo(String[]).

Annotations
@Override
toBuilderMethodsback to summary
public Set<javax.lang.model.element.ExecutableElement> toBuilderMethods()

Implements com.google.auto.value.extension.AutoValueExtension.BuilderContext.toBuilderMethods.

Doc from com.google.auto.value.extension.AutoValueExtension.BuilderContext.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 method Foo.toBuilder().

Annotations
@Override
toBuilderMethodsback to summary
pack-priv ImmutableSet<javax.lang.model.element.ExecutableElement> toBuilderMethods(javax.lang.model.util.Types typeUtils, javax.lang.model.element.TypeElement autoValueType, Set<javax.lang.model.element.ExecutableElement> abstractMethods)

Finds any methods in the set that return the builder type. If the builder has type parameters <A, B>, then the return type of the method must be Builder<A, B> with the same parameter names. We enforce elsewhere that the names and bounds of the builder parameters must be the same as those of the @AutoValue class. Here's a correct example:

@AutoValue abstract class Foo<A extends Number, B> {
  abstract int someProperty();

  abstract Builder<A, B> toBuilder();

  interface Builder<A extends Number, B> {...}
}

We currently impose that there cannot be more than one such method.

com.google.auto.value.processor back to summary

pack-priv Class BuilderSpec.Copier

extends Object
Class Inheritance

Specifies how to copy a parameter value into the target type. This might be the identity, or it might be something like ImmutableList.of(...) or Optional.ofNullable(...).

Field Summary

Modifier and TypeField and Description
private final boolean
private final Function<String, String>
pack-priv static final BuilderSpec.Copier

Constructor Summary

AccessConstructor and Description
private
Copier(Function<String, String> copy, boolean acceptsNull)

Method Summary

Modifier and TypeMethod and Description
pack-priv static BuilderSpec.Copier
pack-priv static BuilderSpec.Copier
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

acceptsNullback to summary
private final boolean acceptsNull
copyback to summary
private final Function<String, String> copy
IDENTITYback to summary
pack-priv static final BuilderSpec.Copier IDENTITY

Constructor Detail

Copierback to summary
private Copier(Function<String, String> copy, boolean acceptsNull)

Method Detail

acceptingNullback to summary
pack-priv static BuilderSpec.Copier acceptingNull(Function<String, String> copy)
notAcceptingNullback to summary
pack-priv static BuilderSpec.Copier notAcceptingNull(Function<String, String> copy)
com.google.auto.value.processor back to summary

public Class BuilderSpec.PropertyGetter

extends Object
Class Inheritance

Information about a builder property getter, referenced from the autovalue.vm template. A property called foo (defined by a method T foo() or T getFoo()) can have a getter method in the builder with the same name (foo() or getFoo()) and a return type of either T or Optional<T>. The Optional<T> form can be used to tell whether the property has been set. Here, Optional<T> can be either java.util.Optional or com.google.common.base.Optional. If T is int, long, or double, then instead of Optional<T> we can have OptionalInt etc. If T is a primitive type (including these ones but also the other five) then Optional<T> can be the corresponding boxed type.

Field Summary

Modifier and TypeField and Description
private final String
private final String
private final Optionalish
private final String

Constructor Summary

AccessConstructor and Description
pack-priv
PropertyGetter(javax.lang.model.element.ExecutableElement
the source method which this getter is implementing.
method
,
String
the type that the getter returns. This is written to take imports into account, so it might be List<String> for example. It is either identical to the type of the corresponding getter in the @AutoValue class, or it is an optional wrapper, like Optional<List<String>>.
type
,
Optionalish
a representation of the Optional type that the getter returns, if this is an optional getter, or null otherwise. An optional getter is one that returns Optional<T> rather than T, as explained above.
optional
)

Makes a new PropertyGetter instance.

Method Summary

Modifier and TypeMethod and Description
public String
public String
public Optionalish
public String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

accessback to summary
private final String access
nameback to summary
private final String name
optionalback to summary
private final Optionalish optional
typeback to summary
private final String type

Constructor Detail

PropertyGetterback to summary
pack-priv PropertyGetter(javax.lang.model.element.ExecutableElement method, String type, Optionalish optional)

Makes a new PropertyGetter instance.

Parameters
method:javax.lang.model.element.ExecutableElement

the source method which this getter is implementing.

type:String

the type that the getter returns. This is written to take imports into account, so it might be List<String> for example. It is either identical to the type of the corresponding getter in the @AutoValue class, or it is an optional wrapper, like Optional<List<String>>.

optional:Optionalish

a representation of the Optional type that the getter returns, if this is an optional getter, or null otherwise. An optional getter is one that returns Optional<T> rather than T, as explained above.

Method Detail

getAccessback to summary
public String getAccess()
getNameback to summary
public String getName()
getOptionalback to summary
public Optionalish getOptional()
getTypeback to summary
public String getType()
com.google.auto.value.processor back to summary

public Class BuilderSpec.PropertySetter

extends Object
Class Inheritance

Information about a property setter, referenced from the autovalue.vm template. A property called foo (defined by a method T foo() or T getFoo()) can have a setter method foo(T) or setFoo(T) that returns the builder type. Additionally, it can have a setter with a type that can be copied to T through a copyOf method; for example a property foo of type ImmutableSet<String> can be set with a method setFoo(Collection<String> foos). And, if T is Optional, it can have a setter with a type that can be copied to T through Optional.of.

Field Summary

Modifier and TypeField and Description
private final String
private final BuilderSpec.Copier
private final String
private final String
private final String
private final boolean
private final javax.lang.model.element.ExecutableElement

Constructor Summary

AccessConstructor and Description
pack-priv
PropertySetter(javax.lang.model.element.ExecutableElement setter, javax.lang.model.type.TypeMirror parameterType, BuilderSpec.Copier copier)

Method Summary

Modifier and TypeMethod and Description
public String
public String
public String
public String
public String
public boolean
pack-priv javax.lang.model.element.ExecutableElement
private static String
parameterTypeString(javax.lang.model.element.ExecutableElement setter, javax.lang.model.type.TypeMirror parameterType)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

accessback to summary
private final String access
copierback to summary
private final BuilderSpec.Copier copier
nameback to summary
private final String name
nullableAnnotationback to summary
private final String nullableAnnotation
parameterTypeStringback to summary
private final String parameterTypeString
primitiveParameterback to summary
private final boolean primitiveParameter
setterback to summary
private final javax.lang.model.element.ExecutableElement setter

Constructor Detail

PropertySetterback to summary
pack-priv PropertySetter(javax.lang.model.element.ExecutableElement setter, javax.lang.model.type.TypeMirror parameterType, BuilderSpec.Copier copier)

Method Detail

copyback to summary
public String copy(AutoValueishProcessor.Property property)
getAccessback to summary
public String getAccess()
getNameback to summary
public String getName()
getNullableAnnotationback to summary
public String getNullableAnnotation()
getParameterTypeback to summary
public String getParameterType()
getPrimitiveParameterback to summary
public boolean getPrimitiveParameter()
getSetterback to summary
pack-priv javax.lang.model.element.ExecutableElement getSetter()
parameterTypeStringback to summary
private static String parameterTypeString(javax.lang.model.element.ExecutableElement setter, javax.lang.model.type.TypeMirror parameterType)