Package net.jqwik.api.providers
Interface TypeUsage
@API(status=MAINTAINED,
since="1.0")
public interface TypeUsage
An instance of
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:
- 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 TypeUsage is used in two places:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceEnhancers can manipulate the perceived type of parameters.static class -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionReturn type usage object with just nullablity set to falseReturn type usage object with just nullablity set to truebooleancanBeAssignedTo(TypeUsage targetType) Check if an instance can be assigned to anotherTypeUsageinstance.<A extends Annotation>
Optional<A>findAnnotation(Class<A> annotationType) Return anOptionalof the first instance of a specificannotationTypeif there is one (directly or indirectly through meta-annotations).static TypeUsageReturn all annotations of a parameter (or an annotated type argument).Return anOptionalof an array's component type - if it is an array.Return interfaces of this type.Return lower bounds if a generic type is a wildcard.getMetaInfo(String key) Get meta info for a certain keyClass<?>Return the raw type which is usually the class or interface you see in a parameters or return values specification.Return superclass of this type.List of superclass and interfaces.getType()getTypeArgument(int position) Return the type argument at a specific position.Return the type arguments of a generic type in the order of there appearance in a type's declaration.Return upper bounds if a generic type is a wildcard or type variable.booleanhasSameTypeAs(TypeUsage other) Check for type equality, ie do not consider annotations.<A extends Annotation>
booleanisAnnotated(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(Class<?> providedClass) Check if a givenprovidedClassis assignable from this generic type.booleanisEnum()Return true if a type is anenumtype.booleanReturn true if it is a wildcard with extends constraint, e.g.booleanReturn true if a type has any type arguments itself.booleanReturn optional true if this type is nullable.booleanCheck if an instance is of a specific raw typebooleanReturn true if it is a parameterized type with no parameters, e.g.booleanReturn true if it is a wildcard with super constraint, e.g.booleanReturn true if a generic type is a wildcard.booleanReturn true if a generic type is a type variable or a wildcard.booleanisVoid()Return true if type is Void.booleanReturn true if a generic type is a wildcard.static TypeUsagestatic TypeUsage<A extends Annotation>
TypeUsagewithAnnotation(A annotation) Return type usage object with additional annotationwithMetaInfo(String key, Object value) Return type usage object with additional meta info
-
Field Details
-
OBJECT_TYPE
-
-
Method Details
-
of
-
wildcard
-
forType
-
getRawType
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
Return upper bounds if a generic type is a wildcard or type variable.TypeUsage.of(Object.class)is always included. -
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
Return the type arguments of a generic type in the order of there appearance in a type's declaration. -
getTypeArgument
Return the type argument at a specific position. -
isOfType
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
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
List<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
Return anOptionalof the first instance of a specificannotationTypeif there is one (directly or indirectly through meta-annotations). -
isAnnotated
Return true if the current instance is annotated (directly or indirectly through meta-annotations) with a specificannotationType. -
isAssignableFrom
Check if a givenprovidedClassis assignable from this generic type. -
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
Return superclass of this type. With all type variables resolved. -
getSuperTypes
List of superclass and interfaces. With all type variables resolved. -
getInterfaces
Return interfaces of this type. With all type variables resolved. -
getType
-
getAnnotatedType
-
isNullable
@API(status=EXPERIMENTAL, since="1.6.0") boolean isNullable()Return optional true if this type is nullable.Plain Java types are never nullable. Nullability must be set explicitly using asNullable(). This is usually done in registered enhancers.
-
isParameterizedRaw
@API(status=EXPERIMENTAL, since="1.8.0") boolean isParameterizedRaw()Return true if it is a parameterized type with no parameters, e.g.List. -
isSuperWildcard
@API(status=EXPERIMENTAL, since="1.8.0") boolean isSuperWildcard()Return true if it is a wildcard with super constraint, e.g.? super String. -
isExtendsConstraint
@API(status=EXPERIMENTAL, since="1.8.0") boolean isExtendsConstraint()Return true if it is a wildcard with extends constraint, e.g.? extends String. -
asNullable
Return type usage object with just nullablity set to true -
asNotNullable
Return type usage object with just nullablity set to false -
getTypeVariable
-
withAnnotation
@API(status=EXPERIMENTAL, since="1.6.0") <A extends Annotation> TypeUsage withAnnotation(A annotation) Return type usage object with additional annotation -
getMetaInfo
Get meta info for a certain key -
withMetaInfo
Return type usage object with additional meta info -
hasSameTypeAs
Check for type equality, ie do not consider annotations.
-