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 User's Guide
    • Field Detail

      • 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.
      • 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)
      • nullableAnnotationForMethod

        java.util.Optional<java.lang.String> nullableAnnotationForMethod​(javax.lang.model.element.ExecutableElement propertyMethod)
        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
      • nullableAnnotationFor

        static java.util.Optional<java.lang.String> nullableAnnotationFor​(javax.lang.model.element.Element element,
                                                                          javax.lang.model.type.TypeMirror elementType)
        Returns an appropriate annotation spelling to indicate the nullability of an element. If the return value is a non-empty Optional, that indicates that the element is nullable, and the string should be used to annotate it. If the return value is an empty Optional, the element is not nullable. The return value can be Optional.of(""), which indicates that the element is nullable but that the nullability comes from a type annotation. In this case, the annotation will appear when the type is written, and must not be specified again. If the Optional contains a present non-empty string then that string will end with a space.
        Parameters:
        element - the element that might be @Nullable, either a method or a parameter.
        elementType - the relevant type of the element: the return type for a method, or the parameter type for a parameter.
      • 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)
      • 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)