Class ModelUtils
java.lang.Object
org.inferred.freebuilder.processor.model.ModelUtils
Utility methods for the javax.lang.model package.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final SimpleTypeVisitor8<Optional<DeclaredType>, ?> private static final SimpleElementVisitor8<Optional<TypeElement>, ?> private static final SimpleTypeVisitor8<Optional<TypeVariable>, ?> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic TypeElementasElement(DeclaredType type) Returns theTypeElementcorresponding totype.static booleanerasesToAnyOf(DeclaredType type, Class<?>... possibilities) Returns true iftypeerases to any ofpossibilities.static booleanerasesToAnyOf(DeclaredType type, QualifiedName... possibilities) Returns true iftypeerases to any ofpossibilities.static Optional<AnnotationMirror> findAnnotationMirror(Element element, Class<? extends Annotation> annotationClass) Returns anAnnotationMirrorfor the annotation of typeannotationClassonelement, orOptional.empty()if no such annotation exists.static Optional<AnnotationMirror> findAnnotationMirror(Element element, String annotationClassName) Returns anAnnotationMirrorfor the annotation of typeannotationClassNameonelement, orOptional.empty()if no such annotation exists.static Optional<AnnotationMirror> findAnnotationMirror(Element element, QualifiedName annotationClass) Returns anAnnotationMirrorfor the annotation of typeannotationClassonelement, orOptional.empty()if no such annotation exists.static Optional<AnnotationValue> findProperty(AnnotationMirror annotation, String propertyName) static TypeMirrorgetReturnType(TypeElement type, ExecutableElement method, Types types) Determines the return type ofmethod, if called on an instance of typetype.static TypeMirrorgetReturnType(DeclaredType type, ExecutableElement method, Types types) Determines the return type ofmethod, if called on an instance of typetype.private static booleanisPlainWildcard(TypeMirror type) static Optional<TypeElement> maybeAsTypeElement(TypeMirror type) Returns theTypeElementcorresponding totype, if there is one.static Optional<DeclaredType> maybeDeclared(TypeMirror type) Returnstypeas aDeclaredType, if it is one.static Optional<TypeElement> Returnselementas aTypeElement, if it is one.static Optional<TypeMirror> maybeUnbox(TypeMirror mirror, Types types) Applies unboxing conversion tomirror, if it can be unboxed.static Optional<TypeVariable> maybeVariable(TypeMirror type) static booleanneedsSafeVarargs(TypeMirror elementType) Returns true if a method with a variable number ofelementTypearguments needs a@SafeVarargsannotation to avoid compiler warnings in Java 7+.static Set<ExecutableElement> only(Modifier modifier, Set<ExecutableElement> methods) static Optional<ExecutableElement> override(TypeElement type, Types types, String methodName, TypeMirror... params) Returns the method ontypethat overrides methodmethodName(params).static Optional<ExecutableElement> override(DeclaredType type, Types types, String methodName, TypeMirror... params) Returns the method ontypethat overrides methodmethodName(params).static booleanoverrides(TypeElement type, Types types, String methodName, TypeMirror... params) Returns whethertypeoverrides methodmethodName(params).static booleanoverrides(DeclaredType type, Types types, String methodName, TypeMirror... params) Returns whethertypeoverrides methodmethodName(params).private static booleansignatureMatches(ExecutableElement method, Types types, String name, TypeMirror... params) static TypeMirrorupperBound(Elements elements, TypeMirror type) Returns the upper bound oftype. T -> T ? -> Object ? extends T -> T ? super T -> Object
-
Field Details
-
TYPE_ELEMENT_VISITOR
-
DECLARED_TYPE_VISITOR
-
TYPE_VARIABLE_VISITOR
-
-
Constructor Details
-
ModelUtils
public ModelUtils()
-
-
Method Details
-
findAnnotationMirror
public static Optional<AnnotationMirror> findAnnotationMirror(Element element, Class<? extends Annotation> annotationClass) Returns anAnnotationMirrorfor the annotation of typeannotationClassonelement, orOptional.empty()if no such annotation exists. -
findAnnotationMirror
public static Optional<AnnotationMirror> findAnnotationMirror(Element element, QualifiedName annotationClass) Returns anAnnotationMirrorfor the annotation of typeannotationClassonelement, orOptional.empty()if no such annotation exists. -
findAnnotationMirror
public static Optional<AnnotationMirror> findAnnotationMirror(Element element, String annotationClassName) Returns anAnnotationMirrorfor the annotation of typeannotationClassNameonelement, orOptional.empty()if no such annotation exists. -
findProperty
public static Optional<AnnotationValue> findProperty(AnnotationMirror annotation, String propertyName) -
maybeType
Returnselementas aTypeElement, if it is one. -
maybeDeclared
Returnstypeas aDeclaredType, if it is one. -
maybeVariable
-
maybeAsTypeElement
Returns theTypeElementcorresponding totype, if there is one. -
asElement
Returns theTypeElementcorresponding totype. -
maybeUnbox
Applies unboxing conversion tomirror, if it can be unboxed. -
override
public static Optional<ExecutableElement> override(TypeElement type, Types types, String methodName, TypeMirror... params) Returns the method ontypethat overrides methodmethodName(params). -
override
public static Optional<ExecutableElement> override(DeclaredType type, Types types, String methodName, TypeMirror... params) Returns the method ontypethat overrides methodmethodName(params). -
overrides
public static boolean overrides(TypeElement type, Types types, String methodName, TypeMirror... params) Returns whethertypeoverrides methodmethodName(params). -
overrides
public static boolean overrides(DeclaredType type, Types types, String methodName, TypeMirror... params) Returns whethertypeoverrides methodmethodName(params). -
needsSafeVarargs
Returns true if a method with a variable number ofelementTypearguments needs a@SafeVarargsannotation to avoid compiler warnings in Java 7+. -
only
-
isPlainWildcard
-
signatureMatches
private static boolean signatureMatches(ExecutableElement method, Types types, String name, TypeMirror... params) -
getReturnType
Determines the return type ofmethod, if called on an instance of typetype.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.)
-
getReturnType
Determines the return type ofmethod, if called on an instance of typetype.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.)
-
upperBound
Returns the upper bound oftype.- T -> T
- ? -> Object
- ? extends T -> T
- ? super T -> Object
-
erasesToAnyOf
Returns true iftypeerases to any ofpossibilities. -
erasesToAnyOf
Returns true iftypeerases to any ofpossibilities.
-