Class 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
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static 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.
      private com.google.common.collect.ImmutableList<AutoValueExtension> extensions  
      private java.lang.ClassLoader loaderForExtensions  
      • Fields inherited from class javax.annotation.processing.AbstractProcessor

        processingEnv
    • 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 boolean ancestorIsAutoValue​(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 of AutoValue.CopyAnnotations; see its javadoc.
      private boolean annotationVisibleFrom​(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 of AutoValue.CopyAnnotations; see its javadoc.
      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)  
      private java.lang.String extensionName​(AutoValueExtension extension)  
      private static java.lang.String generatedSubclassName​(javax.lang.model.element.TypeElement type, int depth)  
      private static java.lang.String getAnnotationFqName​(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 the AutoValue.CopyAnnotations.exclude element, as a list of strings that are fully-qualified class names.
      private javax.lang.model.type.TypeMirror getTypeMirror​(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 boolean implementsAnnotation​(javax.lang.model.element.TypeElement type)  
      void init​(javax.annotation.processing.ProcessingEnvironment processingEnv)  
      private static boolean isNullable​(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 @Nullable annotation to put on the implementation of the given property method, and indicates whether the property is in fact nullable.
      private static java.util.OptionalInt nullableAnnotationIndex​(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) void processType​(javax.lang.model.element.TypeElement type)
      Analyzes a single @AutoValue or @AutoOneOf class, 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 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)  
      private int writeExtensions​(javax.lang.model.element.TypeElement type, ExtensionContext context, com.google.common.collect.ImmutableList<AutoValueExtension> applicableExtensions)  
      • Methods inherited from class javax.annotation.processing.AbstractProcessor

        getCompletions, getSupportedAnnotationTypes, getSupportedOptions, isInitialized
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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:
        init in interface javax.annotation.processing.Processor
        Overrides:
        init in class AutoValueOrOneOfProcessor
      • 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: AutoValueOrOneOfProcessor
        Analyzes a single @AutoValue or @AutoOneOf class, and outputs the corresponding implementation class or classes.
        Specified by:
        processType in class AutoValueOrOneOfProcessor
        Parameters:
        type - the class with the @AutoValue or @AutoOneOf annotation.
      • 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 of AutoValue.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 of AutoValue.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 the AutoValue.CopyAnnotations.exclude element, 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: AutoValueOrOneOfProcessor
        Returns the appropriate @Nullable annotation 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 returns Optional.of(""), to indicate that the property is nullable but the method isn't. The @Nullable annotation will instead appear when the return type of the method is spelled out in the implementation.
        Specified by:
        nullableAnnotationForMethod in class AutoValueOrOneOfProcessor
        methodAnnotations - the annotations to include on propertyMethod. This is governed by the AutoValue.CopyAnnotations logic.
      • 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)