Package net.jqwik.api.providers
Interface TypeUsage
-
@API(status=MAINTAINED, since="1.0") public interface TypeUsageAn instance ofTypeUsagedescribes 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.TypeUsageprovides access to:- the native type of an object
- the component type (if it's an array)
- the type parameters (again as instances of
TypeUsage) - the annotations (if the object is derived from a parameter)
- methods to test for compatibility of types that do also handle compatibility between raw types and boxed type
Within the public API
TypeUsageis used in two places:
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classTypeUsage.TypeUsageFacade
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description booleancanBeAssignedTo(TypeUsage targetType)Check if an instance can be assigned to anotherTypeUsageinstance.<A extends java.lang.annotation.Annotation>
java.util.Optional<A>findAnnotation(java.lang.Class<A> annotationType)Return anOptionalof the first instance of a specificannotationTypeif there is one (directly or indirectly through meta-annotations).static TypeUsageforType(java.lang.reflect.Type type)java.lang.reflect.AnnotatedTypegetAnnotatedType()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 anOptionalof 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.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.lang.reflect.TypegetType()TypeUsagegetTypeArgument(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.util.List<TypeUsage>getUpperBounds()Return upper bounds if a generic type is a wildcard or type variable.<A extends java.lang.annotation.Annotation>
booleanisAnnotated(java.lang.Class<A> annotationType)Return true if the current instance is annotated (directly or indirectly through meta-annotations) with a specificannotationType.booleanisArray()Return true if a type is an array type.booleanisAssignableFrom(java.lang.Class<?> providedClass)Check if a givenprovidedClassis assignable from this generic type.booleanisEnum()Return true if a type is anenumtype.booleanisGeneric()Return true if a type has any type arguments itself.booleanisOfType(java.lang.Class<?> aRawType)Check if an instance is of a specific raw typebooleanisTypeVariable()Return true if a generic type is a wildcard.booleanisTypeVariableOrWildcard()Return true if a generic type is a type variable or a wildcard.booleanisVoid()Return true if type is Void.booleanisWildcard()Return true if a generic type is a wildcard.static TypeUsageof(java.lang.Class<?> type, TypeUsage... typeParameters)static TypeUsagewildcard(TypeUsage upperBound)
-
-
-
Method Detail
-
forType
static TypeUsage forType(java.lang.reflect.Type type)
-
getRawType
java.lang.Class<?> getRawType()
Return the raw type which is usually the class or interface you see in a parameters or return values specification.A raw type always exists.
-
getUpperBounds
java.util.List<TypeUsage> getUpperBounds()
Return upper bounds if a generic type is a wildcard or type variable.TypeUsage.of(Object.class)is always included.
-
getLowerBounds
java.util.List<TypeUsage> getLowerBounds()
Return lower bounds if a generic type is a wildcard.
-
isWildcard
boolean isWildcard()
Return true if a generic type is a wildcard.
-
isTypeVariable
boolean isTypeVariable()
Return true if a generic type is a wildcard.
-
isTypeVariableOrWildcard
boolean isTypeVariableOrWildcard()
Return true if a generic type is a type variable or a wildcard.
-
getTypeArguments
java.util.List<TypeUsage> getTypeArguments()
Return the type arguments of a generic type in the order of there appearance in a type's declaration.
-
getTypeArgument
TypeUsage getTypeArgument(int position)
Return the type argument at a specific position.
-
isOfType
boolean isOfType(java.lang.Class<?> aRawType)
Check if an instance is of a specific raw typeMost of the time this is what you want to do when checking for applicability of a ArbitraryProvider.
-
canBeAssignedTo
boolean canBeAssignedTo(TypeUsage targetType)
Check if an instance can be assigned to anotherTypeUsageinstance.
-
isGeneric
boolean isGeneric()
Return true if a type has any type arguments itself.
-
isEnum
boolean isEnum()
Return true if a type is anenumtype.
-
isArray
boolean isArray()
Return true if a type is an array type.
-
getAnnotations
java.util.List<java.lang.annotation.Annotation> getAnnotations()
Return all annotations of a parameter (or an annotated type argument).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.
-
findAnnotation
<A extends java.lang.annotation.Annotation> java.util.Optional<A> findAnnotation(java.lang.Class<A> annotationType)
Return anOptionalof the first instance of a specificannotationTypeif there is one (directly or indirectly through meta-annotations).
-
isAnnotated
<A extends java.lang.annotation.Annotation> boolean isAnnotated(java.lang.Class<A> annotationType)
Return true if the current instance is annotated (directly or indirectly through meta-annotations) with a specificannotationType.
-
isAssignableFrom
boolean isAssignableFrom(java.lang.Class<?> providedClass)
Check if a givenprovidedClassis assignable from this generic type.
-
getComponentType
java.util.Optional<TypeUsage> getComponentType()
Return anOptionalof an array's component type - if it is an array.
-
isVoid
@API(status=EXPERIMENTAL, since="1.2.0") boolean isVoid()Return true if type is Void.
-
getSuperclass
@API(status=EXPERIMENTAL, since="1.2.0") java.util.Optional<TypeUsage> getSuperclass()Return superclass of this type.
-
getInterfaces
@API(status=EXPERIMENTAL, since="1.2.0") java.util.List<TypeUsage> getInterfaces()Return interfaces of this type.
-
getType
@API(status=INTERNAL, since="1.2.0") java.lang.reflect.Type getType()
-
getAnnotatedType
@API(status=INTERNAL, since="1.2.0") java.lang.reflect.AnnotatedType getAnnotatedType()
-
-