Interface AutoValueExtension.Context
-
- Enclosing class:
- AutoValueExtension
public static interface AutoValueExtension.Context
The context of the generation cycle.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Set<ExecutableElement>
abstractMethods()
Returns the complete set of abstract methods defined in or inherited by the@AutoValue
class.TypeElement
autoValueClass()
Returns the annotated class that this generation cycle is based on.default Optional<AutoValueExtension.BuilderContext>
builder()
Returns a representation of theBuilder
associated with the@AutoValue
class, if there is one.default List<AnnotationMirror>
classAnnotationsToCopy(TypeElement classToCopyFrom)
Returns the complete list of annotations defined on theclassToCopyFrom
that should be added to any generated subclass.default String
finalAutoValueClassName()
The fully-qualified name of the last class in theAutoValue
hierarchy.default List<AnnotationMirror>
methodAnnotationsToCopy(ExecutableElement method)
Returns the complete list of annotations defined on themethod
that should be applied to any override of that method.String
packageName()
Returns the package name of the classes to be generated.ProcessingEnvironment
processingEnvironment()
Returns the processing environment of this generation cycle.Map<String,ExecutableElement>
properties()
Returns the ordered collection of properties to be generated by AutoValue.default Map<String,TypeMirror>
propertyTypes()
Returns the properties to be generated by AutoValue, with their types.
-
-
-
Method Detail
-
processingEnvironment
ProcessingEnvironment processingEnvironment()
Returns the processing environment of this generation cycle. This can be used, among other things, to produce compilation warnings or errors, usingProcessingEnvironment.getMessager()
.
-
packageName
String packageName()
Returns the package name of the classes to be generated.
-
autoValueClass
TypeElement autoValueClass()
Returns the annotated class that this generation cycle is based on.Given
@AutoValue public class Foo {...}
, this will beFoo
.
-
finalAutoValueClassName
default String finalAutoValueClassName()
The fully-qualified name of the last class in theAutoValue
hierarchy. For an@AutoValue
classfoo.bar.Baz
, this will befoo.bar.AutoValue_Baz
. The class may be generated by an extension, which will be the current extension if theisFinal
parameter toAutoValueExtension.generateClass(com.google.auto.value.extension.AutoValueExtension.Context, java.lang.String, java.lang.String, boolean)
is true and the returned string is notnull
.For compatibility reasons, this method has a default implementation that throws an exception. The AutoValue processor supplies an implementation that behaves as documented.
-
properties
Map<String,ExecutableElement> properties()
Returns the ordered collection of properties to be generated by AutoValue. Each key is a property name, and the corresponding value is the getter method for that property. For example, if propertybar
is defined byabstract String getBar()
then this map will have an entry mapping"bar"
to theExecutableElement
forgetBar()
.To determine the type of a property, it is best to use
propertyTypes()
rather than looking at the return type of theExecutableElement
in this map. The reason is that the final type of the property might be different because of type variables. For example, if you have...interface Parent<T>
{ T bar(); }@AutoValue abstract class Foo implements Parent<String> {...}
bar
property inFoo
is actuallyString
, but theExecutableElement
will be the the method inParent
, whose return type isT
.
-
propertyTypes
default Map<String,TypeMirror> propertyTypes()
Returns the properties to be generated by AutoValue, with their types. Each key is a property name, and the corresponding value is the type of that property. The order of the map entries is the same as the order of the@AutoValue
properties.For example, if property
bar
is defined byabstract String getBar()
then this map will have an entry mapping"bar"
to theTypeMirror
forString
.For compatibility reasons, this method has a default implementation that throws an exception. The AutoValue processor supplies an implementation that behaves as documented.
-
abstractMethods
Set<ExecutableElement> abstractMethods()
Returns the complete set of abstract methods defined in or inherited by the@AutoValue
class. This includes all methods that define properties (likeabstract String getBar()
), any abstracttoBuilder()
method, and any other abstract method even if it has been consumed by this or another Extension.
-
classAnnotationsToCopy
default List<AnnotationMirror> classAnnotationsToCopy(TypeElement classToCopyFrom)
Returns the complete list of annotations defined on theclassToCopyFrom
that should be added to any generated subclass. Only annotations visible to the@AutoValue
will be present. SeeAutoValue.CopyAnnotations
for more information.The default implementation of this method returns an empty list for compatibility with extensions which may have implemented this interface themselves.
-
methodAnnotationsToCopy
default List<AnnotationMirror> methodAnnotationsToCopy(ExecutableElement method)
Returns the complete list of annotations defined on themethod
that should be applied to any override of that method. Only annotations visible to the@AutoValue
will be present. SeeAutoValue.CopyAnnotations
for more information.The default implementation of this method returns an empty list for compatibility with extensions which may have implemented this interface themselves.
-
builder
default Optional<AutoValueExtension.BuilderContext> builder()
Returns a representation of theBuilder
associated with the@AutoValue
class, if there is one.This method returns
Optional.empty()
if called from within theAutoValueExtension.applicable(com.google.auto.value.extension.AutoValueExtension.Context)
method. If an Extension needsBuilder
information to decide whether it is applicable, it should returntrue
from theAutoValueExtension.applicable(com.google.auto.value.extension.AutoValueExtension.Context)
method and then returnnull
from theAutoValueExtension.generateClass(com.google.auto.value.extension.AutoValueExtension.Context, java.lang.String, java.lang.String, boolean)
method if it does not need to generate a class after all.The default implementation of this method returns
Optional.empty()
for compatibility with extensions which may have implemented this interface themselves.
-
-