@API(status=MAINTAINED,
since="1.0")
public interface TypeUsage
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 | Interface and Description |
---|---|
static interface |
TypeUsage.Enhancer
Enhancers can manipulate the perceived type of parameters.
|
static class |
TypeUsage.TypeUsageFacade |
Modifier and Type | Field and Description |
---|---|
static TypeUsage |
OBJECT_TYPE |
Modifier and Type | Method and Description |
---|---|
TypeUsage |
asNotNullable()
Return type usage object with just nullablity set to false
|
TypeUsage |
asNullable()
Return type usage object with just nullablity set to true
|
boolean |
canBeAssignedTo(TypeUsage targetType)
Check if an instance can be assigned to another
TypeUsage instance. |
<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). |
static TypeUsage |
forType(java.lang.reflect.Type type) |
java.lang.reflect.AnnotatedType |
getAnnotatedType() |
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.util.List<TypeUsage> |
getInterfaces()
Return interfaces of this type.
|
java.util.List<TypeUsage> |
getLowerBounds()
Return lower bounds if a generic type is a wildcard.
|
java.util.Optional<java.lang.Object> |
getMetaInfo(java.lang.String key)
Get meta info for a certain key
|
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.Optional<TypeUsage> |
getSuperclass()
Return superclass of this type.
|
java.util.List<TypeUsage> |
getSuperTypes()
List of superclass and interfaces.
|
java.lang.reflect.Type |
getType() |
TypeUsage |
getTypeArgument(int position)
Return the type argument at a specific position.
|
java.util.List<TypeUsage> |
getTypeArguments()
Return the type arguments of a generic type in the order of there appearance in a type's declaration.
|
java.lang.String |
getTypeVariable() |
java.util.List<TypeUsage> |
getUpperBounds()
Return upper bounds if a generic type is a wildcard or type variable.
|
<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 |
isExtendsConstraint()
Return true if it is a wildcard with extends constraint, e.g.
|
boolean |
isGeneric()
Return true if a type has any type arguments itself.
|
boolean |
isNullable()
Return optional true if this type is nullable.
|
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 |
isParameterizedRaw()
Return true if it is a parameterized type with no parameters, e.g.
|
boolean |
isSuperWildcard()
Return true if it is a wildcard with super constraint, e.g.
|
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 |
isVoid()
Return true if type is Void.
|
boolean |
isWildcard()
Return true if a generic type is a wildcard.
|
static TypeUsage |
of(java.lang.Class<?> type,
TypeUsage... typeParameters) |
static TypeUsage |
wildcard(TypeUsage upperBound) |
<A extends java.lang.annotation.Annotation> |
withAnnotation(A annotation)
Return type usage object with additional annotation
|
TypeUsage |
withMetaInfo(java.lang.String key,
java.lang.Object value)
Return type usage object with additional meta info
|
@API(status=INTERNAL) static final TypeUsage OBJECT_TYPE
static TypeUsage forType(java.lang.reflect.Type type)
java.lang.Class<?> getRawType()
A raw type always exists.
java.util.List<TypeUsage> getUpperBounds()
TypeUsage.of(Object.class)
is always included.java.util.List<TypeUsage> getLowerBounds()
boolean isWildcard()
boolean isTypeVariable()
boolean isTypeVariableOrWildcard()
java.util.List<TypeUsage> getTypeArguments()
TypeUsage getTypeArgument(int position)
boolean isOfType(java.lang.Class<?> aRawType)
Most of the time this is what you want to do when checking for applicability of a ArbitraryProvider.
boolean canBeAssignedTo(TypeUsage targetType)
TypeUsage
instance.boolean isGeneric()
boolean isEnum()
enum
type.boolean isArray()
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.
<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).<A extends java.lang.annotation.Annotation> boolean isAnnotated(java.lang.Class<A> annotationType)
annotationType
.boolean isAssignableFrom(java.lang.Class<?> providedClass)
providedClass
is assignable from this generic type.java.util.Optional<TypeUsage> getComponentType()
Optional
of an array's component type - if it is an array.@API(status=EXPERIMENTAL, since="1.2.0") boolean isVoid()
@API(status=EXPERIMENTAL, since="1.2.0") java.util.Optional<TypeUsage> getSuperclass()
@API(status=EXPERIMENTAL, since="1.8.0") java.util.List<TypeUsage> getSuperTypes()
@API(status=EXPERIMENTAL, since="1.2.0") java.util.List<TypeUsage> getInterfaces()
@API(status=INTERNAL, since="1.2.0") java.lang.reflect.Type getType()
@API(status=INTERNAL, since="1.2.0") java.lang.reflect.AnnotatedType getAnnotatedType()
@API(status=EXPERIMENTAL, since="1.6.0") boolean isNullable()
Plain Java types are never nullable. Nullability must be set explicitly using asNullable(). This is usually done in registered enhancers.
@API(status=EXPERIMENTAL, since="1.8.0") boolean isParameterizedRaw()
List
.@API(status=EXPERIMENTAL, since="1.8.0") boolean isSuperWildcard()
? super String
.@API(status=EXPERIMENTAL, since="1.8.0") boolean isExtendsConstraint()
? extends String
.@API(status=EXPERIMENTAL, since="1.6.0") TypeUsage asNullable()
@API(status=EXPERIMENTAL, since="1.6.0") TypeUsage asNotNullable()
@API(status=EXPERIMENTAL, since="1.6.0") java.lang.String getTypeVariable()
@API(status=EXPERIMENTAL, since="1.6.0") <A extends java.lang.annotation.Annotation> TypeUsage withAnnotation(A annotation)
@API(status=EXPERIMENTAL, since="1.6.0") java.util.Optional<java.lang.Object> getMetaInfo(java.lang.String key)
@API(status=EXPERIMENTAL, since="1.6.0") TypeUsage withMetaInfo(java.lang.String key, java.lang.Object value)