Package com.google.auto.value.processor
Class AutoAnnotationProcessor
- java.lang.Object
-
- javax.annotation.processing.AbstractProcessor
-
- com.google.auto.value.processor.AutoAnnotationProcessor
-
- All Implemented Interfaces:
javax.annotation.processing.Processor
@AutoService(javax.annotation.processing.Processor.class) @SupportedAnnotationTypes("com.google.auto.value.AutoAnnotation") public class AutoAnnotationProcessor extends javax.annotation.processing.AbstractProcessor
Javac annotation processor (compiler plugin) to generate annotation implementations. User code never references this class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAutoAnnotationProcessor.Memberstatic classAutoAnnotationProcessor.Parameter
-
Field Summary
Fields Modifier and Type Field Description private javax.lang.model.util.ElementselementUtilsprivate javax.lang.model.util.TypestypeUtils
-
Constructor Summary
Constructors Constructor Description AutoAnnotationProcessor()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private AbortProcessingExceptionabortWithError(java.lang.String msg, javax.lang.model.element.Element e)Issue a compilation error and return an exception that, when thrown, will cause the processing of this class to be abandoned.private booleancompatibleTypes(javax.lang.model.type.TypeMirror parameterType, javax.lang.model.type.TypeMirror memberType)Returns true ifparameterTypecan be used to provide the value of an annotation member of typememberType.private static java.lang.StringfullyQualifiedName(java.lang.String pkg, java.lang.String cls)private java.lang.StringgeneratedClassName(javax.lang.model.element.ExecutableElement method)private javax.lang.model.element.TypeElementgetAnnotationReturnType(javax.lang.model.element.ExecutableElement method)private com.google.common.collect.ImmutableMap<java.lang.String,javax.lang.model.element.AnnotationValue>getDefaultValues(javax.lang.model.element.TypeElement annotationElement)private java.lang.StringgetGeneratedTypeName()private com.google.common.collect.ImmutableMap<java.lang.String,javax.lang.model.element.ExecutableElement>getMemberMethods(javax.lang.model.element.TypeElement annotationElement)private com.google.common.collect.ImmutableMap<java.lang.String,AutoAnnotationProcessor.Member>getMembers(javax.lang.model.element.Element context, com.google.common.collect.ImmutableMap<java.lang.String,javax.lang.model.element.ExecutableElement> memberMethods)private com.google.common.collect.ImmutableMap<java.lang.String,AutoAnnotationProcessor.Parameter>getParameters(javax.lang.model.element.TypeElement annotationElement, javax.lang.model.element.ExecutableElement method, java.util.Map<java.lang.String,AutoAnnotationProcessor.Member> members)javax.lang.model.SourceVersiongetSupportedSourceVersion()private javax.lang.model.type.TypeMirrorgetTypeMirror(java.lang.Class<?> c)private static java.util.Optional<java.lang.Integer>invariableHash(java.util.List<? extends javax.lang.model.element.AnnotationValue> annotationValues)private static java.util.Optional<java.lang.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 com.google.common.collect.ImmutableMap<java.lang.String,java.lang.Integer>invariableHashes(com.google.common.collect.ImmutableMap<java.lang.String,AutoAnnotationProcessor.Member> members, com.google.common.collect.ImmutableSet<java.lang.String> parameters)Returns a map from the names of members with invariable hashCodes to the values of those hashCodes.private static booleanisGwtCompatible(javax.lang.model.element.TypeElement annotationElement)private booleanmethodsAreOverloaded(java.util.List<javax.lang.model.element.ExecutableElement> methods)booleanprocess(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)private voidprocess(javax.annotation.processing.RoundEnvironment roundEnv)private voidprocessMethod(javax.lang.model.element.ExecutableElement method)private voidreportError(javax.lang.model.element.Element e, java.lang.String msg, java.lang.Object... msgParams)Issue a compilation error.private voidvalidateParameters(javax.lang.model.element.TypeElement annotationElement, javax.lang.model.element.ExecutableElement method, com.google.common.collect.ImmutableMap<java.lang.String,AutoAnnotationProcessor.Member> members, com.google.common.collect.ImmutableMap<java.lang.String,AutoAnnotationProcessor.Parameter> parameters, com.google.common.collect.ImmutableMap<java.lang.String,javax.lang.model.element.AnnotationValue> defaultValues)private java.util.Set<java.lang.Class<?>>wrapperTypesUsedInCollections(javax.lang.model.element.ExecutableElement method)Returns the wrapper types (Integer.classetc) that are used in collection parameters likeList<Integer>.private voidwriteSourceFile(java.lang.String className, java.lang.String text, javax.lang.model.element.TypeElement originatingType)
-
-
-
Method Detail
-
getSupportedSourceVersion
public javax.lang.model.SourceVersion getSupportedSourceVersion()
- Specified by:
getSupportedSourceVersionin interfacejavax.annotation.processing.Processor- Overrides:
getSupportedSourceVersionin classjavax.annotation.processing.AbstractProcessor
-
reportError
private void reportError(javax.lang.model.element.Element e, java.lang.String msg, java.lang.Object... msgParams)Issue a compilation error. This method does not throw an exception, since we want to continue processing and perhaps report other errors.
-
abortWithError
private AbortProcessingException abortWithError(java.lang.String msg, javax.lang.model.element.Element e)
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.
-
process
public boolean process(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)- Specified by:
processin interfacejavax.annotation.processing.Processor- Specified by:
processin classjavax.annotation.processing.AbstractProcessor
-
process
private void process(javax.annotation.processing.RoundEnvironment roundEnv)
-
processMethod
private void processMethod(javax.lang.model.element.ExecutableElement method)
-
getGeneratedTypeName
private java.lang.String getGeneratedTypeName()
-
invariableHash
private static java.util.Optional<java.lang.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.
-
invariableHash
private static java.util.Optional<java.lang.Integer> invariableHash(java.util.List<? extends javax.lang.model.element.AnnotationValue> annotationValues)
-
invariableHashes
private static com.google.common.collect.ImmutableMap<java.lang.String,java.lang.Integer> invariableHashes(com.google.common.collect.ImmutableMap<java.lang.String,AutoAnnotationProcessor.Member> members, com.google.common.collect.ImmutableSet<java.lang.String> parameters)
Returns a map from the names of members with invariable hashCodes to the values of those hashCodes.
-
methodsAreOverloaded
private boolean methodsAreOverloaded(java.util.List<javax.lang.model.element.ExecutableElement> methods)
-
generatedClassName
private java.lang.String generatedClassName(javax.lang.model.element.ExecutableElement method)
-
getAnnotationReturnType
private javax.lang.model.element.TypeElement getAnnotationReturnType(javax.lang.model.element.ExecutableElement method)
-
getMemberMethods
private com.google.common.collect.ImmutableMap<java.lang.String,javax.lang.model.element.ExecutableElement> getMemberMethods(javax.lang.model.element.TypeElement annotationElement)
-
getMembers
private com.google.common.collect.ImmutableMap<java.lang.String,AutoAnnotationProcessor.Member> getMembers(javax.lang.model.element.Element context, com.google.common.collect.ImmutableMap<java.lang.String,javax.lang.model.element.ExecutableElement> memberMethods)
-
getDefaultValues
private com.google.common.collect.ImmutableMap<java.lang.String,javax.lang.model.element.AnnotationValue> getDefaultValues(javax.lang.model.element.TypeElement annotationElement)
-
getParameters
private com.google.common.collect.ImmutableMap<java.lang.String,AutoAnnotationProcessor.Parameter> getParameters(javax.lang.model.element.TypeElement annotationElement, javax.lang.model.element.ExecutableElement method, java.util.Map<java.lang.String,AutoAnnotationProcessor.Member> members)
-
validateParameters
private void validateParameters(javax.lang.model.element.TypeElement annotationElement, javax.lang.model.element.ExecutableElement method, com.google.common.collect.ImmutableMap<java.lang.String,AutoAnnotationProcessor.Member> members, com.google.common.collect.ImmutableMap<java.lang.String,AutoAnnotationProcessor.Parameter> parameters, com.google.common.collect.ImmutableMap<java.lang.String,javax.lang.model.element.AnnotationValue> defaultValues)
-
compatibleTypes
private boolean compatibleTypes(javax.lang.model.type.TypeMirror parameterType, javax.lang.model.type.TypeMirror memberType)Returns true ifparameterTypecan be used to provide the value of an annotation member of typememberType. 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.
-
wrapperTypesUsedInCollections
private java.util.Set<java.lang.Class<?>> wrapperTypesUsedInCollections(javax.lang.model.element.ExecutableElement method)
Returns the wrapper types (Integer.classetc) that are used in collection parameters likeList<Integer>. This is needed because we will emit a helper method for each such type, for example to convertCollection<Integer>intoint[].
-
getTypeMirror
private javax.lang.model.type.TypeMirror getTypeMirror(java.lang.Class<?> c)
-
isGwtCompatible
private static boolean isGwtCompatible(javax.lang.model.element.TypeElement annotationElement)
-
fullyQualifiedName
private static java.lang.String fullyQualifiedName(java.lang.String pkg, java.lang.String cls)
-
writeSourceFile
private void writeSourceFile(java.lang.String className, java.lang.String text, javax.lang.model.element.TypeElement originatingType)
-
-