Class Processors


  • public final class Processors
    extends java.lang.Object
    Static helper methods for writing a processor.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addGeneratedAnnotation​(com.squareup.javapoet.TypeSpec.Builder typeSpecBuilder, javax.annotation.processing.ProcessingEnvironment env, java.lang.Class<?> generatorClass)  
      static void addGeneratedAnnotation​(com.squareup.javapoet.TypeSpec.Builder typeSpecBuilder, javax.annotation.processing.ProcessingEnvironment env, java.lang.String generatorClass)  
      static com.squareup.javapoet.ClassName append​(com.squareup.javapoet.ClassName name, java.lang.String suffix)
      Appends the given string to the end of the class name.
      static void checkForCompilationError​(javax.lang.model.element.TypeElement e)
      Checks that the given element is not the error type.
      static com.google.common.collect.ImmutableMap<java.lang.String,​javax.lang.model.element.AnnotationValue> convertToAttributeNameMap​(java.util.Map<? extends javax.lang.model.element.ExecutableElement,​? extends javax.lang.model.element.AnnotationValue> annotationValues)
      Converts an annotation value map to be keyed by the attribute name.
      static com.squareup.javapoet.MethodSpec.Builder copyMethodSpecWithoutBody​(com.squareup.javapoet.MethodSpec methodSpec)  
      static void generateAggregatingClass​(java.lang.String aggregatingPackage, com.squareup.javapoet.AnnotationSpec aggregatingAnnotation, javax.lang.model.element.TypeElement element, java.lang.Class<?> generatedAnnotationClass, javax.annotation.processing.ProcessingEnvironment env)  
      static com.google.common.collect.ImmutableList<javax.lang.model.element.ExecutableElement> getAllMethods​(javax.lang.model.element.TypeElement element)
      Returns all transitive methods from a given TypeElement, not including constructors.
      static com.google.common.collect.Multimap<java.lang.String,​javax.lang.model.element.AnnotationMirror> getAnnotationAnnotationArrayValues​(javax.lang.model.util.Elements elements, javax.lang.model.element.AnnotationMirror annotation)
      Returns a multimap from attribute name to the values that are an array of annotation mirrors.
      static javax.lang.model.element.TypeElement getAnnotationClassValue​(javax.lang.model.util.Elements elements, javax.lang.model.element.AnnotationMirror annotation, java.lang.String key)
      Returns the TypeElement for a class attribute on an annotation.
      static com.google.common.collect.ImmutableList<javax.lang.model.element.TypeElement> getAnnotationClassValues​(javax.lang.model.util.Elements elements, javax.lang.model.element.AnnotationMirror annotation, java.lang.String key)
      Returns a list of TypeElements for a class attribute on an annotation.
      static javax.lang.model.element.AnnotationMirror getAnnotationMirror​(javax.lang.model.element.Element element, com.squareup.javapoet.ClassName className)
      Returns the annotation mirror from the given element that corresponds to the given class.
      static javax.lang.model.element.AnnotationMirror getAnnotationMirror​(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)  
      static com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror> getAnnotationsAnnotatedWith​(javax.lang.model.element.Element element, com.squareup.javapoet.ClassName subAnnotation)
      Returns annotations of element that are annotated with subAnnotation
      static com.google.common.collect.ImmutableMap<java.lang.String,​javax.lang.model.element.AnnotationValue> getAnnotationValues​(javax.lang.model.util.Elements elements, javax.lang.model.element.AnnotationMirror annotation)
      Returns a map from AnnotationMirror attribute name to AnnotationValues
      static java.lang.Boolean getBooleanAnnotationValue​(javax.lang.model.element.AnnotationValue value)
      Gets the values from an annotation value representing an int.
      static com.google.common.collect.ImmutableList<javax.lang.model.element.ExecutableElement> getConstructors​(javax.lang.model.element.TypeElement element)  
      static javax.lang.model.type.DeclaredType getDeclaredType​(javax.lang.model.type.TypeMirror type)
      Returns the declared type if the received mirror represents a declared type or an array of declared types, otherwise throws an IllegalStateException.
      static javax.lang.model.type.DeclaredType getDeclaredTypeAnnotationValue​(javax.lang.model.element.AnnotationValue value)
      Gets the values from an annotation value representing a DeclaredType.
      static com.google.common.collect.ImmutableSet<javax.lang.model.element.Element> getElementsAnnotatedWith​(javax.annotation.processing.RoundEnvironment roundEnv, java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)
      Returns all elements in the round that are annotated with at least 1 of the given annotations.
      static com.squareup.javapoet.ClassName getEnclosedClassName​(com.squareup.javapoet.ClassName className)
      Returns an equivalent class name with the . (dots) used for inner classes replaced with _.
      static com.squareup.javapoet.ClassName getEnclosedClassName​(javax.lang.model.element.TypeElement typeElement)
      Returns an equivalent class name with the . (dots) used for inner classes replaced with _.
      static java.lang.String getEnclosedName​(com.squareup.javapoet.ClassName name)
      Returns the name of a class, including prefixing with enclosing class names.
      static java.lang.String getEnclosedName​(javax.lang.model.element.TypeElement element)
      Returns the name of a class.
      static com.google.common.collect.ImmutableSet<javax.lang.model.element.VariableElement> getEnumArrayAnnotationValue​(javax.lang.model.element.AnnotationValue value)
      Gets the values from an annotation value representing a Enum array.
      static java.lang.String getFullEnclosedName​(javax.lang.model.element.Element element)
      Returns the fully qualified class name, with _ instead of .
      static java.lang.String getFullyQualifiedEnclosedClassName​(com.squareup.javapoet.ClassName className)
      Returns the fully qualified class name, with _ instead of .
      static java.lang.Integer getIntAnnotationValue​(javax.lang.model.element.AnnotationValue value)
      Gets the values from an annotation value representing an int.
      static java.lang.Long getLongAnnotationValue​(javax.lang.model.element.AnnotationValue value)
      Gets the values from an annotation value representing a long.
      static com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror> getMapKeyAnnotations​(javax.lang.model.element.Element element)
      Returns MapKey annotated annotations found on an element.
      static com.google.common.collect.ImmutableList<javax.lang.model.element.ExecutableElement> getMethods​(javax.lang.model.element.TypeElement element)
      Returns methods from a given TypeElement, not including constructors.
      static java.util.Optional<javax.lang.model.element.TypeElement> getOptionalAnnotationClassValue​(javax.lang.model.util.Elements elements, javax.lang.model.element.AnnotationMirror annotation, java.lang.String key)
      Returns an optional TypeElement for a class attribute on an annotation.
      static com.google.common.collect.ImmutableList<javax.lang.model.element.TypeElement> getOptionalAnnotationClassValues​(javax.lang.model.util.Elements elements, javax.lang.model.element.AnnotationMirror annotation, java.lang.String key)
      Returns a list of TypeElements for a class attribute on an annotation.
      static java.util.Optional<javax.lang.model.type.DeclaredType> getOptionalDeclaredType​(javax.lang.model.type.TypeMirror type)
      Returns an Optional.of(T) the declared type if the received mirror represents a declared type or an array of declared types, otherwise returns Optional.empty().
      static com.squareup.javapoet.AnnotationSpec getOriginatingElementAnnotation​(javax.lang.model.element.TypeElement element)  
      static java.util.Optional<javax.lang.model.element.TypeElement> getOriginatingTestElement​(javax.lang.model.element.Element element, javax.lang.model.util.Elements elements)  
      static javax.lang.model.element.PackageElement getPackageElement​(javax.lang.model.element.Element originalElement)
      Returns the given elements containing package element.
      static javax.lang.model.type.PrimitiveType getPrimitiveType​(javax.lang.model.type.TypeMirror type)
      If the received mirror represents a primitive type or an array of primitive types, this returns the represented primitive type.
      static com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror> getQualifierAnnotations​(javax.lang.model.element.Element element)
      Returns Qualifier annotated annotations found on an element.
      static com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror> getScopeAnnotations​(javax.lang.model.element.Element element)
      Returns Scope annotated annotations found on an element.
      static java.lang.String getStringAnnotationValue​(javax.lang.model.element.AnnotationValue value)
      Gets the values from an annotation value representing a string.
      static com.google.common.collect.ImmutableList<java.lang.String> getStringArrayAnnotationValue​(javax.lang.model.element.AnnotationValue value)
      Gets the values from an annotation value representing a string array.
      static javax.lang.model.element.TypeElement getTopLevelType​(javax.lang.model.element.Element originalElement)  
      static boolean hasAnnotation​(javax.lang.model.element.AnnotationMirror mirror, com.squareup.javapoet.ClassName className)
      Returns true if the given element has an annotation with the given class name.
      static boolean hasAnnotation​(javax.lang.model.element.AnnotationMirror mirror, java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
      Returns true if the given element is annotated with the given annotation.
      static boolean hasAnnotation​(javax.lang.model.element.Element element, com.squareup.javapoet.ClassName className)
      Returns true if the given element has an annotation with the given class name.
      static boolean hasAnnotation​(javax.lang.model.element.Element element, java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
      Returns true if the given element is annotated with the given annotation.
      static boolean hasAnnotationsAnnotatedWith​(javax.lang.model.element.Element element, com.squareup.javapoet.ClassName subAnnotation)
      Returns true if there are any annotations of element that are annotated with subAnnotation
      static boolean hasDaggerAbstractMethodAnnotation​(javax.lang.model.element.ExecutableElement method)
      Returns true if the given method is annotated with one of the annotations Dagger recognizes for abstract methods (e.g.
      static boolean hasErrorTypeAnnotation​(javax.lang.model.element.Element element)
      Returns true if the given element has an annotation that is an error kind.
      static boolean hasVisibleEmptyConstructor​(javax.lang.model.element.TypeElement type)  
      static boolean isAssignableFrom​(javax.lang.model.element.TypeElement element, com.squareup.javapoet.ClassName className)  
      static boolean isAssignableFromAnyOf​(javax.lang.model.element.TypeElement element, com.google.common.collect.ImmutableSet<com.squareup.javapoet.ClassName> classNames)  
      static boolean isObjectMethod​(javax.lang.model.element.ExecutableElement method)
      Returns true iff the given method is one of the public or protected methods on Object, or an overridden version thereof.
      static boolean isTopLevel​(javax.lang.model.element.Element element)
      Returns true if the given element is a top-level element.
      static com.google.common.collect.ImmutableList<javax.lang.model.element.ExecutableElement> methodsOnInterfaces​(javax.lang.model.element.TypeElement type)
      Finds methods of interfaces implemented by type.
      static com.squareup.javapoet.ParameterSpec parameterSpecFromVariableElement​(javax.lang.model.element.VariableElement element)  
      static com.squareup.javapoet.ClassName prepend​(com.squareup.javapoet.ClassName name, java.lang.String prefix)
      Prepends the given string to the beginning of the class name.
      static com.squareup.javapoet.MethodSpec privateEmptyConstructor()  
      static com.squareup.javapoet.TypeName rawTypeName​(com.squareup.javapoet.TypeName typeName)
      Returns the TypeName for the raw type of the given type name.
      static com.squareup.javapoet.ClassName removeNameSuffix​(javax.lang.model.element.TypeElement type, java.lang.String suffix)
      Removes the string suffix from the simple name of type and returns it.
      static boolean requiresModuleInstance​(javax.lang.model.util.Elements elements, javax.lang.model.element.TypeElement module)  
      static com.google.common.collect.ImmutableSet<com.squareup.javapoet.ClassName> toClassNames​(java.lang.Iterable<javax.lang.model.element.TypeElement> elements)  
      static com.google.common.collect.ImmutableSet<javax.lang.model.element.TypeElement> toTypeElements​(javax.lang.model.util.Elements elements, java.lang.String[] classes)  
      static java.lang.String upperToLowerCamel​(java.lang.String upperCamel)
      Shortcut for converting from upper camel to lower camel case
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • CONSTRUCTOR_NAME

        public static final java.lang.String CONSTRUCTOR_NAME
        See Also:
        Constant Field Values
      • STATIC_INITIALIZER_NAME

        public static final java.lang.String STATIC_INITIALIZER_NAME
        See Also:
        Constant Field Values
    • Method Detail

      • generateAggregatingClass

        public static void generateAggregatingClass​(java.lang.String aggregatingPackage,
                                                    com.squareup.javapoet.AnnotationSpec aggregatingAnnotation,
                                                    javax.lang.model.element.TypeElement element,
                                                    java.lang.Class<?> generatedAnnotationClass,
                                                    javax.annotation.processing.ProcessingEnvironment env)
                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • getAnnotationValues

        public static com.google.common.collect.ImmutableMap<java.lang.String,​javax.lang.model.element.AnnotationValue> getAnnotationValues​(javax.lang.model.util.Elements elements,
                                                                                                                                                  javax.lang.model.element.AnnotationMirror annotation)
        Returns a map from AnnotationMirror attribute name to AnnotationValues
      • getAnnotationAnnotationArrayValues

        public static com.google.common.collect.Multimap<java.lang.String,​javax.lang.model.element.AnnotationMirror> getAnnotationAnnotationArrayValues​(javax.lang.model.util.Elements elements,
                                                                                                                                                              javax.lang.model.element.AnnotationMirror annotation)
        Returns a multimap from attribute name to the values that are an array of annotation mirrors. The returned map will not contain mappings for any attributes that are not Annotation Arrays.

        e.g. if the input was the annotation mirror for

           @Foo({@Bar("hello"), @Bar("world")})
         
        the map returned would have "value" map to a set containing the two @Bar annotation mirrors.
      • getAnnotationClassValue

        public static javax.lang.model.element.TypeElement getAnnotationClassValue​(javax.lang.model.util.Elements elements,
                                                                                   javax.lang.model.element.AnnotationMirror annotation,
                                                                                   java.lang.String key)
        Returns the TypeElement for a class attribute on an annotation.
      • getAnnotationClassValues

        public static com.google.common.collect.ImmutableList<javax.lang.model.element.TypeElement> getAnnotationClassValues​(javax.lang.model.util.Elements elements,
                                                                                                                             javax.lang.model.element.AnnotationMirror annotation,
                                                                                                                             java.lang.String key)
        Returns a list of TypeElements for a class attribute on an annotation.
      • getOptionalAnnotationClassValue

        public static java.util.Optional<javax.lang.model.element.TypeElement> getOptionalAnnotationClassValue​(javax.lang.model.util.Elements elements,
                                                                                                               javax.lang.model.element.AnnotationMirror annotation,
                                                                                                               java.lang.String key)
        Returns an optional TypeElement for a class attribute on an annotation.
      • getOptionalAnnotationClassValues

        public static com.google.common.collect.ImmutableList<javax.lang.model.element.TypeElement> getOptionalAnnotationClassValues​(javax.lang.model.util.Elements elements,
                                                                                                                                     javax.lang.model.element.AnnotationMirror annotation,
                                                                                                                                     java.lang.String key)
        Returns a list of TypeElements for a class attribute on an annotation.
      • getPrimitiveType

        public static javax.lang.model.type.PrimitiveType getPrimitiveType​(javax.lang.model.type.TypeMirror type)
        If the received mirror represents a primitive type or an array of primitive types, this returns the represented primitive type. Otherwise throws an IllegalStateException.
      • getOptionalDeclaredType

        public static java.util.Optional<javax.lang.model.type.DeclaredType> getOptionalDeclaredType​(javax.lang.model.type.TypeMirror type)
        Returns an Optional.of(T) the declared type if the received mirror represents a declared type or an array of declared types, otherwise returns Optional.empty().
      • getDeclaredType

        public static javax.lang.model.type.DeclaredType getDeclaredType​(javax.lang.model.type.TypeMirror type)
        Returns the declared type if the received mirror represents a declared type or an array of declared types, otherwise throws an IllegalStateException.
      • getStringArrayAnnotationValue

        public static com.google.common.collect.ImmutableList<java.lang.String> getStringArrayAnnotationValue​(javax.lang.model.element.AnnotationValue value)
        Gets the values from an annotation value representing a string array.
      • getBooleanAnnotationValue

        public static java.lang.Boolean getBooleanAnnotationValue​(javax.lang.model.element.AnnotationValue value)
        Gets the values from an annotation value representing an int.
      • getIntAnnotationValue

        public static java.lang.Integer getIntAnnotationValue​(javax.lang.model.element.AnnotationValue value)
        Gets the values from an annotation value representing an int.
      • getLongAnnotationValue

        public static java.lang.Long getLongAnnotationValue​(javax.lang.model.element.AnnotationValue value)
        Gets the values from an annotation value representing a long.
      • getStringAnnotationValue

        public static java.lang.String getStringAnnotationValue​(javax.lang.model.element.AnnotationValue value)
        Gets the values from an annotation value representing a string.
      • getDeclaredTypeAnnotationValue

        public static javax.lang.model.type.DeclaredType getDeclaredTypeAnnotationValue​(javax.lang.model.element.AnnotationValue value)
        Gets the values from an annotation value representing a DeclaredType.
      • getEnumArrayAnnotationValue

        public static com.google.common.collect.ImmutableSet<javax.lang.model.element.VariableElement> getEnumArrayAnnotationValue​(javax.lang.model.element.AnnotationValue value)
        Gets the values from an annotation value representing a Enum array.
      • convertToAttributeNameMap

        public static com.google.common.collect.ImmutableMap<java.lang.String,​javax.lang.model.element.AnnotationValue> convertToAttributeNameMap​(java.util.Map<? extends javax.lang.model.element.ExecutableElement,​? extends javax.lang.model.element.AnnotationValue> annotationValues)
        Converts an annotation value map to be keyed by the attribute name.
      • getPackageElement

        public static javax.lang.model.element.PackageElement getPackageElement​(javax.lang.model.element.Element originalElement)
        Returns the given elements containing package element.
      • getTopLevelType

        public static javax.lang.model.element.TypeElement getTopLevelType​(javax.lang.model.element.Element originalElement)
      • isTopLevel

        public static boolean isTopLevel​(javax.lang.model.element.Element element)
        Returns true if the given element is a top-level element.
      • hasAnnotation

        public static boolean hasAnnotation​(javax.lang.model.element.Element element,
                                            java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
        Returns true if the given element is annotated with the given annotation.
      • hasAnnotation

        public static boolean hasAnnotation​(javax.lang.model.element.Element element,
                                            com.squareup.javapoet.ClassName className)
        Returns true if the given element has an annotation with the given class name.
      • hasAnnotation

        public static boolean hasAnnotation​(javax.lang.model.element.AnnotationMirror mirror,
                                            com.squareup.javapoet.ClassName className)
        Returns true if the given element has an annotation with the given class name.
      • hasAnnotation

        public static boolean hasAnnotation​(javax.lang.model.element.AnnotationMirror mirror,
                                            java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
        Returns true if the given element is annotated with the given annotation.
      • hasErrorTypeAnnotation

        public static boolean hasErrorTypeAnnotation​(javax.lang.model.element.Element element)
        Returns true if the given element has an annotation that is an error kind.
      • getElementsAnnotatedWith

        @SafeVarargs
        public static com.google.common.collect.ImmutableSet<javax.lang.model.element.Element> getElementsAnnotatedWith​(javax.annotation.processing.RoundEnvironment roundEnv,
                                                                                                                        java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)
        Returns all elements in the round that are annotated with at least 1 of the given annotations.
      • getEnclosedName

        public static java.lang.String getEnclosedName​(com.squareup.javapoet.ClassName name)
        Returns the name of a class, including prefixing with enclosing class names. i.e. for inner class Foo enclosed by Bar, returns Bar_Foo instead of just Foo
      • getEnclosedName

        public static java.lang.String getEnclosedName​(javax.lang.model.element.TypeElement element)
        Returns the name of a class. See getEnclosedName(ClassName).
      • getEnclosedClassName

        public static com.squareup.javapoet.ClassName getEnclosedClassName​(com.squareup.javapoet.ClassName className)
        Returns an equivalent class name with the . (dots) used for inner classes replaced with _.
      • getEnclosedClassName

        public static com.squareup.javapoet.ClassName getEnclosedClassName​(javax.lang.model.element.TypeElement typeElement)
        Returns an equivalent class name with the . (dots) used for inner classes replaced with _.
      • getFullyQualifiedEnclosedClassName

        public static java.lang.String getFullyQualifiedEnclosedClassName​(com.squareup.javapoet.ClassName className)
        Returns the fully qualified class name, with _ instead of .
      • getFullEnclosedName

        public static java.lang.String getFullEnclosedName​(javax.lang.model.element.Element element)
        Returns the fully qualified class name, with _ instead of . For elements that are not type elements, this continues to append the simple name of elements. For example, foo_bar_Outer_Inner_fooMethod.
      • append

        public static com.squareup.javapoet.ClassName append​(com.squareup.javapoet.ClassName name,
                                                             java.lang.String suffix)
        Appends the given string to the end of the class name.
      • prepend

        public static com.squareup.javapoet.ClassName prepend​(com.squareup.javapoet.ClassName name,
                                                              java.lang.String prefix)
        Prepends the given string to the beginning of the class name.
      • removeNameSuffix

        public static com.squareup.javapoet.ClassName removeNameSuffix​(javax.lang.model.element.TypeElement type,
                                                                       java.lang.String suffix)
        Removes the string suffix from the simple name of type and returns it.
        Throws:
        BadInputException - if the simple name of type does not end with suffix
      • getAnnotationMirror

        public static javax.lang.model.element.AnnotationMirror getAnnotationMirror​(javax.lang.model.element.Element element,
                                                                                    java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
        See Also:
        getAnnotationMirror(Element, ClassName)
      • getAnnotationMirror

        public static javax.lang.model.element.AnnotationMirror getAnnotationMirror​(javax.lang.model.element.Element element,
                                                                                    com.squareup.javapoet.ClassName className)
        Returns the annotation mirror from the given element that corresponds to the given class.
        Throws:
        java.lang.IllegalStateException - if the given element isn't annotated with that annotation.
      • isAssignableFrom

        public static boolean isAssignableFrom​(javax.lang.model.element.TypeElement element,
                                               com.squareup.javapoet.ClassName className)
        Returns:
        true if element inherits directly or indirectly from the className
      • isAssignableFromAnyOf

        public static boolean isAssignableFromAnyOf​(javax.lang.model.element.TypeElement element,
                                                    com.google.common.collect.ImmutableSet<com.squareup.javapoet.ClassName> classNames)
        Returns:
        true if element inherits directly or indirectly from any of the classNames
      • getMethods

        public static com.google.common.collect.ImmutableList<javax.lang.model.element.ExecutableElement> getMethods​(javax.lang.model.element.TypeElement element)
        Returns methods from a given TypeElement, not including constructors.
      • getConstructors

        public static com.google.common.collect.ImmutableList<javax.lang.model.element.ExecutableElement> getConstructors​(javax.lang.model.element.TypeElement element)
      • getAllMethods

        public static com.google.common.collect.ImmutableList<javax.lang.model.element.ExecutableElement> getAllMethods​(javax.lang.model.element.TypeElement element)
        Returns all transitive methods from a given TypeElement, not including constructors. Also does not include methods from Object or that override methods on Object.
      • checkForCompilationError

        public static void checkForCompilationError​(javax.lang.model.element.TypeElement e)
        Checks that the given element is not the error type.
      • methodsOnInterfaces

        public static com.google.common.collect.ImmutableList<javax.lang.model.element.ExecutableElement> methodsOnInterfaces​(javax.lang.model.element.TypeElement type)
        Finds methods of interfaces implemented by type. This method also checks the superinterfaces of those interfaces. This method does not check the interfaces of any superclass of type.
      • getMapKeyAnnotations

        public static com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror> getMapKeyAnnotations​(javax.lang.model.element.Element element)
        Returns MapKey annotated annotations found on an element.
      • getQualifierAnnotations

        public static com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror> getQualifierAnnotations​(javax.lang.model.element.Element element)
        Returns Qualifier annotated annotations found on an element.
      • getScopeAnnotations

        public static com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror> getScopeAnnotations​(javax.lang.model.element.Element element)
        Returns Scope annotated annotations found on an element.
      • getAnnotationsAnnotatedWith

        public static com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror> getAnnotationsAnnotatedWith​(javax.lang.model.element.Element element,
                                                                                                                                     com.squareup.javapoet.ClassName subAnnotation)
        Returns annotations of element that are annotated with subAnnotation
      • hasAnnotationsAnnotatedWith

        public static boolean hasAnnotationsAnnotatedWith​(javax.lang.model.element.Element element,
                                                          com.squareup.javapoet.ClassName subAnnotation)
        Returns true if there are any annotations of element that are annotated with subAnnotation
      • isObjectMethod

        public static boolean isObjectMethod​(javax.lang.model.element.ExecutableElement method)
        Returns true iff the given method is one of the public or protected methods on Object, or an overridden version thereof.

        This method ignores the return type of the given method, but this is generally fine since two methods which only differ by their return type will cause a compiler error. (e.g. a non-static method with the signature int equals(Object))

      • parameterSpecFromVariableElement

        public static com.squareup.javapoet.ParameterSpec parameterSpecFromVariableElement​(javax.lang.model.element.VariableElement element)
      • upperToLowerCamel

        public static java.lang.String upperToLowerCamel​(java.lang.String upperCamel)
        Shortcut for converting from upper camel to lower camel case

        Example: "SomeString" => "someString"

      • copyMethodSpecWithoutBody

        public static com.squareup.javapoet.MethodSpec.Builder copyMethodSpecWithoutBody​(com.squareup.javapoet.MethodSpec methodSpec)
        Returns:
        copy of the given MethodSpec as MethodSpec.Builder with method body removed
      • privateEmptyConstructor

        public static com.squareup.javapoet.MethodSpec privateEmptyConstructor()
        Returns:
        A method spec for an empty constructor (useful for abstract Dagger modules).
      • hasDaggerAbstractMethodAnnotation

        public static boolean hasDaggerAbstractMethodAnnotation​(javax.lang.model.element.ExecutableElement method)
        Returns true if the given method is annotated with one of the annotations Dagger recognizes for abstract methods (e.g. @Binds).
      • toTypeElements

        public static com.google.common.collect.ImmutableSet<javax.lang.model.element.TypeElement> toTypeElements​(javax.lang.model.util.Elements elements,
                                                                                                                  java.lang.String[] classes)
      • toClassNames

        public static com.google.common.collect.ImmutableSet<com.squareup.javapoet.ClassName> toClassNames​(java.lang.Iterable<javax.lang.model.element.TypeElement> elements)
      • requiresModuleInstance

        public static boolean requiresModuleInstance​(javax.lang.model.util.Elements elements,
                                                     javax.lang.model.element.TypeElement module)
      • hasVisibleEmptyConstructor

        public static boolean hasVisibleEmptyConstructor​(javax.lang.model.element.TypeElement type)
      • addGeneratedAnnotation

        public static void addGeneratedAnnotation​(com.squareup.javapoet.TypeSpec.Builder typeSpecBuilder,
                                                  javax.annotation.processing.ProcessingEnvironment env,
                                                  java.lang.Class<?> generatorClass)
      • addGeneratedAnnotation

        public static void addGeneratedAnnotation​(com.squareup.javapoet.TypeSpec.Builder typeSpecBuilder,
                                                  javax.annotation.processing.ProcessingEnvironment env,
                                                  java.lang.String generatorClass)
      • getOriginatingElementAnnotation

        public static com.squareup.javapoet.AnnotationSpec getOriginatingElementAnnotation​(javax.lang.model.element.TypeElement element)
      • rawTypeName

        public static com.squareup.javapoet.TypeName rawTypeName​(com.squareup.javapoet.TypeName typeName)
        Returns the TypeName for the raw type of the given type name. If the argument isn't a parameterized type, it returns the argument unchanged.
      • getOriginatingTestElement

        public static java.util.Optional<javax.lang.model.element.TypeElement> getOriginatingTestElement​(javax.lang.model.element.Element element,
                                                                                                         javax.lang.model.util.Elements elements)