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

pack-priv abstract Class AutoValueishProcessor

extends javax.annotation.processing.AbstractProcessor
Class Inheritance
Known Direct Subclasses
com.google.auto.value.processor.AutoValueProcessor, com.google.auto.value.processor.AutoBuilderProcessor, com.google.auto.value.processor.AutoOneOfProcessor
Static Imports
com.google.auto.common.AnnotationMirrors.getAnnotationValue, .GeneratedAnnotations.generatedAnnotation, .MoreElements.asType, .MoreElements.getPackage, .MoreElements.isAnnotationPresent, .MoreStreams.toImmutableList, .MoreStreams.toImmutableMap, .MoreStreams.toImmutableSet, com.google.auto.value.processor.ClassNames.AUTO_VALUE_PACKAGE_NAME, .ClassNames.COPY_ANNOTATIONS_NAME, com.google.common.collect.Iterables.getOnlyElement, .Sets.union, java.util.stream.Collectors.joining, .Collectors.toCollection, .Collectors.toSet, javax.lang.model.util.ElementFilter.constructorsIn

Shared code between AutoValueProcessor, AutoOneOfProcessor, and AutoBuilderProcessor.
Author
[email protected] (Éamonn McManus)

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public static class
AutoValueishProcessor.GetterProperty

A Property that corresponds to an abstract getter method in the source.

pack-priv static enum
public static class
AutoValueishProcessor.Property

A property of an @AutoValue (etc) class, defined by one of its abstract methods.

Field Summary

Modifier and TypeField and Description
private final String
private javax.lang.model.element.TypeElement
annotationType

The annotation we are processing, for example AutoValue or AutoBuilder.

private final boolean
private final Map<String, String>
deferredTypeNames

Qualified names of @AutoValue (etc) classes that we attempted to process but had to abandon because we needed other types that they referenced and those other types were missing.

private ErrorReporter
private String

Constructor Summary

AccessConstructor and Description
pack-priv
AutoValueishProcessor(String annotationClassName, boolean appliesToInterfaces)

Method Summary

Modifier and TypeMethod and Description
pack-priv static ImmutableSet<javax.lang.model.element.ExecutableElement>
abstractMethodsIn(Iterable<javax.lang.model.element.ExecutableElement> methods)

Returns the subset of all abstract methods in the given set of methods.

pack-priv void
addDeferredType(javax.lang.model.element.TypeElement type, String missingType)

private boolean
annotationAppliesToFields(javax.lang.model.element.TypeElement annotation)

pack-priv static ImmutableList<javax.lang.model.element.AnnotationMirror>
annotationsToCopy(javax.lang.model.element.Element autoValueType, javax.lang.model.element.Element typeOrMethod, Set<String> excludedAnnotations, javax.lang.model.util.Types typeUtils)

Implements the semantics of AutoValue.CopyAnnotations; see its javadoc.

pack-priv static ImmutableList<String>
annotationStrings(List<? extends javax.lang.model.element.AnnotationMirror> annotations)

Returns the spelling to be used in the generated code for the given list of annotations.

private static boolean
annotationVisibleFrom(javax.lang.model.element.AnnotationMirror annotation, javax.lang.model.element.Element from, javax.lang.model.util.Types typeUtils)

pack-priv final void
checkModifiersIfNested(javax.lang.model.element.TypeElement type)

Checks that, if the given @AutoValue, @AutoOneOf, or @AutoBuilder class is nested, it is static and not private.

pack-priv final void
checkModifiersIfNested(javax.lang.model.element.TypeElement type, javax.lang.model.element.TypeElement reportedType, String what)

pack-priv final void
checkReturnType(javax.lang.model.element.TypeElement autoValueClass, javax.lang.model.element.ExecutableElement getter)

Checks that the return type of the given property method is allowed.

pack-priv ImmutableList<String>
copiedClassAnnotations(javax.lang.model.element.TypeElement type)

pack-priv ImmutableList<String>
copyAnnotations(javax.lang.model.element.Element autoValueType, javax.lang.model.element.Element typeOrMethod, Set<String> excludedAnnotations)

Implements the semantics of AutoValue.CopyAnnotations; see its javadoc.

pack-priv final ImmutableList<String>
deferredTypeNames()

Qualified names of @AutoValue (etc) classes that we attempted to process but had to abandon because we needed other types that they referenced and those other types were missing.

pack-priv final void
defineSharedVarsForType(javax.lang.model.element.TypeElement type, ImmutableSet<javax.lang.model.element.ExecutableElement> methods, Nullables nullables, AutoValueishTemplateVars vars)

Defines the template variables that are shared by AutoValue, AutoOneOf, and AutoBuilder.

private static Map<AutoValueishProcessor.ObjectMethod, javax.lang.model.element.ExecutableElement>
determineObjectMethodsToGenerate(Set<javax.lang.model.element.ExecutableElement> methods)

Given a list of all methods defined in or inherited by a class, returns a map indicating which of equals, hashCode, and toString should be generated.

private static String
disambiguate(String name, Collection<String> existingNames)

pack-priv final javax.lang.model.util.Elements
pack-priv static String
equalsParameterType(Map<AutoValueishProcessor.ObjectMethod, javax.lang.model.element.ExecutableElement>
the Object methods that are being generated
methodsToGenerate
,
Nullables nullables)

Returns the encoded parameter type of the equals(Object) method that is to be generated, or an empty string if the method is not being generated.

pack-priv final ErrorReporter
pack-priv static void
fixReservedIdentifiers(Map<?, String> methodToIdentifier)

Modifies the values of the given map to avoid reserved words.

pack-priv static String
generatedClassName(javax.lang.model.element.TypeElement
the name of the type bearing the @AutoValue (etc) annotation.
type
,
String
the prefix to use in the generated class. This may start with one or more dollar signs, for an @AutoValue implementation where there are AutoValue extensions.
prefix
)

Returns the name of the generated @AutoValue (etc) class, for example AutoOneOf_TaskResult or $$AutoValue_SimpleMethod.

private static String
getAnnotationFqName(javax.lang.model.element.AnnotationMirror annotation)

Returns the fully-qualified name of an annotation-mirror, e.g. "com.google.auto.value.AutoValue".

pack-priv static Optional<javax.lang.model.element.AnnotationMirror>
getAnnotationMirror(javax.lang.model.element.Element element, String annotationName)

pack-priv static Set<String>
getAnnotationsMarkedWithInherited(javax.lang.model.element.Element element)

pack-priv static Set<String>
getExcludedAnnotationClassNames(javax.lang.model.element.Element element)

Returns the contents of the AutoValue.CopyAnnotations.exclude element, as a set of strings that are fully-qualified class names.

private static Set<javax.lang.model.type.TypeMirror>
getExcludedAnnotationTypes(javax.lang.model.element.Element element)

Returns the contents of the AutoValue.CopyAnnotations.exclude element, as a set of TypeMirror where each type is an annotation type.

private static Set<String>
getReturnTypeAnnotations(javax.lang.model.element.ExecutableElement method, Predicate<javax.lang.model.element.TypeElement> typeFilter)

pack-priv final String
getSerialVersionUID(javax.lang.model.element.TypeElement type)

Returns a string like "private static final long serialVersionUID = 1234L" if type instanceof Serializable and defines serialVersionUID = 1234L; otherwise "".

public final javax.lang.model.SourceVersion
private static boolean
gettersAllPrefixed(Set<javax.lang.model.element.ExecutableElement> methods)

pack-priv static boolean
hasAnnotationMirror(javax.lang.model.element.Element element, String annotationName)

pack-priv static boolean
hasVisibleNoArgConstructor(javax.lang.model.element.TypeElement type)

True if the type is a class with a non-private no-arg constructor, or is an interface.

public synchronized void
init(javax.annotation.processing.ProcessingEnvironment processingEnv)

private static boolean
isInAutoValuePackage(String className)

True if the given class name is in the com.google.auto.value package or a subpackage.

private static boolean
isJavaLangObject(javax.lang.model.element.TypeElement type)

private static boolean
isNullable(javax.lang.model.type.TypeMirror type)

private static boolean
isNullable(javax.lang.model.type.TypeMirror type, int depth)

private static boolean
isNullable(javax.lang.model.element.AnnotationMirror annotation)

pack-priv static boolean
isPrefixedGetter(javax.lang.model.element.ExecutableElement method)

pack-priv static String
nameWithoutPrefix(String name)

Returns the name of the property defined by the given getter.

pack-priv static Optional<String>
nullableAnnotationFor(javax.lang.model.element.Element
the element that might be @Nullable, either a method or a parameter.
element
,
javax.lang.model.type.TypeMirror
the relevant type of the element: the return type for a method, or the parameter type for a parameter.
elementType
)

Returns an appropriate annotation spelling to indicate the nullability of an element.

pack-priv abstract Optional<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 OptionalInt
nullableAnnotationIndex(List<? extends javax.lang.model.element.AnnotationMirror> annotations)

pack-priv static AutoValueishProcessor.ObjectMethod
objectMethodToOverride(javax.lang.model.element.ExecutableElement method)

Determines which of the three public non-final methods from java.lang.Object, if any, is overridden by the given method.

pack-priv static ImmutableSet<javax.lang.model.element.ExecutableElement>
prefixedGettersIn(Collection<javax.lang.model.element.ExecutableElement> methods)

Returns the subset of the given zero-arg methods whose names begin with get.

public final boolean
process(Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)

pack-priv abstract void
processType(javax.lang.model.element.TypeElement
the class with the @AutoValue or @AutoOneOf annotation.
type
)

Analyzes a single @AutoValue (etc) class, and outputs the corresponding implementation class or classes.

pack-priv boolean
propertiesCanBeVoid()

True if void properties are allowed.

pack-priv final ImmutableListMultimap<javax.lang.model.element.ExecutableElement, javax.lang.model.element.AnnotationMirror>
propertyFieldAnnotationMap(javax.lang.model.element.TypeElement type, ImmutableSet<javax.lang.model.element.ExecutableElement> propertyMethods)

private ImmutableList<javax.lang.model.element.AnnotationMirror>
propertyFieldAnnotations(javax.lang.model.element.TypeElement type, javax.lang.model.element.ExecutableElement method)

pack-priv static ImmutableListMultimap<javax.lang.model.element.ExecutableElement, javax.lang.model.element.AnnotationMirror>
propertyMethodAnnotationMap(javax.lang.model.element.TypeElement type, ImmutableSet<javax.lang.model.element.ExecutableElement> propertyMethods, javax.lang.model.util.Types typeUtils)

pack-priv static ImmutableList<javax.lang.model.element.AnnotationMirror>
propertyMethodAnnotations(javax.lang.model.element.TypeElement type, javax.lang.model.element.ExecutableElement method, javax.lang.model.util.Types typeUtils)

pack-priv ImmutableMap<javax.lang.model.element.ExecutableElement, javax.lang.model.type.TypeMirror>
propertyMethodsIn(Set<javax.lang.model.element.ExecutableElement> abstractMethods, javax.lang.model.element.TypeElement autoValueOrOneOfType)

Returns the subset of property methods in the given set of abstract methods, with their actual return types.

pack-priv final ImmutableBiMap<String, javax.lang.model.element.ExecutableElement>
propertyNameToMethodMap(Set<javax.lang.model.element.ExecutableElement> propertyMethods)

Returns a bi-map between property names and the corresponding abstract property methods.

pack-priv final ImmutableSet<AutoValueishProcessor.Property>
propertySet(ImmutableMap<javax.lang.model.element.ExecutableElement, javax.lang.model.type.TypeMirror> propertyMethodsAndTypes, ImmutableListMultimap<javax.lang.model.element.ExecutableElement, javax.lang.model.element.AnnotationMirror> annotatedPropertyFields, ImmutableListMultimap<javax.lang.model.element.ExecutableElement, javax.lang.model.element.AnnotationMirror>
a map from property methods to the method annotations that should go on the implementation of those methods. These annotations are method annotations specifically. Type annotations do not appear because they are considered part of the return type and will appear when that is spelled out. Annotations that are excluded by AutoValue.CopyAnnotations also do not appear here.
annotatedPropertyMethods
,
Nullables nullables)

Returns the ordered set of Property definitions for the given @AutoValue or AutoOneOf type.

pack-priv final javax.lang.model.util.Types
private void
validateType(javax.lang.model.element.TypeElement type)

Validations common to all the subclasses.

private void
warnAboutPrimitiveArrays(javax.lang.model.element.TypeElement autoValueClass, javax.lang.model.element.ExecutableElement getter)

private static String
wildcardTypeParametersString(javax.lang.model.element.TypeElement type)

Returns the @AutoValue or @AutoOneOf type parameters, with a ?

pack-priv final void
writeSourceFile(String className, String text, javax.lang.model.element.TypeElement originatingType)