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

public final Class MemoizeExtension

extends AutoValueExtension
Class Inheritance
Annotations
@AutoService:AutoValueExtension
Static Imports
com.google.auto.common.GeneratedAnnotationSpecs.generatedAnnotationSpec, .MoreStreams.toImmutableList, .MoreStreams.toImmutableMap, .MoreStreams.toImmutableSet, com.google.auto.value.extension.memoized.processor.ClassNames.MEMOIZED_NAME, .MemoizedValidator.getAnnotationMirror, com.google.common.base.Predicates.equalTo, .Predicates.not, com.google.common.collect.Iterables.filter, .Iterables.getOnlyElement, com.squareup.javapoet.MethodSpec.constructorBuilder, .MethodSpec.methodBuilder, .TypeSpec.classBuilder, java.util.stream.Collectors.joining, .Collectors.toList, javax.lang.model.element.Modifier.ABSTRACT, javax.lang.model.element.Modifier.FINAL, javax.lang.model.element.Modifier.PRIVATE, javax.lang.model.element.Modifier.PUBLIC, javax.lang.model.element.Modifier.STATIC, javax.lang.model.element.Modifier.TRANSIENT, javax.lang.model.element.Modifier.VOLATILE, javax.lang.model.type.TypeKind.VOID, javax.lang.model.util.ElementFilter.methodsIn, javax.tools.Diagnostic.Kind.ERROR

An extension that implements the com.google.auto.value.extension.memoized.Memoized contract.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static final ImmutableSet<String>
private static final ClassName
private static final AnnotationSpec

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static TypeName
annotatedType(javax.lang.model.type.TypeMirror type)

Translate a TypeMirror into a TypeName, including type annotations.

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.

private static boolean
containsNullable(List<? extends javax.lang.model.element.AnnotationMirror> annotations)

True if one of the given annotations is @Nullable in any package.

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 Optional<AnnotationSpec>
getLazyInitAnnotation(javax.lang.model.util.Elements elements)

Returns the errorprone @LazyInit annotation if it is found on the classpath.

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

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

Determines the incremental type of this Extension.

private static ImmutableSet<javax.lang.model.element.ExecutableElement>
Inherited from com.google.auto.value.extension.AutoValueExtension:
consumeMethodsconsumePropertiesgetSupportedOptionsmustBeFinal

Field Detail

DO_NOT_PULL_DOWN_ANNOTATIONSback to summary
private static final ImmutableSet<String> DO_NOT_PULL_DOWN_ANNOTATIONS
LAZY_INITback to summary
private static final ClassName LAZY_INIT
SUPPRESS_WARNINGSback to summary
private static final AnnotationSpec SUPPRESS_WARNINGS

Constructor Detail

MemoizeExtensionback to summary
public MemoizeExtension()

Method Detail

annotatedTypeback to summary
private static TypeName annotatedType(javax.lang.model.type.TypeMirror type)

Translate a TypeMirror into a TypeName, including type annotations.

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
containsNullableback to summary
private static boolean containsNullable(List<? extends javax.lang.model.element.AnnotationMirror> annotations)

True if one of the given annotations is @Nullable in any package.

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
getLazyInitAnnotationback to summary
private static Optional<AnnotationSpec> getLazyInitAnnotation(javax.lang.model.util.Elements elements)

Returns the errorprone @LazyInit annotation if it is found on the classpath.

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
memoizedMethodsback to summary
private static ImmutableSet<javax.lang.model.element.ExecutableElement> memoizedMethods(AutoValueExtension.Context context)
com.google.auto.value.extension.memoized.processor back to summary

pack-priv final Class MemoizeExtension.Generator

extends Object
Class Inheritance
  • java.lang.Object
  • com.google.auto.value.extension.memoized.processor.MemoizeExtension.Generator

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
MemoizeExtension.Generator.MethodOverrider

Determines the required fields and overriding method for a @Memoized method.

Field Summary

Modifier and TypeField and Description
private final String
private final String
private final AutoValueExtension.Context
private final javax.lang.model.util.Elements
private boolean
private final boolean
private final Optional<AnnotationSpec>
private final javax.annotation.processing.Messager
private final javax.lang.model.SourceVersion
private final javax.lang.model.util.Types

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 ImmutableList<TypeVariableName>
private MethodSpec
private MethodSpec
pack-priv String
private static String
generateIdentifier(String name, Set<String> existingNames)

private boolean
private boolean
private TypeName
private ImmutableList<TypeVariableName>
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
elementsback to summary
private final javax.lang.model.util.Elements elements
hasErrorsback to summary
private boolean hasErrors
isFinalback to summary
private final boolean isFinal
lazyInitAnnotationback to summary
private final Optional<AnnotationSpec> lazyInitAnnotation
messagerback to summary
private final javax.annotation.processing.Messager messager
sourceVersionback to summary
private final javax.lang.model.SourceVersion sourceVersion
typesback to summary
private final javax.lang.model.util.Types types

Constructor Detail

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

Method Detail

annotatedTypeVariableNamesback to summary
private ImmutableList<TypeVariableName> annotatedTypeVariableNames()
constructorback to summary
private MethodSpec constructor()
equalsWithHashCodeCheckback to summary
private MethodSpec equalsWithHashCodeCheck()
generateback to summary
pack-priv String generate()
generateIdentifierback to summary
private static String generateIdentifier(String name, Set<String> existingNames)
isEqualsFinalback to summary
private boolean isEqualsFinal()
isHashCodeMemoizedback to summary
private boolean isHashCodeMemoized()
superTypeback to summary
private TypeName superType()
typeVariableNamesback to summary
private ImmutableList<TypeVariableName> typeVariableNames()
com.google.auto.value.extension.memoized.processor back to summary

private final Class MemoizeExtension.Generator.MethodOverrider

extends Object
Class Inheritance
  • java.lang.Object
  • com.google.auto.value.extension.memoized.processor.MemoizeExtension.Generator.MethodOverrider

Determines the required fields and overriding method for a @Memoized method.

Field Summary

Modifier and TypeField and Description
private final FieldSpec
private final ImmutableList.Builder<FieldSpec>
private final javax.lang.model.element.ExecutableElement
private final MethodSpec.Builder

Constructor Summary

AccessConstructor and Description
pack-priv
MethodOverrider(javax.lang.model.element.ExecutableElement method)

Method Summary

Modifier and TypeMethod and Description
private FieldSpec
buildCacheField(TypeName type, String name)

Builds a FieldSpec for use in property caching.

private void
checkIllegalModifier(javax.lang.model.element.Modifier modifier)

pack-priv Iterable<FieldSpec>
fields()

The fields that should be added to the subclass.

pack-priv MethodSpec
method()

The overriding method that should be added to the subclass.

private javax.lang.model.element.ExecutableElement
objectMethod(String methodName)

private boolean
private void
printMessage(javax.tools.Diagnostic.Kind kind, String format, Object... args)

private boolean
pullDownMethodAnnotation(javax.lang.model.element.AnnotationMirror annotation)

pack-priv MemoizeExtension.Generator.MethodOverrider.InitializationStrategy
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheFieldback to summary
private final FieldSpec cacheField
fieldsback to summary
private final ImmutableList.Builder<FieldSpec> fields
methodback to summary
private final javax.lang.model.element.ExecutableElement method
overrideback to summary
private final MethodSpec.Builder override

Constructor Detail

MethodOverriderback to summary
pack-priv MethodOverrider(javax.lang.model.element.ExecutableElement method)

Method Detail

buildCacheFieldback to summary
private FieldSpec buildCacheField(TypeName type, String name)

Builds a FieldSpec for use in property caching. Field will be private transient volatile and have the given type and name. If the @LazyInit annotation is available it is added as well.

checkIllegalModifierback to summary
private void checkIllegalModifier(javax.lang.model.element.Modifier modifier)
fieldsback to summary
pack-priv Iterable<FieldSpec> fields()

The fields that should be added to the subclass.

methodback to summary
pack-priv MethodSpec method()

The overriding method that should be added to the subclass.

objectMethodback to summary
private javax.lang.model.element.ExecutableElement objectMethod(String methodName)
overridesObjectMethodback to summary
private boolean overridesObjectMethod(String methodName)
printMessageback to summary
private void printMessage(javax.tools.Diagnostic.Kind kind, String format, Object... args)
Annotations
@FormatMethod
pullDownMethodAnnotationback to summary
private boolean pullDownMethodAnnotation(javax.lang.model.element.AnnotationMirror annotation)
strategyback to summary
pack-priv MemoizeExtension.Generator.MethodOverrider.InitializationStrategy strategy()
validateback to summary
private void validate()
com.google.auto.value.extension.memoized.processor back to summary

private final Class MemoizeExtension.Generator.MethodOverrider.CheckBooleanField

extends InitializationStrategy
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final FieldSpec

Constructor Summary

AccessConstructor and Description
private

Field Detail

fieldback to summary
private final FieldSpec field

Constructor Detail

CheckBooleanFieldback to summary
private CheckBooleanField()
com.google.auto.value.extension.memoized.processor back to summary

private abstract Class MemoizeExtension.Generator.MethodOverrider.InitializationStrategy

extends Object
Class Inheritance
  • java.lang.Object
  • com.google.auto.value.extension.memoized.processor.MemoizeExtension.Generator.MethodOverrider.InitializationStrategy
Known Direct Subclasses
com.google.auto.value.extension.memoized.processor.MemoizeExtension.Generator.MethodOverrider.NullMeansUninitialized, com.google.auto.value.extension.memoized.processor.MemoizeExtension.Generator.MethodOverrider.CheckBooleanField

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract Iterable<FieldSpec>
pack-priv abstract CodeBlock
pack-priv abstract CodeBlock
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

InitializationStrategyback to summary
private InitializationStrategy()

Method Detail

additionalFieldsback to summary
pack-priv abstract Iterable<FieldSpec> additionalFields()
checkMemoizedback to summary
pack-priv abstract CodeBlock checkMemoized()
setMemoizedback to summary
pack-priv abstract CodeBlock setMemoized()
com.google.auto.value.extension.memoized.processor back to summary

private final Class MemoizeExtension.Generator.MethodOverrider.NullMeansUninitialized

extends InitializationStrategy
Class Inheritance

Constructor Summary

AccessConstructor and Description
private

Constructor Detail

NullMeansUninitializedback to summary
private NullMeansUninitialized()