Package com.google.auto.value.processor
Class AutoAnnotationProcessor
java.lang.Object
javax.annotation.processing.AbstractProcessor
com.google.auto.value.processor.AutoAnnotationProcessor
- All Implemented Interfaces:
Processor
@AutoService(javax.annotation.processing.Processor.class)
@SupportedAnnotationTypes("com.google.auto.value.AutoAnnotation")
public class AutoAnnotationProcessor
extends AbstractProcessor
Javac annotation processor (compiler plugin) to generate annotation implementations. User code
never references this class.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
-
Field Summary
FieldsFields inherited from class javax.annotation.processing.AbstractProcessor
processingEnv
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate AbortProcessingException
abortWithError
(String msg, Element e) Issue a compilation error and return an exception that, when thrown, will cause the processing of this class to be abandoned.private boolean
compatibleTypes
(TypeMirror parameterType, TypeMirror memberType) Returns true ifparameterType
can be used to provide the value of an annotation member of typememberType
.private static String
fullyQualifiedName
(String pkg, String cls) private String
generatedClassName
(ExecutableElement method) private TypeElement
private com.google.common.collect.ImmutableMap
<String, AnnotationValue> getDefaultValues
(TypeElement annotationElement) private String
private com.google.common.collect.ImmutableMap
<String, ExecutableElement> getMemberMethods
(TypeElement annotationElement) private com.google.common.collect.ImmutableMap
<String, AutoAnnotationProcessor.Member> getMembers
(Element context, com.google.common.collect.ImmutableMap<String, ExecutableElement> memberMethods) private com.google.common.collect.ImmutableMap
<String, AutoAnnotationProcessor.Parameter> getParameters
(TypeElement annotationElement, ExecutableElement method, Map<String, AutoAnnotationProcessor.Member> members) private TypeMirror
getTypeMirror
(Class<?> c) invariableHash
(List<? extends AnnotationValue> annotationValues) invariableHash
(AnnotationValue annotationValue) Returns the hashCode of the given AnnotationValue, if that hashCode is guaranteed to be always the same.invariableHashes
(com.google.common.collect.ImmutableMap<String, AutoAnnotationProcessor.Member> members, com.google.common.collect.ImmutableSet<String> parameters) Returns a map from the names of members with invariable hashCodes to the values of those hashCodes.private static boolean
isGwtCompatible
(TypeElement annotationElement) private boolean
methodsAreOverloaded
(List<ExecutableElement> methods) boolean
process
(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) private void
process
(RoundEnvironment roundEnv) private void
processMethod
(ExecutableElement method) private void
reportError
(Element e, String msg, Object... msgParams) Issue a compilation error.private void
validateParameters
(TypeElement annotationElement, ExecutableElement method, com.google.common.collect.ImmutableMap<String, AutoAnnotationProcessor.Member> members, com.google.common.collect.ImmutableMap<String, AutoAnnotationProcessor.Parameter> parameters, com.google.common.collect.ImmutableMap<String, AnnotationValue> defaultValues) Returns the wrapper types (Integer.class
etc) that are used in collection parameters likeList<Integer>
.private void
writeSourceFile
(String className, String text, TypeElement originatingType) Methods inherited from class javax.annotation.processing.AbstractProcessor
getCompletions, getSupportedAnnotationTypes, getSupportedOptions, init, isInitialized
-
Field Details
-
elementUtils
-
typeUtils
-
-
Constructor Details
-
AutoAnnotationProcessor
public AutoAnnotationProcessor()
-
-
Method Details
-
getSupportedSourceVersion
- Specified by:
getSupportedSourceVersion
in interfaceProcessor
- Overrides:
getSupportedSourceVersion
in classAbstractProcessor
-
reportError
Issue a compilation error. This method does not throw an exception, since we want to continue processing and perhaps report other errors. -
abortWithError
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
- Specified by:
process
in interfaceProcessor
- Specified by:
process
in classAbstractProcessor
-
process
-
processMethod
-
getGeneratedTypeName
-
invariableHash
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
-
invariableHashes
private static com.google.common.collect.ImmutableMap<String,Integer> invariableHashes(com.google.common.collect.ImmutableMap<String, AutoAnnotationProcessor.Member> members, com.google.common.collect.ImmutableSet<String> parameters) Returns a map from the names of members with invariable hashCodes to the values of those hashCodes. -
methodsAreOverloaded
-
generatedClassName
-
getAnnotationReturnType
-
getMemberMethods
private com.google.common.collect.ImmutableMap<String,ExecutableElement> getMemberMethods(TypeElement annotationElement) -
getMembers
private com.google.common.collect.ImmutableMap<String,AutoAnnotationProcessor.Member> getMembers(Element context, com.google.common.collect.ImmutableMap<String, ExecutableElement> memberMethods) -
getDefaultValues
private com.google.common.collect.ImmutableMap<String,AnnotationValue> getDefaultValues(TypeElement annotationElement) -
getParameters
private com.google.common.collect.ImmutableMap<String,AutoAnnotationProcessor.Parameter> getParameters(TypeElement annotationElement, ExecutableElement method, Map<String, AutoAnnotationProcessor.Member> members) -
validateParameters
private void validateParameters(TypeElement annotationElement, ExecutableElement method, com.google.common.collect.ImmutableMap<String, AutoAnnotationProcessor.Member> members, com.google.common.collect.ImmutableMap<String, AutoAnnotationProcessor.Parameter> parameters, com.google.common.collect.ImmutableMap<String, AnnotationValue> defaultValues) -
compatibleTypes
Returns true ifparameterType
can 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
Returns the wrapper types (Integer.class
etc) 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
-
isGwtCompatible
-
fullyQualifiedName
-
writeSourceFile
-