class BuilderMethodClassifier
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private javax.lang.model.element.TypeElement |
autoValueClass |
private javax.lang.model.element.TypeElement |
builderType |
private java.util.Set<javax.lang.model.element.ExecutableElement> |
buildMethods |
private static java.lang.String |
COM_GOOGLE_COMMON_COLLECT_IMMUTABLE |
private ErrorReporter |
errorReporter |
private com.google.common.collect.ImmutableMap<java.lang.String,javax.lang.model.element.ExecutableElement> |
getterNameToGetter |
private com.google.common.collect.ImmutableBiMap<javax.lang.model.element.ExecutableElement,java.lang.String> |
getterToPropertyName |
private java.util.Set<java.lang.String> |
propertiesWithBuilderGetters |
private com.google.common.collect.Multimap<java.lang.String,javax.lang.model.element.ExecutableElement> |
propertyNameToPrefixedSetters |
private java.util.Map<java.lang.String,javax.lang.model.element.ExecutableElement> |
propertyNameToPropertyBuilder |
private com.google.common.collect.Multimap<java.lang.String,javax.lang.model.element.ExecutableElement> |
propertyNameToUnprefixedSetters |
private boolean |
settersPrefixed |
private static com.google.common.base.Equivalence<javax.lang.model.type.TypeMirror> |
TYPE_EQUIVALENCE |
private javax.lang.model.util.Types |
typeUtils |
Modifier | Constructor and Description |
---|---|
private |
BuilderMethodClassifier(ErrorReporter errorReporter,
javax.annotation.processing.ProcessingEnvironment processingEnv,
javax.lang.model.element.TypeElement autoValueClass,
javax.lang.model.element.TypeElement builderType,
com.google.common.collect.ImmutableBiMap<javax.lang.model.element.ExecutableElement,java.lang.String> getterToPropertyName) |
Modifier and Type | Method and Description |
---|---|
(package private) java.util.Set<javax.lang.model.element.ExecutableElement> |
buildMethods()
Returns the methods that were identified as
build() methods. |
private boolean |
canMakeCopyUsing(javax.lang.model.element.ExecutableElement copyOfMethod,
javax.lang.model.type.TypeMirror targetType,
javax.lang.model.type.TypeMirror parameterType)
Returns true if
copyOfMethod can be used to copy the parameterType
to the targetType . |
private boolean |
canMakeCopyUsing(com.google.common.collect.ImmutableList<javax.lang.model.element.ExecutableElement> copyOfMethods,
javax.lang.model.element.ExecutableElement valueGetter,
javax.lang.model.element.ExecutableElement setter)
Checks that the given setter method has a parameter type that can be copied to the return type
of the given getter using one of the given
copyOf methods. |
private boolean |
checkSetterParameter(javax.lang.model.element.ExecutableElement valueGetter,
javax.lang.model.element.ExecutableElement setter)
Checks that the given setter method has a parameter type that is compatible with the return
type of the given getter.
|
(package private) static com.google.common.base.Optional<BuilderMethodClassifier> |
classify(java.lang.Iterable<javax.lang.model.element.ExecutableElement> methods,
ErrorReporter errorReporter,
javax.annotation.processing.ProcessingEnvironment processingEnv,
javax.lang.model.element.TypeElement autoValueClass,
javax.lang.model.element.TypeElement builderType,
com.google.common.collect.ImmutableBiMap<javax.lang.model.element.ExecutableElement,java.lang.String> getterToPropertyName)
Classifies the given methods from a builder type and its ancestors.
|
private boolean |
classifyGetter(javax.lang.model.element.ExecutableElement builderGetter,
javax.lang.model.element.ExecutableElement originalGetter) |
private boolean |
classifyMethod(javax.lang.model.element.ExecutableElement method)
Classifies a method and update the state of this object based on what is found.
|
private boolean |
classifyMethodNoArgs(javax.lang.model.element.ExecutableElement method)
Classifies a method given that it has no arguments.
|
private boolean |
classifyMethodOneArg(javax.lang.model.element.ExecutableElement method)
Classifies a method given that it has one argument.
|
private boolean |
classifyMethods(java.lang.Iterable<javax.lang.model.element.ExecutableElement> methods)
Classifies the given methods and sets the state of this object based on what is found.
|
private boolean |
classifyPropertyBuilder(javax.lang.model.element.ExecutableElement method,
java.lang.String property) |
private com.google.common.collect.ImmutableList<javax.lang.model.element.ExecutableElement> |
copyOfMethods(javax.lang.model.type.TypeMirror targetType)
Returns
copyOf methods from the given type. |
private java.lang.String |
prefixWithSet(java.lang.String propertyName) |
(package private) com.google.common.collect.ImmutableSet<java.lang.String> |
propertiesWithBuilderGetters()
Returns the set of properties that have getters in the builder.
|
(package private) java.util.Map<java.lang.String,javax.lang.model.element.ExecutableElement> |
propertyNameToPropertyBuilder() |
(package private) com.google.common.collect.ImmutableMultimap<java.lang.String,javax.lang.model.element.ExecutableElement> |
propertyNameToSetters()
Returns a multimap from the name of a property to the methods that set it.
|
private java.lang.String |
typeParamsString() |
private static final com.google.common.base.Equivalence<javax.lang.model.type.TypeMirror> TYPE_EQUIVALENCE
private final ErrorReporter errorReporter
private final javax.lang.model.util.Types typeUtils
private final javax.lang.model.element.TypeElement autoValueClass
private final javax.lang.model.element.TypeElement builderType
private final com.google.common.collect.ImmutableBiMap<javax.lang.model.element.ExecutableElement,java.lang.String> getterToPropertyName
private final com.google.common.collect.ImmutableMap<java.lang.String,javax.lang.model.element.ExecutableElement> getterNameToGetter
private final java.util.Set<javax.lang.model.element.ExecutableElement> buildMethods
private final java.util.Set<java.lang.String> propertiesWithBuilderGetters
private final com.google.common.collect.Multimap<java.lang.String,javax.lang.model.element.ExecutableElement> propertyNameToPrefixedSetters
private final com.google.common.collect.Multimap<java.lang.String,javax.lang.model.element.ExecutableElement> propertyNameToUnprefixedSetters
private final java.util.Map<java.lang.String,javax.lang.model.element.ExecutableElement> propertyNameToPropertyBuilder
private boolean settersPrefixed
private static final java.lang.String COM_GOOGLE_COMMON_COLLECT_IMMUTABLE
private BuilderMethodClassifier(ErrorReporter errorReporter, javax.annotation.processing.ProcessingEnvironment processingEnv, javax.lang.model.element.TypeElement autoValueClass, javax.lang.model.element.TypeElement builderType, com.google.common.collect.ImmutableBiMap<javax.lang.model.element.ExecutableElement,java.lang.String> getterToPropertyName)
static com.google.common.base.Optional<BuilderMethodClassifier> classify(java.lang.Iterable<javax.lang.model.element.ExecutableElement> methods, ErrorReporter errorReporter, javax.annotation.processing.ProcessingEnvironment processingEnv, javax.lang.model.element.TypeElement autoValueClass, javax.lang.model.element.TypeElement builderType, com.google.common.collect.ImmutableBiMap<javax.lang.model.element.ExecutableElement,java.lang.String> getterToPropertyName)
methods
- the methods in builderType
and its ancestors.errorReporter
- where to report errors.autoValueClass
- the AutoValue
class containing the builder.builderType
- the builder class or interface within autoValueClass
.getterToPropertyName
- a map from getter methods to the properties they get.Optional
that contains the results of the classification if it was
successful or nothing if it was not.com.google.common.collect.ImmutableMultimap<java.lang.String,javax.lang.model.element.ExecutableElement> propertyNameToSetters()
@AutoValue
class called foo()
or
getFoo()
then the name of the property is foo
and there will be an entry in
the map where the key is "foo"
and the value is a method in the builder called
foo
or setFoo
.java.util.Map<java.lang.String,javax.lang.model.element.ExecutableElement> propertyNameToPropertyBuilder()
com.google.common.collect.ImmutableSet<java.lang.String> propertiesWithBuilderGetters()
@AutoValue
class called foo()
or getFoo()
then the name of the property is foo
, If the builder also has a method of the same name
(foo()
or getFoo()
) then the set returned here will contain foo
.java.util.Set<javax.lang.model.element.ExecutableElement> buildMethods()
build()
methods. These are methods that
have no parameters and return the @AutoValue
type, conventionally called
build()
.private boolean classifyMethods(java.lang.Iterable<javax.lang.model.element.ExecutableElement> methods)
private boolean classifyMethod(javax.lang.model.element.ExecutableElement method)
private boolean classifyMethodNoArgs(javax.lang.model.element.ExecutableElement method)
build()
method, meaning that its return type must be the
@AutoValue
class.private boolean classifyGetter(javax.lang.model.element.ExecutableElement builderGetter, javax.lang.model.element.ExecutableElement originalGetter)
private boolean classifyPropertyBuilder(javax.lang.model.element.ExecutableElement method, java.lang.String property)
private boolean classifyMethodOneArg(javax.lang.model.element.ExecutableElement method)
foo(T)
or setFoo(T)
, where
the AutoValue
class has a property called foo
of type T
.private boolean checkSetterParameter(javax.lang.model.element.ExecutableElement valueGetter, javax.lang.model.element.ExecutableElement setter)
ImmutableList.copyOf
.private boolean canMakeCopyUsing(com.google.common.collect.ImmutableList<javax.lang.model.element.ExecutableElement> copyOfMethods, javax.lang.model.element.ExecutableElement valueGetter, javax.lang.model.element.ExecutableElement setter)
copyOf
methods.private boolean canMakeCopyUsing(javax.lang.model.element.ExecutableElement copyOfMethod, javax.lang.model.type.TypeMirror targetType, javax.lang.model.type.TypeMirror parameterType)
copyOfMethod
can be used to copy the parameterType
to the targetType
.private com.google.common.collect.ImmutableList<javax.lang.model.element.ExecutableElement> copyOfMethods(javax.lang.model.type.TypeMirror targetType)
copyOf
methods from the given type. These are static methods called
copyOf
with a single parameter. All of Guava's concrete immutable collection types have
at least one such method, but we will also accept other classes with an appropriate method,
such as EnumSet
.private java.lang.String prefixWithSet(java.lang.String propertyName)
private java.lang.String typeParamsString()