Package com.google.auto.value.processor
Class AutoValueProcessor
- java.lang.Object
-
- javax.annotation.processing.AbstractProcessor
-
- com.google.auto.value.processor.AutoValueOrOneOfProcessor
-
- com.google.auto.value.processor.AutoValueProcessor
-
- All Implemented Interfaces:
javax.annotation.processing.Processor
@AutoService(javax.annotation.processing.Processor.class) @SupportedAnnotationTypes("com.google.auto.value.AutoValue") @SupportedOptions("com.google.auto.value.OmitIdentifiers") public class AutoValueProcessor extends AutoValueOrOneOfProcessor
Javac annotation processor (compiler plugin) for value types; user code never references this class.- See Also:
- AutoValue User's Guide
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.auto.value.processor.AutoValueOrOneOfProcessor
AutoValueOrOneOfProcessor.ObjectMethod, AutoValueOrOneOfProcessor.Property
-
-
Field Summary
Fields Modifier and Type Field Description private com.google.common.collect.ImmutableList<AutoValueExtension>
extensions
private java.lang.ClassLoader
loaderForExtensions
-
Constructor Summary
Constructors Constructor Description AutoValueProcessor()
AutoValueProcessor(java.lang.ClassLoader loaderForExtensions)
AutoValueProcessor(java.lang.Iterable<? extends AutoValueExtension> extensions)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
ancestorIsAutoValue(javax.lang.model.element.TypeElement type)
private com.google.common.collect.ImmutableList<AutoValueExtension>
applicableExtensions(javax.lang.model.element.TypeElement type, ExtensionContext context)
private void
defineVarsForType(javax.lang.model.element.TypeElement type, AutoValueTemplateVars vars, com.google.common.collect.ImmutableSet<javax.lang.model.element.ExecutableElement> toBuilderMethods, com.google.common.collect.ImmutableSet<javax.lang.model.element.ExecutableElement> propertyMethods, java.util.Optional<BuilderSpec.Builder> builder)
private java.lang.String
extensionName(AutoValueExtension extension)
private static java.lang.String
generatedSubclassName(javax.lang.model.element.TypeElement type, int depth)
private javax.lang.model.type.TypeMirror
getTypeMirror(java.lang.Class<?> c)
private static <E> com.google.common.collect.ImmutableSet<E>
immutableSetDifference(com.google.common.collect.ImmutableSet<E> a, com.google.common.collect.ImmutableSet<E> b)
private boolean
implementsAnnotation(javax.lang.model.element.TypeElement type)
void
init(javax.annotation.processing.ProcessingEnvironment processingEnv)
private static boolean
isNullable(javax.lang.model.element.AnnotationMirror annotation)
private com.google.common.collect.ImmutableSet<javax.lang.model.element.ExecutableElement>
methodsConsumedByExtensions(javax.lang.model.element.TypeElement type, com.google.common.collect.ImmutableList<AutoValueExtension> applicableExtensions, ExtensionContext context, com.google.common.collect.ImmutableSet<javax.lang.model.element.ExecutableElement> abstractMethods, com.google.common.collect.ImmutableBiMap<java.lang.String,javax.lang.model.element.ExecutableElement> properties)
(package private) static java.util.Optional<java.lang.String>
nullableAnnotationFor(javax.lang.model.element.Element element, javax.lang.model.type.TypeMirror elementType)
Returns an appropriate annotation spelling to indicate the nullability of an element.(package private) java.util.Optional<java.lang.String>
nullableAnnotationForMethod(javax.lang.model.element.ExecutableElement propertyMethod)
Returns the appropriate@Nullable
annotation to put on the implementation of the given property method, and indicates whether the property is in fact nullable.private static java.util.OptionalInt
nullableAnnotationIndex(java.util.List<? extends javax.lang.model.element.AnnotationMirror> annotations)
(package private) static com.google.common.collect.ImmutableSet<javax.lang.model.element.ExecutableElement>
prefixedGettersIn(java.lang.Iterable<javax.lang.model.element.ExecutableElement> methods)
(package private) void
processType(javax.lang.model.element.TypeElement type)
Analyzes a single@AutoValue
or@AutoOneOf
class, and outputs the corresponding implementation class or classes.private void
validateMethods(javax.lang.model.element.TypeElement type, com.google.common.collect.ImmutableSet<javax.lang.model.element.ExecutableElement> abstractMethods, com.google.common.collect.ImmutableSet<javax.lang.model.element.ExecutableElement> toBuilderMethods, com.google.common.collect.ImmutableSet<javax.lang.model.element.ExecutableElement> propertyMethods, boolean extensionsPresent)
private int
writeExtensions(javax.lang.model.element.TypeElement type, ExtensionContext context, com.google.common.collect.ImmutableList<AutoValueExtension> applicableExtensions)
-
Methods inherited from class com.google.auto.value.processor.AutoValueOrOneOfProcessor
abstractMethodsIn, annotationsToCopy, annotationStrings, checkModifiersIfNested, checkReturnType, defineSharedVarsForType, elementUtils, equalsParameterType, errorReporter, fixReservedIdentifiers, generatedClassName, getAnnotationMirror, getSerialVersionUID, getSupportedSourceVersion, hasAnnotationMirror, objectMethodToOverride, process, propertyMethodAnnotationMap, propertyMethodsIn, propertyNameToMethodMap, propertySet, typeUtils, writeSourceFile
-
-
-
-
Field Detail
-
extensions
private com.google.common.collect.ImmutableList<AutoValueExtension> extensions
-
loaderForExtensions
private final java.lang.ClassLoader loaderForExtensions
-
-
Constructor Detail
-
AutoValueProcessor
public AutoValueProcessor()
-
AutoValueProcessor
AutoValueProcessor(java.lang.ClassLoader loaderForExtensions)
-
AutoValueProcessor
public AutoValueProcessor(java.lang.Iterable<? extends AutoValueExtension> extensions)
-
-
Method Detail
-
init
public void init(javax.annotation.processing.ProcessingEnvironment processingEnv)
- Specified by:
init
in interfacejavax.annotation.processing.Processor
- Overrides:
init
in classAutoValueOrOneOfProcessor
-
generatedSubclassName
private static java.lang.String generatedSubclassName(javax.lang.model.element.TypeElement type, int depth)
-
processType
void processType(javax.lang.model.element.TypeElement type)
Description copied from class:AutoValueOrOneOfProcessor
Analyzes a single@AutoValue
or@AutoOneOf
class, and outputs the corresponding implementation class or classes.- Specified by:
processType
in classAutoValueOrOneOfProcessor
- Parameters:
type
- the class with the@AutoValue
or@AutoOneOf
annotation.
-
writeExtensions
private int writeExtensions(javax.lang.model.element.TypeElement type, ExtensionContext context, com.google.common.collect.ImmutableList<AutoValueExtension> applicableExtensions)
-
applicableExtensions
private com.google.common.collect.ImmutableList<AutoValueExtension> applicableExtensions(javax.lang.model.element.TypeElement type, ExtensionContext context)
-
methodsConsumedByExtensions
private com.google.common.collect.ImmutableSet<javax.lang.model.element.ExecutableElement> methodsConsumedByExtensions(javax.lang.model.element.TypeElement type, com.google.common.collect.ImmutableList<AutoValueExtension> applicableExtensions, ExtensionContext context, com.google.common.collect.ImmutableSet<javax.lang.model.element.ExecutableElement> abstractMethods, com.google.common.collect.ImmutableBiMap<java.lang.String,javax.lang.model.element.ExecutableElement> properties)
-
validateMethods
private void validateMethods(javax.lang.model.element.TypeElement type, com.google.common.collect.ImmutableSet<javax.lang.model.element.ExecutableElement> abstractMethods, com.google.common.collect.ImmutableSet<javax.lang.model.element.ExecutableElement> toBuilderMethods, com.google.common.collect.ImmutableSet<javax.lang.model.element.ExecutableElement> propertyMethods, boolean extensionsPresent)
-
extensionName
private java.lang.String extensionName(AutoValueExtension extension)
-
defineVarsForType
private void defineVarsForType(javax.lang.model.element.TypeElement type, AutoValueTemplateVars vars, com.google.common.collect.ImmutableSet<javax.lang.model.element.ExecutableElement> toBuilderMethods, com.google.common.collect.ImmutableSet<javax.lang.model.element.ExecutableElement> propertyMethods, java.util.Optional<BuilderSpec.Builder> builder)
-
nullableAnnotationForMethod
java.util.Optional<java.lang.String> nullableAnnotationForMethod(javax.lang.model.element.ExecutableElement propertyMethod)
Description copied from class:AutoValueOrOneOfProcessor
Returns the appropriate@Nullable
annotation to put on the implementation of the given property method, and indicates whether the property is in fact nullable. The annotation in question is on the method, not its return type. If instead the return type is@Nullable
, this method returnsOptional.of("")
, to indicate that the property is nullable but the method isn't. The@Nullable
annotation will instead appear when the return type of the method is spelled out in the implementation.- Specified by:
nullableAnnotationForMethod
in classAutoValueOrOneOfProcessor
-
nullableAnnotationFor
static java.util.Optional<java.lang.String> nullableAnnotationFor(javax.lang.model.element.Element element, javax.lang.model.type.TypeMirror elementType)
Returns an appropriate annotation spelling to indicate the nullability of an element. If the return value is a non-empty Optional, that indicates that the element is nullable, and the string should be used to annotate it. If the return value is an empty Optional, the element is not nullable. The return value can beOptional.of("")
, which indicates that the element is nullable but that the nullability comes from a type annotation. In this case, the annotation will appear when the type is written, and must not be specified again. If the Optional contains a present non-empty string then that string will end with a space.- Parameters:
element
- the element that might be@Nullable
, either a method or a parameter.elementType
- the relevant type of the element: the return type for a method, or the parameter type for a parameter.
-
nullableAnnotationIndex
private static java.util.OptionalInt nullableAnnotationIndex(java.util.List<? extends javax.lang.model.element.AnnotationMirror> annotations)
-
isNullable
private static boolean isNullable(javax.lang.model.element.AnnotationMirror annotation)
-
prefixedGettersIn
static com.google.common.collect.ImmutableSet<javax.lang.model.element.ExecutableElement> prefixedGettersIn(java.lang.Iterable<javax.lang.model.element.ExecutableElement> methods)
-
ancestorIsAutoValue
private boolean ancestorIsAutoValue(javax.lang.model.element.TypeElement type)
-
implementsAnnotation
private boolean implementsAnnotation(javax.lang.model.element.TypeElement type)
-
getTypeMirror
private javax.lang.model.type.TypeMirror getTypeMirror(java.lang.Class<?> c)
-
immutableSetDifference
private static <E> com.google.common.collect.ImmutableSet<E> immutableSetDifference(com.google.common.collect.ImmutableSet<E> a, com.google.common.collect.ImmutableSet<E> b)
-
-