public final class Processors
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
CONSTRUCTOR_NAME |
static java.lang.String |
STATIC_INITIALIZER_NAME |
| Modifier and Type | Method and 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 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,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass) |
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.String annotationClassName) |
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 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 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,
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.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.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 |
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 |
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 |
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
|
public static final java.lang.String CONSTRUCTOR_NAME
public static final java.lang.String STATIC_INITIALIZER_NAME
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)
AnnotationMirror attribute name to AnnotationValuespublic 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)
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.public static javax.lang.model.element.TypeElement getAnnotationClassValue(javax.lang.model.util.Elements elements,
javax.lang.model.element.AnnotationMirror annotation,
java.lang.String key)
TypeElement for a class attribute on an annotation.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)
TypeElements for a class attribute on an annotation.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)
TypeElement for a class attribute on an annotation.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)
TypeElements for a class attribute on an annotation.public static javax.lang.model.type.PrimitiveType getPrimitiveType(javax.lang.model.type.TypeMirror type)
public static java.util.Optional<javax.lang.model.type.DeclaredType> getOptionalDeclaredType(javax.lang.model.type.TypeMirror type)
Optional.of(T) the declared type if the received mirror represents a declared
type or an array of declared types, otherwise returns Optional.empty().public static javax.lang.model.type.DeclaredType getDeclaredType(javax.lang.model.type.TypeMirror type)
IllegalStateException.public static com.google.common.collect.ImmutableList<java.lang.String> getStringArrayAnnotationValue(javax.lang.model.element.AnnotationValue value)
public static java.lang.Boolean getBooleanAnnotationValue(javax.lang.model.element.AnnotationValue value)
public static java.lang.Integer getIntAnnotationValue(javax.lang.model.element.AnnotationValue value)
public static java.lang.Long getLongAnnotationValue(javax.lang.model.element.AnnotationValue value)
public static java.lang.String getStringAnnotationValue(javax.lang.model.element.AnnotationValue value)
public static javax.lang.model.type.DeclaredType getDeclaredTypeAnnotationValue(javax.lang.model.element.AnnotationValue value)
public static com.google.common.collect.ImmutableSet<javax.lang.model.element.VariableElement> getEnumArrayAnnotationValue(javax.lang.model.element.AnnotationValue value)
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)
public static javax.lang.model.element.PackageElement getPackageElement(javax.lang.model.element.Element originalElement)
public static javax.lang.model.element.TypeElement getTopLevelType(javax.lang.model.element.Element originalElement)
public static boolean isTopLevel(javax.lang.model.element.Element element)
public static boolean hasAnnotation(javax.lang.model.element.Element element,
java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
public static boolean hasAnnotation(javax.lang.model.element.Element element,
com.squareup.javapoet.ClassName className)
public static boolean hasAnnotation(javax.lang.model.element.AnnotationMirror mirror,
com.squareup.javapoet.ClassName className)
public static boolean hasAnnotation(javax.lang.model.element.AnnotationMirror mirror,
java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
public static boolean hasErrorTypeAnnotation(javax.lang.model.element.Element element)
@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)
public static java.lang.String getEnclosedName(com.squareup.javapoet.ClassName name)
public static java.lang.String getEnclosedName(javax.lang.model.element.TypeElement element)
getEnclosedName(ClassName).public static com.squareup.javapoet.ClassName getEnclosedClassName(com.squareup.javapoet.ClassName className)
. (dots) used for inner classes replaced with
_.public static java.lang.String getFullyQualifiedEnclosedClassName(com.squareup.javapoet.ClassName className)
public static java.lang.String getFullEnclosedName(javax.lang.model.element.Element element)
public static com.squareup.javapoet.ClassName append(com.squareup.javapoet.ClassName name,
java.lang.String suffix)
public static com.squareup.javapoet.ClassName prepend(com.squareup.javapoet.ClassName name,
java.lang.String prefix)
public static com.squareup.javapoet.ClassName removeNameSuffix(javax.lang.model.element.TypeElement type,
java.lang.String suffix)
suffix from the simple name of type and returns it.BadInputException - if the simple name of type does not end with suffixpublic static javax.lang.model.element.AnnotationMirror getAnnotationMirror(javax.lang.model.element.Element element,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
getAnnotationMirror(Element, ClassName)public static javax.lang.model.element.AnnotationMirror getAnnotationMirror(javax.lang.model.element.Element element,
java.lang.String annotationClassName)
getAnnotationMirror(Element, ClassName)public static javax.lang.model.element.AnnotationMirror getAnnotationMirror(javax.lang.model.element.Element element,
com.squareup.javapoet.ClassName className)
java.lang.IllegalStateException - if the given element isn't annotated with that annotation.public static boolean isAssignableFrom(javax.lang.model.element.TypeElement element,
com.squareup.javapoet.ClassName className)
public static boolean isAssignableFromAnyOf(javax.lang.model.element.TypeElement element,
com.google.common.collect.ImmutableSet<com.squareup.javapoet.ClassName> classNames)
public static com.google.common.collect.ImmutableList<javax.lang.model.element.ExecutableElement> getMethods(javax.lang.model.element.TypeElement element)
public static com.google.common.collect.ImmutableList<javax.lang.model.element.ExecutableElement> getConstructors(javax.lang.model.element.TypeElement element)
public static com.google.common.collect.ImmutableList<javax.lang.model.element.ExecutableElement> getAllMethods(javax.lang.model.element.TypeElement element)
public static void checkForCompilationError(javax.lang.model.element.TypeElement e)
public static com.google.common.collect.ImmutableList<javax.lang.model.element.ExecutableElement> methodsOnInterfaces(javax.lang.model.element.TypeElement type)
type. This method also checks the
superinterfaces of those interfaces. This method does not check the interfaces of any
superclass of type.public static com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror> getMapKeyAnnotations(javax.lang.model.element.Element element)
public static com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror> getQualifierAnnotations(javax.lang.model.element.Element element)
public static com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror> getScopeAnnotations(javax.lang.model.element.Element element)
public static com.google.common.collect.ImmutableList<javax.lang.model.element.AnnotationMirror> getAnnotationsAnnotatedWith(javax.lang.model.element.Element element,
com.squareup.javapoet.ClassName subAnnotation)
public static boolean hasAnnotationsAnnotatedWith(javax.lang.model.element.Element element,
com.squareup.javapoet.ClassName subAnnotation)
public static boolean isObjectMethod(javax.lang.model.element.ExecutableElement method)
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))
public static com.squareup.javapoet.ParameterSpec parameterSpecFromVariableElement(javax.lang.model.element.VariableElement element)
public static java.lang.String upperToLowerCamel(java.lang.String upperCamel)
Example: "SomeString" => "someString"
public static com.squareup.javapoet.MethodSpec.Builder copyMethodSpecWithoutBody(com.squareup.javapoet.MethodSpec methodSpec)
MethodSpec.Builder with method body removedpublic static com.squareup.javapoet.MethodSpec privateEmptyConstructor()
public static boolean hasDaggerAbstractMethodAnnotation(javax.lang.model.element.ExecutableElement method)
public static com.google.common.collect.ImmutableSet<javax.lang.model.element.TypeElement> toTypeElements(javax.lang.model.util.Elements elements,
java.lang.String[] classes)
public static com.google.common.collect.ImmutableSet<com.squareup.javapoet.ClassName> toClassNames(java.lang.Iterable<javax.lang.model.element.TypeElement> elements)
public static boolean requiresModuleInstance(javax.lang.model.util.Elements elements,
javax.lang.model.element.TypeElement module)
public static void addGeneratedAnnotation(com.squareup.javapoet.TypeSpec.Builder typeSpecBuilder,
javax.annotation.processing.ProcessingEnvironment env,
java.lang.Class<?> generatorClass)
public static void addGeneratedAnnotation(com.squareup.javapoet.TypeSpec.Builder typeSpecBuilder,
javax.annotation.processing.ProcessingEnvironment env,
java.lang.String generatorClass)
public static com.squareup.javapoet.AnnotationSpec getOriginatingElementAnnotation(javax.lang.model.element.TypeElement element)
public static com.squareup.javapoet.TypeName rawTypeName(com.squareup.javapoet.TypeName typeName)
TypeName for the raw type of the given type name. If the argument isn't a
parameterized type, it returns the argument unchanged.