public class ModelUtils
extends java.lang.Object
| Constructor and Description |
|---|
ModelUtils() |
| Modifier and Type | Method and Description |
|---|---|
static javax.lang.model.element.TypeElement |
asElement(javax.lang.model.type.DeclaredType type)
Returns the
TypeElement corresponding to type. |
static boolean |
erasesToAnyOf(javax.lang.model.type.DeclaredType type,
java.lang.Class<?>... possibilities)
Returns true if
type erases to any of possibilities. |
static boolean |
erasesToAnyOf(javax.lang.model.type.DeclaredType type,
QualifiedName... possibilities)
Returns true if
type erases to any of possibilities. |
static java.util.Optional<javax.lang.model.element.AnnotationMirror> |
findAnnotationMirror(javax.lang.model.element.Element element,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Returns an
AnnotationMirror for the annotation of type annotationClass on
element, or Optional.empty() if no such annotation exists. |
static java.util.Optional<javax.lang.model.element.AnnotationMirror> |
findAnnotationMirror(javax.lang.model.element.Element element,
QualifiedName annotationClass)
Returns an
AnnotationMirror for the annotation of type annotationClass on
element, or Optional.empty() if no such annotation exists. |
static java.util.Optional<javax.lang.model.element.AnnotationMirror> |
findAnnotationMirror(javax.lang.model.element.Element element,
java.lang.String annotationClassName)
Returns an
AnnotationMirror for the annotation of type annotationClassName on
element, or Optional.empty() if no such annotation exists. |
static java.util.Optional<javax.lang.model.element.AnnotationValue> |
findProperty(javax.lang.model.element.AnnotationMirror annotation,
java.lang.String propertyName) |
static javax.lang.model.type.TypeMirror |
getReturnType(javax.lang.model.type.DeclaredType type,
javax.lang.model.element.ExecutableElement method,
javax.lang.model.util.Types types)
Determines the return type of
method, if called on an instance of type type. |
static javax.lang.model.type.TypeMirror |
getReturnType(javax.lang.model.element.TypeElement type,
javax.lang.model.element.ExecutableElement method,
javax.lang.model.util.Types types)
Determines the return type of
method, if called on an instance of type type. |
static java.util.Optional<javax.lang.model.element.TypeElement> |
maybeAsTypeElement(javax.lang.model.type.TypeMirror type)
Returns the
TypeElement corresponding to type, if there is one. |
static java.util.Optional<javax.lang.model.type.DeclaredType> |
maybeDeclared(javax.lang.model.type.TypeMirror type)
Returns
type as a DeclaredType, if it is one. |
static java.util.Optional<javax.lang.model.element.TypeElement> |
maybeType(javax.lang.model.element.Element element)
Returns
element as a TypeElement, if it is one. |
static java.util.Optional<javax.lang.model.type.TypeMirror> |
maybeUnbox(javax.lang.model.type.TypeMirror mirror,
javax.lang.model.util.Types types)
Applies unboxing conversion to
mirror, if it can be unboxed. |
static java.util.Optional<javax.lang.model.type.TypeVariable> |
maybeVariable(javax.lang.model.type.TypeMirror type) |
static boolean |
needsSafeVarargs(javax.lang.model.type.TypeMirror elementType)
Returns true if a method with a variable number of
elementType arguments needs a
@SafeVarargs annotation to avoid compiler warnings in Java 7+. |
static java.util.Set<javax.lang.model.element.ExecutableElement> |
only(javax.lang.model.element.Modifier modifier,
java.util.Set<javax.lang.model.element.ExecutableElement> methods) |
static java.util.Optional<javax.lang.model.element.ExecutableElement> |
override(javax.lang.model.type.DeclaredType type,
javax.lang.model.util.Types types,
java.lang.String methodName,
javax.lang.model.type.TypeMirror... params)
Returns the method on
type that overrides method methodName(params). |
static java.util.Optional<javax.lang.model.element.ExecutableElement> |
override(javax.lang.model.element.TypeElement type,
javax.lang.model.util.Types types,
java.lang.String methodName,
javax.lang.model.type.TypeMirror... params)
Returns the method on
type that overrides method methodName(params). |
static boolean |
overrides(javax.lang.model.type.DeclaredType type,
javax.lang.model.util.Types types,
java.lang.String methodName,
javax.lang.model.type.TypeMirror... params)
Returns whether
type overrides method methodName(params). |
static boolean |
overrides(javax.lang.model.element.TypeElement type,
javax.lang.model.util.Types types,
java.lang.String methodName,
javax.lang.model.type.TypeMirror... params)
Returns whether
type overrides method methodName(params). |
static javax.lang.model.type.TypeMirror |
upperBound(javax.lang.model.util.Elements elements,
javax.lang.model.type.TypeMirror type)
Returns the upper bound of
type.
T -> T
? -> Object
? extends T -> T
? super T -> Object
|
public static java.util.Optional<javax.lang.model.element.AnnotationMirror> findAnnotationMirror(javax.lang.model.element.Element element,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
AnnotationMirror for the annotation of type annotationClass on
element, or Optional.empty() if no such annotation exists.public static java.util.Optional<javax.lang.model.element.AnnotationMirror> findAnnotationMirror(javax.lang.model.element.Element element,
QualifiedName annotationClass)
AnnotationMirror for the annotation of type annotationClass on
element, or Optional.empty() if no such annotation exists.public static java.util.Optional<javax.lang.model.element.AnnotationMirror> findAnnotationMirror(javax.lang.model.element.Element element,
java.lang.String annotationClassName)
AnnotationMirror for the annotation of type annotationClassName on
element, or Optional.empty() if no such annotation exists.public static java.util.Optional<javax.lang.model.element.AnnotationValue> findProperty(javax.lang.model.element.AnnotationMirror annotation,
java.lang.String propertyName)
public static java.util.Optional<javax.lang.model.element.TypeElement> maybeType(javax.lang.model.element.Element element)
element as a TypeElement, if it is one.public static java.util.Optional<javax.lang.model.type.DeclaredType> maybeDeclared(javax.lang.model.type.TypeMirror type)
type as a DeclaredType, if it is one.public static java.util.Optional<javax.lang.model.type.TypeVariable> maybeVariable(javax.lang.model.type.TypeMirror type)
public static java.util.Optional<javax.lang.model.element.TypeElement> maybeAsTypeElement(javax.lang.model.type.TypeMirror type)
TypeElement corresponding to type, if there is one.public static javax.lang.model.element.TypeElement asElement(javax.lang.model.type.DeclaredType type)
TypeElement corresponding to type.public static java.util.Optional<javax.lang.model.type.TypeMirror> maybeUnbox(javax.lang.model.type.TypeMirror mirror,
javax.lang.model.util.Types types)
mirror, if it can be unboxed.public static java.util.Optional<javax.lang.model.element.ExecutableElement> override(javax.lang.model.element.TypeElement type,
javax.lang.model.util.Types types,
java.lang.String methodName,
javax.lang.model.type.TypeMirror... params)
type that overrides method methodName(params).public static java.util.Optional<javax.lang.model.element.ExecutableElement> override(javax.lang.model.type.DeclaredType type,
javax.lang.model.util.Types types,
java.lang.String methodName,
javax.lang.model.type.TypeMirror... params)
type that overrides method methodName(params).public static boolean overrides(javax.lang.model.element.TypeElement type,
javax.lang.model.util.Types types,
java.lang.String methodName,
javax.lang.model.type.TypeMirror... params)
type overrides method methodName(params).public static boolean overrides(javax.lang.model.type.DeclaredType type,
javax.lang.model.util.Types types,
java.lang.String methodName,
javax.lang.model.type.TypeMirror... params)
type overrides method methodName(params).public static boolean needsSafeVarargs(javax.lang.model.type.TypeMirror elementType)
elementType arguments needs a
@SafeVarargs annotation to avoid compiler warnings in Java 7+.public static java.util.Set<javax.lang.model.element.ExecutableElement> only(javax.lang.model.element.Modifier modifier,
java.util.Set<javax.lang.model.element.ExecutableElement> methods)
public static javax.lang.model.type.TypeMirror getReturnType(javax.lang.model.element.TypeElement type,
javax.lang.model.element.ExecutableElement method,
javax.lang.model.util.Types types)
method, if called on an instance of type type.
For instance, in this example, myY.getProperty() returns List<T>, not T:
interface X<T> {
T getProperty();
}
@FreeBuilder interface Y<T> extends X<List<T>> { }
(Unfortunately, a bug in Eclipse prevents us handling these cases correctly at the moment. javac works fine.)
public static javax.lang.model.type.TypeMirror getReturnType(javax.lang.model.type.DeclaredType type,
javax.lang.model.element.ExecutableElement method,
javax.lang.model.util.Types types)
method, if called on an instance of type type.
For instance, in this example, myY.getProperty() returns List<T>, not T:
interface X<T> {
T getProperty();
}
@FreeBuilder interface Y<T> extends X<List<T>> { }
(Unfortunately, a bug in Eclipse prevents us handling these cases correctly at the moment. javac works fine.)
public static javax.lang.model.type.TypeMirror upperBound(javax.lang.model.util.Elements elements,
javax.lang.model.type.TypeMirror type)
type.public static boolean erasesToAnyOf(javax.lang.model.type.DeclaredType type,
QualifiedName... possibilities)
type erases to any of possibilities.public static boolean erasesToAnyOf(javax.lang.model.type.DeclaredType type,
java.lang.Class<?>... possibilities)
type erases to any of possibilities.