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

public Class AutoAnnotationProcessor

extends javax.annotation.processing.AbstractProcessor
Class Inheritance
Annotations
@AutoService:javax.annotation.processing.Processor
@IncrementalAnnotationProcessor:ISOLATING
@javax.annotation.processing.SupportedAnnotationTypes
Static Imports
com.google.auto.common.GeneratedAnnotations.generatedAnnotation, com.google.auto.value.processor.ClassNames.AUTO_ANNOTATION_NAME, com.google.common.collect.Maps.immutableEntry, java.util.Comparator.comparing, java.util.stream.Collectors.joining

Javac annotation processor (compiler plugin) to generate annotation implementations. User code never references this class.
Author
[email protected] (Éamonn McManus)

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static class

Field Summary

Modifier and TypeField and Description
private javax.lang.model.util.Elements
private javax.lang.model.type.TypeMirror
private javax.lang.model.util.Types

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private AbortProcessingException
abortWithError(javax.lang.model.element.Element e, String msg, Object... msgParams)

Issue a compilation error and return an exception that, when thrown, will cause the processing of this class to be abandoned.

private boolean
compatibleTypes(javax.lang.model.type.TypeMirror parameterType, javax.lang.model.type.TypeMirror memberType)

Returns true if parameterType can be used to provide the value of an annotation member of type memberType.

private static long
computeSerialVersionUid(ImmutableMap<String, AutoAnnotationProcessor.Member> members, ImmutableMap<String, AutoAnnotationProcessor.Parameter> parameters)

We compute a serialVersionUID for the generated class based on the names and types of the annotation members that the @AutoAnnotation method defines.

private String
private static String
private String
generatedClassName(javax.lang.model.element.ExecutableElement method)

private javax.lang.model.element.TypeElement
getAnnotationReturnType(javax.lang.model.element.ExecutableElement method)

private ImmutableMap<String, javax.lang.model.element.AnnotationValue>
getDefaultValues(javax.lang.model.element.TypeElement annotationElement)

private String
private ImmutableMap<String, javax.lang.model.element.ExecutableElement>
getMemberMethods(javax.lang.model.element.TypeElement annotationElement)

private ImmutableMap<String, AutoAnnotationProcessor.Member>
getMembers(javax.lang.model.element.Element context, ImmutableMap<String, javax.lang.model.element.ExecutableElement> memberMethods)

private ImmutableMap<String, AutoAnnotationProcessor.Parameter>
getParameters(javax.lang.model.element.TypeElement annotationElement, javax.lang.model.element.ExecutableElement method, Map<String, AutoAnnotationProcessor.Member> members)

public ImmutableSet<String>
public javax.lang.model.SourceVersion
private javax.lang.model.type.TypeMirror
public synchronized void
init(javax.annotation.processing.ProcessingEnvironment processingEnv)

private static Optional<Integer>
invariableHash(javax.lang.model.element.AnnotationValue annotationValue)

Returns the hashCode of the given AnnotationValue, if that hashCode is guaranteed to be always the same.

private static Optional<Integer>
invariableHash(List<? extends javax.lang.model.element.AnnotationValue> annotationValues)

private static ImmutableMap<String, Integer>
invariableHashes(ImmutableMap<String, AutoAnnotationProcessor.Member> members, ImmutableSet<String> parameters)

Returns a map from the names of members with invariable hashCodes to the values of those hashCodes.

private static boolean
isGwtCompatible(javax.lang.model.element.TypeElement annotationElement)

private boolean
methodsAreOverloaded(List<javax.lang.model.element.ExecutableElement> methods)

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

private void
process(javax.annotation.processing.RoundEnvironment roundEnv)

private void
processMethod(javax.lang.model.element.ExecutableElement method)

private void
reportError(javax.lang.model.element.Element e, String msg, Object... msgParams)

Issue a compilation error.

private void
validateParameters(javax.lang.model.element.TypeElement annotationElement, javax.lang.model.element.ExecutableElement method, ImmutableMap<String, AutoAnnotationProcessor.Member> members, ImmutableMap<String, AutoAnnotationProcessor.Parameter> parameters, ImmutableMap<String, javax.lang.model.element.AnnotationValue> defaultValues)

private ImmutableSet<Class<?>>
wrapperTypesUsedInCollections(javax.lang.model.element.ExecutableElement method)

Returns the wrapper types (Integer.class etc) that are used in collection parameters like List<Integer>.

private void
writeSourceFile(String className, String text, javax.lang.model.element.TypeElement originatingType)

Field Detail

elementUtilsback to summary
private javax.lang.model.util.Elements elementUtils
javaLangObjectback to summary
private javax.lang.model.type.TypeMirror javaLangObject
typeUtilsback to summary
private javax.lang.model.util.Types typeUtils

Constructor Detail

AutoAnnotationProcessorback to summary
public AutoAnnotationProcessor()

Method Detail

abortWithErrorback to summary
private AbortProcessingException abortWithError(javax.lang.model.element.Element e, String msg, Object... msgParams)

Issue a compilation error and return an exception that, when thrown, will cause the processing of this class to be abandoned. This does not prevent the processing of other classes.

Annotations
@FormatMethod
compatibleTypesback to summary
private boolean compatibleTypes(javax.lang.model.type.TypeMirror parameterType, javax.lang.model.type.TypeMirror memberType)

Returns true if parameterType can be used to provide the value of an annotation member of type memberType. They must either be the same type, or the member type must be an array and the parameter type must be a collection of a compatible type.

computeSerialVersionUidback to summary
private static long computeSerialVersionUid(ImmutableMap<String, AutoAnnotationProcessor.Member> members, ImmutableMap<String, AutoAnnotationProcessor.Parameter> parameters)

We compute a serialVersionUID for the generated class based on the names and types of the annotation members that the @AutoAnnotation method defines. These are exactly the names and types of the instance fields in the generated class. So in the common case where the annotation acquires a new member with a default value, if the @AutoAnnotation method is not changed then the generated class will acquire an implementation of the new member method which just returns the default value. The serialVersionUID will not change, which makes sense because the instance fields haven't changed, and instances that were serialized before the new member was added should deserialize fine. On the other hand, if you then add a parameter to the @AutoAnnotation method for the new member, the implementation class will acquire a new instance field, and we will compute a different serialVersionUID. That's because an instance serialized before that change would not have a value for the new instance field, which would end up zero or null. Users don't expect annotation methods to return null so that would be bad.

We could instead add a readObject(ObjectInputStream) method that would check that all of the instance fields are really present in the deserialized instance, and perhaps replace them with their default values from the annotation if not. That seems a lot more complicated than is justified, though, especially since the instance fields are final and would have to be set in the deserialized object through reflection.

equalsParameterTypeback to summary
private String equalsParameterType()
fullyQualifiedNameback to summary
private static String fullyQualifiedName(String pkg, String cls)
generatedClassNameback to summary
private String generatedClassName(javax.lang.model.element.ExecutableElement method)
getAnnotationReturnTypeback to summary
private javax.lang.model.element.TypeElement getAnnotationReturnType(javax.lang.model.element.ExecutableElement method)
getDefaultValuesback to summary
private ImmutableMap<String, javax.lang.model.element.AnnotationValue> getDefaultValues(javax.lang.model.element.TypeElement annotationElement)
getGeneratedTypeNameback to summary
private String getGeneratedTypeName()
getMemberMethodsback to summary
private ImmutableMap<String, javax.lang.model.element.ExecutableElement> getMemberMethods(javax.lang.model.element.TypeElement annotationElement)
getMembersback to summary
private ImmutableMap<String, AutoAnnotationProcessor.Member> getMembers(javax.lang.model.element.Element context, ImmutableMap<String, javax.lang.model.element.ExecutableElement> memberMethods)
getParametersback to summary
private ImmutableMap<String, AutoAnnotationProcessor.Parameter> getParameters(javax.lang.model.element.TypeElement annotationElement, javax.lang.model.element.ExecutableElement method, Map<String, AutoAnnotationProcessor.Member> members)
getSupportedOptionsback to summary
public ImmutableSet<String> getSupportedOptions()
Annotations
@Override
getSupportedSourceVersionback to summary
public javax.lang.model.SourceVersion getSupportedSourceVersion()
Annotations
@Override
getTypeMirrorback to summary
private javax.lang.model.type.TypeMirror getTypeMirror(Class<?> c)
initback to summary
public synchronized void init(javax.annotation.processing.ProcessingEnvironment processingEnv)
Annotations
@Override
invariableHashback to summary
private static Optional<Integer> invariableHash(javax.lang.model.element.AnnotationValue annotationValue)

Returns the hashCode of the given AnnotationValue, if that hashCode is guaranteed to be always the same. The hashCode of a String or primitive type never changes. The hashCode of a Class or an enum constant does potentially change in different runs of the same program. The hashCode of an array doesn't change if the hashCodes of its elements don't. Although we could have a similar rule for nested annotation values, we currently don't.

invariableHashback to summary
private static Optional<Integer> invariableHash(List<? extends javax.lang.model.element.AnnotationValue> annotationValues)
invariableHashesback to summary
private static ImmutableMap<String, Integer> invariableHashes(ImmutableMap<String, AutoAnnotationProcessor.Member> members, ImmutableSet<String> parameters)

Returns a map from the names of members with invariable hashCodes to the values of those hashCodes.

isGwtCompatibleback to summary
private static boolean isGwtCompatible(javax.lang.model.element.TypeElement annotationElement)
methodsAreOverloadedback to summary
private boolean methodsAreOverloaded(List<javax.lang.model.element.ExecutableElement> methods)
processback to summary
public boolean process(Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)
Annotations
@Override
processback to summary
private void process(javax.annotation.processing.RoundEnvironment roundEnv)
processMethodback to summary
private void processMethod(javax.lang.model.element.ExecutableElement method)
reportErrorback to summary
private void reportError(javax.lang.model.element.Element e, String msg, Object... msgParams)

Issue a compilation error. This method does not throw an exception, since we want to continue processing and perhaps report other errors.

Annotations
@FormatMethod
validateParametersback to summary
private void validateParameters(javax.lang.model.element.TypeElement annotationElement, javax.lang.model.element.ExecutableElement method, ImmutableMap<String, AutoAnnotationProcessor.Member> members, ImmutableMap<String, AutoAnnotationProcessor.Parameter> parameters, ImmutableMap<String, javax.lang.model.element.AnnotationValue> defaultValues)
wrapperTypesUsedInCollectionsback to summary
private ImmutableSet<Class<?>> wrapperTypesUsedInCollections(javax.lang.model.element.ExecutableElement method)

Returns the wrapper types (Integer.class etc) that are used in collection parameters like List<Integer>. This is needed because we will emit a helper method for each such type, for example to convert Collection<Integer> into int[].

writeSourceFileback to summary
private void writeSourceFile(String className, String text, javax.lang.model.element.TypeElement originatingType)
com.google.auto.value.processor back to summary

public Class AutoAnnotationProcessor.Member

extends Object
Class Inheritance
  • java.lang.Object
  • com.google.auto.value.processor.AutoAnnotationProcessor.Member

Field Summary

Modifier and TypeField and Description
private final javax.lang.model.element.Element
private final javax.lang.model.element.ExecutableElement
private final javax.annotation.processing.ProcessingEnvironment

Constructor Summary

AccessConstructor and Description
pack-priv
Member(javax.annotation.processing.ProcessingEnvironment processingEnv, javax.lang.model.element.Element context, javax.lang.model.element.ExecutableElement method)

Method Summary

Modifier and TypeMethod and Description
public String
public String
public javax.lang.model.type.TypeKind
public int
public String
public javax.lang.model.type.TypeMirror
public boolean
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

contextback to summary
private final javax.lang.model.element.Element context
methodback to summary
private final javax.lang.model.element.ExecutableElement method
processingEnvback to summary
private final javax.annotation.processing.ProcessingEnvironment processingEnv

Constructor Detail

Memberback to summary
pack-priv Member(javax.annotation.processing.ProcessingEnvironment processingEnv, javax.lang.model.element.Element context, javax.lang.model.element.ExecutableElement method)

Method Detail

getComponentTypeback to summary
public String getComponentType()
getDefaultValueback to summary
public String getDefaultValue()
getKindback to summary
public javax.lang.model.type.TypeKind getKind()
getNameHashback to summary
public int getNameHash()
getTypeback to summary
public String getType()
getTypeMirrorback to summary
public javax.lang.model.type.TypeMirror getTypeMirror()
isArrayOfClassWithBoundsback to summary
public boolean isArrayOfClassWithBounds()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

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

public Class AutoAnnotationProcessor.Parameter

extends Object
Class Inheritance
  • java.lang.Object
  • com.google.auto.value.processor.AutoAnnotationProcessor.Parameter

Field Summary

Modifier and TypeField and Description
private final javax.lang.model.type.TypeKind
private final String

Constructor Summary

AccessConstructor and Description
pack-priv
Parameter(javax.lang.model.type.TypeMirror type)

Method Summary

Modifier and TypeMethod and Description
public javax.lang.model.type.TypeKind
public String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

kindback to summary
private final javax.lang.model.type.TypeKind kind
typeNameback to summary
private final String typeName

Constructor Detail

Parameterback to summary
pack-priv Parameter(javax.lang.model.type.TypeMirror type)

Method Detail

getKindback to summary
public javax.lang.model.type.TypeKind getKind()
getTypeback to summary
public String getType()