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, 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 static java.util.regex.PatternAUTO_VALUE_CLASSNAME_PATTERNUsed to test whether a fully-qualified name is AutoValue.class.getCanonicalName() or one of its nested annotations.private com.google.common.collect.ImmutableList<AutoValueExtension>extensionsprivate java.lang.ClassLoaderloaderForExtensions
-
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 com.google.common.collect.ImmutableSetMultimap<javax.lang.model.element.ExecutableElement,java.lang.String>allMethodExcludedAnnotations(java.lang.Iterable<javax.lang.model.element.ExecutableElement> methods)private booleanancestorIsAutoValue(javax.lang.model.element.TypeElement type)private com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror>annotationsToCopy(javax.lang.model.element.Element autoValueType, javax.lang.model.element.Element typeOrMethod, java.util.Set<java.lang.String> excludedAnnotations)Implements the semantics ofAutoValue.CopyAnnotations; see its javadoc.private booleanannotationVisibleFrom(javax.lang.model.element.AnnotationMirror annotation, javax.lang.model.element.Element from)private com.google.common.collect.ImmutableList<AutoValueExtension>applicableExtensions(javax.lang.model.element.TypeElement type, ExtensionContext context)private com.google.common.collect.ImmutableList<java.lang.String>copyAnnotations(javax.lang.model.element.Element autoValueType, javax.lang.model.element.Element typeOrMethod, java.util.Set<java.lang.String> excludedAnnotations)Implements the semantics ofAutoValue.CopyAnnotations; see its javadoc.private voiddefineVarsForType(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.StringextensionName(AutoValueExtension extension)private static java.lang.StringgeneratedSubclassName(javax.lang.model.element.TypeElement type, int depth)private static java.lang.StringgetAnnotationFqName(javax.lang.model.element.AnnotationMirror annotation)Returns the fully-qualified name of an annotation-mirror, e.g.private static java.util.Set<java.lang.String>getAnnotationsMarkedWithInherited(javax.lang.model.element.Element element)private java.util.Set<java.lang.String>getExcludedClasses(javax.lang.model.element.Element element)Returns the contents of theAutoValue.CopyAnnotations.excludeelement, as a list of strings that are fully-qualified class names.private javax.lang.model.type.TypeMirrorgetTypeMirror(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 booleanimplementsAnnotation(javax.lang.model.element.TypeElement type)voidinit(javax.annotation.processing.ProcessingEnvironment processingEnv)private static booleanisNullable(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) java.util.Optional<java.lang.String>nullableAnnotationForMethod(javax.lang.model.element.ExecutableElement propertyMethod, com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror> methodAnnotations)Returns the appropriate@Nullableannotation to put on the implementation of the given property method, and indicates whether the property is in fact nullable.private static java.util.OptionalIntnullableAnnotationIndex(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) voidprocessType(javax.lang.model.element.TypeElement type)Analyzes a single@AutoValueor@AutoOneOfclass, and outputs the corresponding implementation class or classes.private com.google.common.collect.ImmutableMap<javax.lang.model.element.ExecutableElement,com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror>>propertyMethodAnnotationMap(javax.lang.model.element.TypeElement type, com.google.common.collect.ImmutableSet<javax.lang.model.element.ExecutableElement> propertyMethods)private com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror>propertyMethodAnnotations(javax.lang.model.element.TypeElement type, javax.lang.model.element.ExecutableElement method, com.google.common.collect.ImmutableSetMultimap<javax.lang.model.element.ExecutableElement,java.lang.String> excludedAnnotationsMap)private voidvalidateMethods(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 intwriteExtensions(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, annotationStrings, checkModifiersIfNested, checkReturnType, determineObjectMethodsToGenerate, elementUtils, equalsParameterType, errorReporter, fixReservedIdentifiers, generatedClassName, getAnnotationMirror, getSerialVersionUID, getSupportedSourceVersion, hasAnnotationMirror, objectMethodToOverride, process, propertyMethodsIn, propertyNameToMethodMap, propertySet, typeUtils, wildcardTypeParametersString, writeSourceFile
-
-
-
-
Field Detail
-
AUTO_VALUE_CLASSNAME_PATTERN
private static final java.util.regex.Pattern AUTO_VALUE_CLASSNAME_PATTERN
Used to test whether a fully-qualified name is AutoValue.class.getCanonicalName() or one of its nested annotations.
-
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:
initin interfacejavax.annotation.processing.Processor- Overrides:
initin 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:AutoValueOrOneOfProcessorAnalyzes a single@AutoValueor@AutoOneOfclass, and outputs the corresponding implementation class or classes.- Specified by:
processTypein classAutoValueOrOneOfProcessor- Parameters:
type- the class with the@AutoValueor@AutoOneOfannotation.
-
copyAnnotations
private com.google.common.collect.ImmutableList<java.lang.String> copyAnnotations(javax.lang.model.element.Element autoValueType, javax.lang.model.element.Element typeOrMethod, java.util.Set<java.lang.String> excludedAnnotations)Implements the semantics ofAutoValue.CopyAnnotations; see its javadoc.
-
annotationsToCopy
private com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror> annotationsToCopy(javax.lang.model.element.Element autoValueType, javax.lang.model.element.Element typeOrMethod, java.util.Set<java.lang.String> excludedAnnotations)Implements the semantics ofAutoValue.CopyAnnotations; see its javadoc.
-
annotationVisibleFrom
private boolean annotationVisibleFrom(javax.lang.model.element.AnnotationMirror annotation, javax.lang.model.element.Element from)
-
getAnnotationFqName
private static java.lang.String getAnnotationFqName(javax.lang.model.element.AnnotationMirror annotation)
Returns the fully-qualified name of an annotation-mirror, e.g. "com.google.auto.value.AutoValue".
-
getExcludedClasses
private java.util.Set<java.lang.String> getExcludedClasses(javax.lang.model.element.Element element)
Returns the contents of theAutoValue.CopyAnnotations.excludeelement, as a list of strings that are fully-qualified class names.
-
getAnnotationsMarkedWithInherited
private static java.util.Set<java.lang.String> getAnnotationsMarkedWithInherited(javax.lang.model.element.Element element)
-
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)
-
propertyMethodAnnotationMap
private com.google.common.collect.ImmutableMap<javax.lang.model.element.ExecutableElement,com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror>> propertyMethodAnnotationMap(javax.lang.model.element.TypeElement type, com.google.common.collect.ImmutableSet<javax.lang.model.element.ExecutableElement> propertyMethods)
-
nullableAnnotationForMethod
java.util.Optional<java.lang.String> nullableAnnotationForMethod(javax.lang.model.element.ExecutableElement propertyMethod, com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror> methodAnnotations)Description copied from class:AutoValueOrOneOfProcessorReturns the appropriate@Nullableannotation 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@Nullableannotation will instead appear when the return type of the method is spelled out in the implementation.- Specified by:
nullableAnnotationForMethodin classAutoValueOrOneOfProcessormethodAnnotations- the annotations to include onpropertyMethod. This is governed by theAutoValue.CopyAnnotationslogic.
-
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)
-
propertyMethodAnnotations
private com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror> propertyMethodAnnotations(javax.lang.model.element.TypeElement type, javax.lang.model.element.ExecutableElement method, com.google.common.collect.ImmutableSetMultimap<javax.lang.model.element.ExecutableElement,java.lang.String> excludedAnnotationsMap)
-
allMethodExcludedAnnotations
private com.google.common.collect.ImmutableSetMultimap<javax.lang.model.element.ExecutableElement,java.lang.String> allMethodExcludedAnnotations(java.lang.Iterable<javax.lang.model.element.ExecutableElement> methods)
-
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)
-
-