public class TypeUsage
extends java.lang.Object
TypeUsage
describes the information available for parameter or return types.
The class is supposed to relieve its users from all the intricacies of the Java reflection API.
Doing that it will resolve meta annotations, repeated annotations as well as annotated type parameters.
TypeUsage
provides access to:
TypeUsage
)
Within the public API TypeUsage
is used in two places:
Modifier and Type | Method and Description |
---|---|
boolean |
canBeAssignedTo(TypeUsage targetType)
Check if an instance can be assigned to another
TypeUsage instance. |
boolean |
equals(java.lang.Object obj) |
<A extends java.lang.annotation.Annotation> |
findAnnotation(java.lang.Class<A> annotationType)
Return an
Optional of the first instance of a specific annotationType
if there is one (directly or indirectly through meta-annotations). |
java.util.Optional<TypeUsage> |
findSuperType(java.lang.Class<?> typeToFind) |
static TypeUsage |
forParameter(MethodParameter parameter) |
static TypeUsage |
forType(java.lang.reflect.Type type) |
<A extends java.lang.annotation.Annotation> |
getAnnotation(java.lang.Class<A> annotationType)
Deprecated.
Use
findAnnotation(Class) instead. |
java.util.List<java.lang.annotation.Annotation> |
getAnnotations()
Return all annotations of a parameter (or an annotated type argument).
|
java.util.Optional<TypeUsage> |
getComponentType()
Return an
Optional of an array's component type - if it is an array. |
java.lang.Class<?> |
getRawType()
Return the raw type which is usually the class or interface you see in a parameters or return values
specification.
|
java.util.List<TypeUsage> |
getTypeArguments()
Return the type arguments of a generic type in the order of there appearance in a type's declaration.
|
int |
hashCode() |
boolean |
hasLowerBounds()
Return true if a type parameter has upper bounds.
|
boolean |
hasUpperBounds()
Return true if a type parameter has upper bounds.
|
<A extends java.lang.annotation.Annotation> |
isAnnotated(java.lang.Class<A> annotationType)
Return true if the current instance is annotated (directly or indirectly through meta-annotations)
with a specific
annotationType . |
boolean |
isArray()
Return true if a type is an array type.
|
boolean |
isAssignableFrom(java.lang.Class<?> providedClass)
Check if a given
providedClass is assignable from this generic type. |
boolean |
isEnum()
Return true if a type is an
enum type. |
boolean |
isGeneric()
Return true if a type has any type arguments itself.
|
boolean |
isOfType(java.lang.Class<?> aRawType)
Check if an instance is of a specific raw type
Most of the time this is what you want to do when checking for applicability of a
ArbitraryProvider.
|
boolean |
isTypeVariable()
Return true if a generic type is a wildcard.
|
boolean |
isTypeVariableOrWildcard()
Return true if a generic type is a type variable or a wildcard.
|
boolean |
isWildcard()
Return true if a generic type is a wildcard.
|
static TypeUsage |
of(java.lang.Class<?> type,
TypeUsage... typeParameters) |
java.lang.String |
toString() |
java.lang.String |
toString(java.util.Set<TypeUsage> touchedTypes) |
static TypeUsage |
wildcard(TypeUsage upperBound) |
public static TypeUsage forParameter(MethodParameter parameter)
public static TypeUsage forType(java.lang.reflect.Type type)
public java.lang.Class<?> getRawType()
A raw type always exists.
public boolean hasUpperBounds()
public boolean hasLowerBounds()
public boolean isWildcard()
public boolean isTypeVariable()
public boolean isTypeVariableOrWildcard()
public java.util.List<TypeUsage> getTypeArguments()
public boolean isOfType(java.lang.Class<?> aRawType)
Most of the time this is what you want to do when checking for applicability of a ArbitraryProvider.
public boolean canBeAssignedTo(TypeUsage targetType)
TypeUsage
instance.public boolean isGeneric()
public boolean isEnum()
enum
type.public boolean isArray()
public java.util.List<java.lang.annotation.Annotation> getAnnotations()
This list already contains all meta annotations, repeated annotations and annotations from annotated type arguments. Thus, it does much more than the usual Java reflection API.
@Deprecated public <A extends java.lang.annotation.Annotation> java.util.Optional<A> getAnnotation(java.lang.Class<A> annotationType)
findAnnotation(Class)
instead.Optional
of the first instance of a specific annotationType
if there is one.public <A extends java.lang.annotation.Annotation> java.util.Optional<A> findAnnotation(java.lang.Class<A> annotationType)
Optional
of the first instance of a specific annotationType
if there is one (directly or indirectly through meta-annotations).public <A extends java.lang.annotation.Annotation> boolean isAnnotated(java.lang.Class<A> annotationType)
annotationType
.public boolean isAssignableFrom(java.lang.Class<?> providedClass)
providedClass
is assignable from this generic type.public java.util.Optional<TypeUsage> getComponentType()
Optional
of an array's component type - if it is an array.public java.util.Optional<TypeUsage> findSuperType(java.lang.Class<?> typeToFind)
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(java.util.Set<TypeUsage> touchedTypes)