Extensions are discovered at compile time using the java. APIs,
allowing them to run without any additional annotations. To be found by ServiceLoader, an
extension class must be public with a public no-arg constructor, and its fully-qualified name
must appear in a file called META-INF/services/com.google.auto.value.extension.AutoValueExtension in a jar that is on the
compiler's -classpath or -processorpath.
When the AutoValue processor runs for a class Foo, it will ask each Extension whether
it is applicable. Suppose two Extensions reply that they are. Then
the processor will generate the AutoValue logic in a direct subclass of Foo, and it
will ask the first Extension to generate a subclass of that, and the second Extension to generate
a subclass of the subclass. So we might have this hierarchy:
@AutoValue abstract class Foo {...} // the hand-written class
abstract class $$AutoValue_Foo extends Foo {...} // generated by AutoValue processor
abstract class $AutoValue_Foo extends $$AutoValue_Foo {...} // generated by first Extension
final class AutoValue_Foo extends $AutoValue_Foo {...} // generated by second Extension
(The exact naming scheme illustrated here is not fixed and should not be relied on.)
If an Extension needs its generated class to be the final class in the inheritance hierarchy,
its mustBeFinal(Context) method returns true. Only one Extension can return true for a
given context. Only generated classes that will be the final class in the inheritance hierarchy
can be declared final. All others should be declared abstract.
The first generated class in the hierarchy will always be the one generated by the AutoValue
processor and the last one will always be the one generated by the Extension that mustBeFinal, if any. Other than that, the order of the classes in the hierarchy is unspecified.
The last class in the hierarchy is AutoValue_Foo and that is the one that the
Foo class will reference, for example with new AutoValue_Foo(...).
Each Extension must also be sure to generate a constructor with arguments corresponding to all
properties in com.,
in order, and to call the superclass constructor with the same arguments. This constructor must
have at least package visibility.
Because the class generated by the AutoValue processor is at the top of the generated
hierarchy, Extensions can override its methods, for example hashCode(),
toString(), or the implementations of the various bar() property methods.
| Modifier and Type | Class and Description |
|---|---|
| public static interface | AutoValueExtension.
Represents a |
| public static interface | AutoValueExtension.
The context of the generation cycle. |
| public static enum | AutoValueExtension.
Indicates to an annotation processor environment supporting incremental annotation processing (currently a feature specific to Gradle starting with version 4.8) the incremental type of an Extension. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | applicable(AutoValueExtension.
The Context of the code generation for this class. contextDetermines whether this Extension applies to the given context. |
| public Set | consumeMethods(AutoValueExtension.
the Context of the code generation for this class. contextReturns a possible empty set of abstract methods that this Extension intends to implement. |
| public Set | consumeProperties(AutoValueExtension.
the Context of the code generation for this class. contextReturns a possibly empty set of property names that this Extension intends to implement. |
| public abstract String | Returns: The source code of the generated class, ornull if this extension does not
generate a class in the hierarchy.The context,Context of the code generation for this class.The simple name of the resulting class. The returned code will be written to a
file named accordingly. className, String The simple name of the direct parent of the generated class. This could be
the AutoValue generated class, or a class generated as the result of another Extension. classToExtend, boolean True if this class is the last class in the chain, meaning it should be marked
as final. Otherwise it should be marked as abstract. isFinal)Returns the generated source code of the class named |
| public Set | Returns: the set of options recognized by this extension or an empty set if noneAnalogous to |
| public AutoValueExtension. | incrementalType(javax.
Determines the incremental type of this Extension. |
| public boolean | mustBeFinal(AutoValueExtension.
the Context of the code generation for this class. contextDenotes that the class generated by this Extension must be the final class in the inheritance hierarchy. |
| AutoValueExtension | back to summary |
|---|---|
| public AutoValueExtension() | |
| applicable | back to summary |
|---|---|
| public boolean applicable(AutoValueExtension. Determines whether this Extension applies to the given context. If an Extension returns
| |
| consumeMethods | back to summary |
|---|---|
| public Set Returns a possible empty set of abstract methods that this Extension intends to implement. This will prevent AutoValue from generating an implementation, in cases where it would have, and it will also avoid warnings about abstract methods that AutoValue doesn't expect. The default set returned by this method is empty. Each returned method must be one of the abstract methods in For example, Android's
| |
| consumeProperties | back to summary |
|---|---|
| public Set Returns a possibly empty set of property names that this Extension intends to implement. This
will prevent AutoValue from generating an implementation, and remove the supplied properties
from builders, constructors, Each returned string must be one of the property names in Returning a property name from this method is equivalent to returning the property's getter
method from For example, Android's
| |
| generateClass | back to summary |
|---|---|
| public abstract String generateClass(AutoValueExtension. Returns the generated source code of the class named The returned string will typically look like this:
Here,
| |
| getSupportedOptions | back to summary |
|---|---|
| public Set Analogous to By default, if the extension class is annotated with
| |
| incrementalType | back to summary |
|---|---|
| public AutoValueExtension. Determines the incremental type of this Extension. The The actual incremental type of the AutoValue processor as a whole will be the loosest
incremental types of the Extensions present in the annotation processor path. The default
returned value is | |
| mustBeFinal | back to summary |
|---|---|
| public boolean mustBeFinal(AutoValueExtension. Denotes that the class generated by this Extension must be the final class in the inheritance hierarchy. Only one Extension may be the final class, so this should be used sparingly.
| |
Builder associated with an @AutoValue class.
| Modifier and Type | Method and Description |
|---|---|
| public javax. | |
| public Set | builderMethods()
Returns static no-argument methods in the |
| public javax. | builderType()
Returns the |
| public Optional | buildMethod()
Returns the method |
| public Map | |
| public Map | |
| public Set | toBuilderMethods()
Returns abstract no-argument methods in the |
| autoBuildMethod | back to summary |
|---|---|
| public javax. Returns the abstract build method. If the Extensions should call the | |
| builderMethods | back to summary |
|---|---|
| public Set Returns static no-argument methods in the Consider a class like this:
Here | |
| builderType | back to summary |
|---|---|
| public javax. Returns the | |
| buildMethod | back to summary |
|---|---|
| public Optional Returns the method A common convention is for | |
| propertyBuilders | back to summary |
|---|---|
| public Map Returns a map from property names to property builders. For example, if there is a property
| |
| setters | back to summary |
|---|---|
| public Map Returns a map from property names to the corresponding setters. A property may have more than
one setter. For example, an | |
| toBuilderMethods | back to summary |
|---|---|
| public Set Returns abstract no-argument methods in the Consider a class like this:
Here | |
| Modifier and Type | Method and Description |
|---|---|
| public Set | abstractMethods()
Returns the complete set of abstract methods defined in or inherited by the
|
| public javax. | |
| public default Optional | builder()
Returns a representation of the |
| public default List | classAnnotationsToCopy(javax.
Returns the complete list of annotations defined on the |
| public default String | |
| public default List | methodAnnotationsToCopy(javax.
Returns the complete list of annotations defined on the |
| public String | |
| public javax. | |
| public Map | |
| public default Map |
| abstractMethods | back to summary |
|---|---|
| public Set Returns the complete set of abstract methods defined in or inherited by the
| |
| autoValueClass | back to summary |
|---|---|
| public javax. Returns the annotated class that this generation cycle is based on. Given | |
| builder | back to summary |
|---|---|
| public default Optional Returns a representation of the This method returns The default implementation of this method returns | |
| classAnnotationsToCopy | back to summary |
|---|---|
| public default List Returns the complete list of annotations defined on the The default implementation of this method returns an empty list for compatibility with extensions which may have implemented this interface themselves. | |
| finalAutoValueClassName | back to summary |
|---|---|
| public default String finalAutoValueClassName() The fully-qualified name of the last class in the For compatibility reasons, this method has a default implementation that throws an exception. The AutoValue processor supplies an implementation that behaves as documented. | |
| methodAnnotationsToCopy | back to summary |
|---|---|
| public default List Returns the complete list of annotations defined on the The default implementation of this method returns an empty list for compatibility with extensions which may have implemented this interface themselves. | |
| packageName | back to summary |
|---|---|
| public String packageName() Returns the package name of the classes to be generated. | |
| processingEnvironment | back to summary |
|---|---|
| public javax. Returns the processing environment of this generation cycle. This can be used, among other
things, to produce compilation warnings or errors, using | |
| properties | back to summary |
|---|---|
| public Map 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 property To determine the type of a property, it is best to use ...then the type of the bar property in Foo is actually String, but
the ExecutableElement will be the the method in Parent, whose return type is
T.
| |
| propertyTypes | back to summary |
|---|---|
| public default Map 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 For example, if property For compatibility reasons, this method has a default implementation that throws an exception. The AutoValue processor supplies an implementation that behaves as documented. | |
The constants for this enum are ordered by increasing performance (but also constraints).
| Modifier and Type | Field and Description |
|---|---|
| public static final AutoValueExtension. | AGGREGATING
This extension is aggregating, meaning that it may generate outputs based on several annotated input classes and it respects the constraints imposed on aggregating processors. |
| public static final AutoValueExtension. | ISOLATING
This extension is isolating, meaning roughly that its output depends on the
|
| public static final AutoValueExtension. | UNKNOWN
The incrementality of this extension is unknown, or it is neither aggregating nor isolating. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static AutoValueExtension. | |
| public static AutoValueExtension. |
| AGGREGATING | back to summary |
|---|---|
| public static final AutoValueExtension. This extension is aggregating, meaning that it may generate outputs based on several annotated input classes and it respects the constraints imposed on aggregating processors. It is unusual for AutoValue extensions to be aggregating. | |
| ISOLATING | back to summary |
|---|---|
| public static final AutoValueExtension. This extension is isolating, meaning roughly that its output depends on the
| |
| UNKNOWN | back to summary |
|---|---|
| public static final AutoValueExtension. The incrementality of this extension is unknown, or it is neither aggregating nor isolating. | |
| IncrementalExtensionType | back to summary |
|---|---|
| private IncrementalExtensionType() | |
| valueOf | back to summary |
|---|---|
| public static AutoValueExtension. | |
| values | back to summary |
|---|---|
| public static AutoValueExtension. | |