Top Description Inners Constructors Methods
com.google.auto.value.extension.serializable.processor

public final Class SerializableAutoValueExtension

extends AutoValueExtension
Class Inheritance
Annotations
@AutoService:AutoValueExtension
Static Imports
com.google.auto.common.MoreStreams.toImmutableList, .MoreStreams.toImmutableMap, com.google.auto.value.extension.serializable.processor.ClassNames.SERIALIZABLE_AUTO_VALUE_NAME, java.util.stream.Collectors.joining

An AutoValue extension that enables classes with unserializable fields to be serializable.

For this extension to work:

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
SerializableAutoValueExtension.ProxyGenerator

A generator of nested serializable Proxy classes.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
applicable(AutoValueExtension.Context
The Context of the code generation for this class.
context
)

Overrides com.google.auto.value.extension.AutoValueExtension.applicable.

Determines whether this Extension applies to the given context.

public String
generateClass(AutoValueExtension.Context
The Context of the code generation for this class.
context
,
String
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
)

Implements abstract com.google.auto.value.extension.AutoValueExtension.generateClass.

Returns the generated source code of the class named className to extend classToExtend, or null if this extension does not generate a class in the hierarchy.

private static boolean
private static boolean
public AutoValueExtension.IncrementalExtensionType
incrementalType(javax.annotation.processing.ProcessingEnvironment processingEnvironment)

Overrides com.google.auto.value.extension.AutoValueExtension.incrementalType.

Determines the incremental type of this Extension.

Inherited from com.google.auto.value.extension.AutoValueExtension:
consumeMethodsconsumePropertiesgetSupportedOptionsmustBeFinal

Constructor Detail

SerializableAutoValueExtensionback to summary
public SerializableAutoValueExtension()

Method Detail

applicableback to summary
public boolean applicable(AutoValueExtension.Context context)

Overrides com.google.auto.value.extension.AutoValueExtension.applicable.

Doc from com.google.auto.value.extension.AutoValueExtension.applicable.

Determines whether this Extension applies to the given context. If an Extension returns false for a given class, it will not be called again during the processing of that class. An Extension can return true and still choose not to generate any code for the class, by returning null from generateClass. That is often a more flexible approach.

Parameters
context:AutoValueExtension.Context

The Context of the code generation for this class.

Annotations
@Override
generateClassback to summary
public String generateClass(AutoValueExtension.Context context, String className, String classToExtend, boolean isFinal)

Implements abstract com.google.auto.value.extension.AutoValueExtension.generateClass.

Doc from com.google.auto.value.extension.AutoValueExtension.generateClass.

Returns the generated source code of the class named className to extend classToExtend, or null if this extension does not generate a class in the hierarchy. If there is a generated class, it should be final if isFinal is true; otherwise it should be abstract. The returned string should be a complete Java class definition of the class className in the package context.packageName().

The returned string will typically look like this:

package <package>;
...
<finalOrAbstract> class <className> extends <classToExtend> {
  // Constructor
  <className>(<constructorParameters>) {
    super(<constructorParameterNames>);
    ...
  }
  ...
}

Here, <package> is Context#packageName(); <finalOrAbstract> is the keyword final if isFinal is true or abstract otherwise; and <className> and <classToExtend> are the values of this method's parameters of the same name. The <constructorParameters> and <constructorParameterNames> are typically derived from Context#propertyTypes().

Parameters
context:AutoValueExtension.Context

The Context of the code generation for this class.

className:String

The simple name of the resulting class. The returned code will be written to a file named accordingly.

classToExtend: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.

isFinal: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.

Returns:String

The source code of the generated class, or null if this extension does not generate a class in the hierarchy.

Annotations
@Override
hasSerializableAutoValueAnnotationback to summary
private static boolean hasSerializableAutoValueAnnotation(AutoValueExtension.Context context)
hasSerializableInterfaceback to summary
private static boolean hasSerializableInterface(AutoValueExtension.Context context)
incrementalTypeback to summary
public AutoValueExtension.IncrementalExtensionType incrementalType(javax.annotation.processing.ProcessingEnvironment processingEnvironment)

Overrides com.google.auto.value.extension.AutoValueExtension.incrementalType.

Doc from com.google.auto.value.extension.AutoValueExtension.incrementalType.

Determines the incremental type of this Extension.

The ProcessingEnvironment can be used, among other things, to obtain the processor options, using ProcessingEnvironment#getOptions().

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 IncrementalExtensionType#UNKNOWN, which will disable incremental annotation processing entirely.

Annotations
@Override
com.google.auto.value.extension.serializable.processor back to summary

private final Class SerializableAutoValueExtension.Generator

extends Object
Class Inheritance
  • java.lang.Object
  • com.google.auto.value.extension.serializable.processor.SerializableAutoValueExtension.Generator

Field Summary

Modifier and TypeField and Description
private final String
private final String
private final AutoValueExtension.Context
private final boolean
private final ImmutableList<PropertyMirror>
private final SerializableAutoValueExtension.ProxyGenerator
private final ImmutableList<TypeVariableName>

Constructor Summary

AccessConstructor and Description
pack-priv
Generator(AutoValueExtension.Context context, String className, String classToExtend, boolean isFinal)

Method Summary

Modifier and TypeMethod and Description
private ImmutableMap<Equivalence.Wrapper<javax.lang.model.type.TypeMirror>, Serializer>
private MethodSpec
constructor()

Creates a constructor that calls super with all the AutoValue fields.

private String
private static TypeName
getClassTypeName(ClassName className, List<TypeVariableName> typeVariableNames)

Adds type parameters to the given ClassName, if available.

private MethodSpec
writeReplace()

Creates an implementation of writeReplace that delegates serialization to its inner Proxy class.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classNameback to summary
private final String className
classToExtendback to summary
private final String classToExtend
contextback to summary
private final AutoValueExtension.Context context
isFinalback to summary
private final boolean isFinal
propertyMirrorsback to summary
private final ImmutableList<PropertyMirror> propertyMirrors
proxyGeneratorback to summary
private final SerializableAutoValueExtension.ProxyGenerator proxyGenerator
typeVariableNamesback to summary
private final ImmutableList<TypeVariableName> typeVariableNames

Constructor Detail

Generatorback to summary
pack-priv Generator(AutoValueExtension.Context context, String className, String classToExtend, boolean isFinal)

Method Detail

buildSerializersMapback to summary
private ImmutableMap<Equivalence.Wrapper<javax.lang.model.type.TypeMirror>, Serializer> buildSerializersMap()
constructorback to summary
private MethodSpec constructor()

Creates a constructor that calls super with all the AutoValue fields.

generateback to summary
private String generate()
getClassTypeNameback to summary
private static TypeName getClassTypeName(ClassName className, List<TypeVariableName> typeVariableNames)

Adds type parameters to the given ClassName, if available.

writeReplaceback to summary
private MethodSpec writeReplace()

Creates an implementation of writeReplace that delegates serialization to its inner Proxy class.

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

private final Class SerializableAutoValueExtension.ProxyGenerator

extends Object
Class Inheritance
  • java.lang.Object
  • com.google.auto.value.extension.serializable.processor.SerializableAutoValueExtension.ProxyGenerator

A generator of nested serializable Proxy classes.

Field Summary

Modifier and TypeField and Description
private final TypeName
private final ImmutableList<PropertyMirror>
private static final String
private final ImmutableMap<Equivalence.Wrapper<javax.lang.model.type.TypeMirror>, Serializer>
private final ImmutableList<TypeVariableName>

Constructor Summary

AccessConstructor and Description
pack-priv
ProxyGenerator(TypeName outerClassTypeName, ImmutableList<TypeVariableName> typeVariableNames, ImmutableList<PropertyMirror> propertyMirrors, ImmutableMap<Equivalence.Wrapper<javax.lang.model.type.TypeMirror>, Serializer> serializersMap)

Method Summary

Modifier and TypeMethod and Description
private MethodSpec
constructor()

Creates a constructor that converts the AutoValue's properties to serializable values.

private TypeSpec
private List<FieldSpec>
properties()

Maps each AutoValue property to a serializable type.

private MethodSpec
readResolve()

Creates an implementation of readResolve that returns the serializable values in the Proxy object back to their original types.

private CodeBlock
resolve(PropertyMirror propertyMirror)

Maps a serializable type back to its original AutoValue property.

private static FieldSpec
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

outerClassTypeNameback to summary
private final TypeName outerClassTypeName
propertyMirrorsback to summary
private final ImmutableList<PropertyMirror> propertyMirrors
PROXY_CLASS_NAMEback to summary
private static final String PROXY_CLASS_NAME
serializersMapback to summary
private final ImmutableMap<Equivalence.Wrapper<javax.lang.model.type.TypeMirror>, Serializer> serializersMap
typeVariableNamesback to summary
private final ImmutableList<TypeVariableName> typeVariableNames

Constructor Detail

ProxyGeneratorback to summary
pack-priv ProxyGenerator(TypeName outerClassTypeName, ImmutableList<TypeVariableName> typeVariableNames, ImmutableList<PropertyMirror> propertyMirrors, ImmutableMap<Equivalence.Wrapper<javax.lang.model.type.TypeMirror>, Serializer> serializersMap)

Method Detail

constructorback to summary
private MethodSpec constructor()

Creates a constructor that converts the AutoValue's properties to serializable values.

generateback to summary
private TypeSpec generate()
propertiesback to summary
private List<FieldSpec> properties()

Maps each AutoValue property to a serializable type.

readResolveback to summary
private MethodSpec readResolve()

Creates an implementation of readResolve that returns the serializable values in the Proxy object back to their original types.

resolveback to summary
private CodeBlock resolve(PropertyMirror propertyMirror)

Maps a serializable type back to its original AutoValue property.

serialVersionUidback to summary
private static FieldSpec serialVersionUid()