Package dagger.hilt.processor.internal
Class Processors
- java.lang.Object
-
- dagger.hilt.processor.internal.Processors
-
public final class Processors extends java.lang.Object
Static helper methods for writing a processor.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CONSTRUCTOR_NAME
static java.lang.String
STATIC_INITIALIZER_NAME
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addGeneratedAnnotation(com.squareup.javapoet.TypeSpec.Builder typeSpecBuilder, androidx.room.compiler.processing.XProcessingEnv env, java.lang.Class<?> generatorClass)
static void
addGeneratedAnnotation(com.squareup.javapoet.TypeSpec.Builder typeSpecBuilder, androidx.room.compiler.processing.XProcessingEnv 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 com.squareup.javapoet.MethodSpec.Builder
copyMethodSpecWithoutBody(com.squareup.javapoet.MethodSpec methodSpec)
static void
generateAggregatingClass(java.lang.String aggregatingPackage, com.squareup.javapoet.AnnotationSpec aggregatingAnnotation, androidx.room.compiler.processing.XTypeElement originatingElement, java.lang.Class<?> generatorClass)
Generates the aggregating metadata class for an aggregating annotation.static void
generateAggregatingClass(java.lang.String aggregatingPackage, com.squareup.javapoet.AnnotationSpec aggregatingAnnotation, androidx.room.compiler.processing.XTypeElement originatingElement, java.lang.Class<?> generatorClass, androidx.room.compiler.processing.XFiler.Mode mode)
Generates the aggregating metadata class for an aggregating annotation.static com.google.common.collect.ImmutableList<androidx.room.compiler.processing.XTypeElement>
getAnnotationClassValues(androidx.room.compiler.processing.XAnnotation annotation, java.lang.String key)
Returns a list ofXTypeElement
s for a class attribute on an annotation.static com.google.common.collect.ImmutableMap<java.lang.String,androidx.room.compiler.processing.XAnnotationValue>
getAnnotationValues(androidx.room.compiler.processing.XAnnotation annotation)
Returns a map fromXAnnotation
attribute name toXAnnotationValue
sstatic com.squareup.javapoet.ClassName
getEnclosedClassName(androidx.room.compiler.processing.XTypeElement typeElement)
Returns an equivalent class name with the.
(dots) used for inner classes replaced with_
.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 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
getFullEnclosedName(androidx.room.compiler.processing.XElement element)
Returns the fully qualified class name, with _ instead of .static com.google.common.collect.ImmutableList<androidx.room.compiler.processing.XAnnotation>
getMapKeyAnnotations(androidx.room.compiler.processing.XElement element)
Returns MapKey annotated annotations found on an element.static com.google.common.collect.ImmutableList<androidx.room.compiler.processing.XTypeElement>
getOptionalAnnotationClassValues(androidx.room.compiler.processing.XAnnotation annotation, java.lang.String key)
static com.squareup.javapoet.AnnotationSpec
getOriginatingElementAnnotation(androidx.room.compiler.processing.XTypeElement element)
static java.util.Optional<androidx.room.compiler.processing.XTypeElement>
getOriginatingTestElement(androidx.room.compiler.processing.XElement element)
static com.google.common.collect.ImmutableList<androidx.room.compiler.processing.XAnnotation>
getQualifierAnnotations(androidx.room.compiler.processing.XElement element)
Returns Qualifier annotated annotations found on an element.static com.google.common.collect.ImmutableList<androidx.room.compiler.processing.XAnnotation>
getScopeAnnotations(androidx.room.compiler.processing.XElement element)
Returns Scope annotated annotations found on an element.static androidx.room.compiler.processing.XTypeElement
getTopLevelType(androidx.room.compiler.processing.XElement originalElement)
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
hasDaggerAbstractMethodAnnotation(androidx.room.compiler.processing.XExecutableElement method)
Returns true if the given method is annotated with one of the annotations Dagger recognizes for abstract methods (e.g.static boolean
hasErrorTypeAnnotation(androidx.room.compiler.processing.XElement element)
Returns true if the given element has an annotation that is an error kind.static boolean
hasJavaPackagePrivateVisibility(androidx.room.compiler.processing.XHasModifiers element)
static boolean
hasVisibleEmptyConstructor(androidx.room.compiler.processing.XTypeElement type)
static boolean
isAssignableFrom(androidx.room.compiler.processing.XTypeElement element, com.squareup.javapoet.ClassName className)
Returnstrue
if element inherits directly or indirectly from the className.static boolean
isAssignableFromAnyOf(androidx.room.compiler.processing.XTypeElement element, com.google.common.collect.ImmutableSet<com.squareup.javapoet.ClassName> classNames)
Returnstrue
if element inherits directly or indirectly from any of the classNames.static boolean
isTopLevel(androidx.room.compiler.processing.XElement 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.TypeName
rawTypeName(com.squareup.javapoet.TypeName typeName)
Returns theTypeName
for the raw type of the given type name.static com.squareup.javapoet.ClassName
removeNameSuffix(androidx.room.compiler.processing.XTypeElement type, java.lang.String suffix)
Removes the stringsuffix
from the simple name oftype
and returns it.static boolean
requiresModuleInstance(androidx.room.compiler.processing.XTypeElement module)
static java.lang.String
upperToLowerCamel(java.lang.String upperCamel)
Shortcut for converting from upper camel to lower camel case
-
-
-
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, androidx.room.compiler.processing.XTypeElement originatingElement, java.lang.Class<?> generatorClass)
Generates the aggregating metadata class for an aggregating annotation.
-
generateAggregatingClass
public static void generateAggregatingClass(java.lang.String aggregatingPackage, com.squareup.javapoet.AnnotationSpec aggregatingAnnotation, androidx.room.compiler.processing.XTypeElement originatingElement, java.lang.Class<?> generatorClass, androidx.room.compiler.processing.XFiler.Mode mode)
Generates the aggregating metadata class for an aggregating annotation.
-
getAnnotationValues
public static com.google.common.collect.ImmutableMap<java.lang.String,androidx.room.compiler.processing.XAnnotationValue> getAnnotationValues(androidx.room.compiler.processing.XAnnotation annotation)
Returns a map fromXAnnotation
attribute name toXAnnotationValue
s
-
getAnnotationClassValues
public static com.google.common.collect.ImmutableList<androidx.room.compiler.processing.XTypeElement> getAnnotationClassValues(androidx.room.compiler.processing.XAnnotation annotation, java.lang.String key)
Returns a list ofXTypeElement
s for a class attribute on an annotation.
-
getOptionalAnnotationClassValues
public static com.google.common.collect.ImmutableList<androidx.room.compiler.processing.XTypeElement> getOptionalAnnotationClassValues(androidx.room.compiler.processing.XAnnotation annotation, java.lang.String key)
-
getTopLevelType
public static androidx.room.compiler.processing.XTypeElement getTopLevelType(androidx.room.compiler.processing.XElement originalElement)
-
isTopLevel
public static boolean isTopLevel(androidx.room.compiler.processing.XElement element)
-
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.
-
hasErrorTypeAnnotation
public static boolean hasErrorTypeAnnotation(androidx.room.compiler.processing.XElement element)
Returns true if the given element has an annotation that is an error kind.
-
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
-
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(androidx.room.compiler.processing.XTypeElement typeElement)
Returns an equivalent class name with the.
(dots) used for inner classes replaced with_
.
-
getFullEnclosedName
public static java.lang.String getFullEnclosedName(androidx.room.compiler.processing.XElement 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(androidx.room.compiler.processing.XTypeElement type, java.lang.String suffix)
Removes the stringsuffix
from the simple name oftype
and returns it.- Throws:
BadInputException
- if the simple name oftype
does not end withsuffix
-
isAssignableFrom
public static boolean isAssignableFrom(androidx.room.compiler.processing.XTypeElement element, com.squareup.javapoet.ClassName className)
Returnstrue
if element inherits directly or indirectly from the className.
-
isAssignableFromAnyOf
public static boolean isAssignableFromAnyOf(androidx.room.compiler.processing.XTypeElement element, com.google.common.collect.ImmutableSet<com.squareup.javapoet.ClassName> classNames)
Returnstrue
if element inherits directly or indirectly from any of the classNames.
-
getMapKeyAnnotations
public static com.google.common.collect.ImmutableList<androidx.room.compiler.processing.XAnnotation> getMapKeyAnnotations(androidx.room.compiler.processing.XElement element)
Returns MapKey annotated annotations found on an element.
-
getQualifierAnnotations
public static com.google.common.collect.ImmutableList<androidx.room.compiler.processing.XAnnotation> getQualifierAnnotations(androidx.room.compiler.processing.XElement element)
Returns Qualifier annotated annotations found on an element.
-
getScopeAnnotations
public static com.google.common.collect.ImmutableList<androidx.room.compiler.processing.XAnnotation> getScopeAnnotations(androidx.room.compiler.processing.XElement element)
Returns Scope annotated annotations found on an element.
-
upperToLowerCamel
public static java.lang.String upperToLowerCamel(java.lang.String upperCamel)
Shortcut for converting from upper camel to lower camel caseExample: "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
-
hasDaggerAbstractMethodAnnotation
public static boolean hasDaggerAbstractMethodAnnotation(androidx.room.compiler.processing.XExecutableElement method)
Returns true if the given method is annotated with one of the annotations Dagger recognizes for abstract methods (e.g. @Binds).
-
requiresModuleInstance
public static boolean requiresModuleInstance(androidx.room.compiler.processing.XTypeElement module)
-
hasVisibleEmptyConstructor
public static boolean hasVisibleEmptyConstructor(androidx.room.compiler.processing.XTypeElement type)
-
addGeneratedAnnotation
public static void addGeneratedAnnotation(com.squareup.javapoet.TypeSpec.Builder typeSpecBuilder, androidx.room.compiler.processing.XProcessingEnv env, java.lang.Class<?> generatorClass)
-
addGeneratedAnnotation
public static void addGeneratedAnnotation(com.squareup.javapoet.TypeSpec.Builder typeSpecBuilder, androidx.room.compiler.processing.XProcessingEnv env, java.lang.String generatorClass)
-
getOriginatingElementAnnotation
public static com.squareup.javapoet.AnnotationSpec getOriginatingElementAnnotation(androidx.room.compiler.processing.XTypeElement element)
-
rawTypeName
public static com.squareup.javapoet.TypeName rawTypeName(com.squareup.javapoet.TypeName typeName)
Returns theTypeName
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<androidx.room.compiler.processing.XTypeElement> getOriginatingTestElement(androidx.room.compiler.processing.XElement element)
-
hasJavaPackagePrivateVisibility
public static boolean hasJavaPackagePrivateVisibility(androidx.room.compiler.processing.XHasModifiers element)
-
-