public class TypeUtils
extends java.lang.Object
Utility methods focusing on type inspection, particularly with regard to generics.
| Modifier and Type | Class and Description |
|---|---|
private static class |
TypeUtils.GenericArrayTypeImpl
GenericArrayType implementation class.
|
private static class |
TypeUtils.ParameterizedTypeImpl
ParameterizedType implementation class.
|
static class |
TypeUtils.WildcardTypeBuilder
WildcardType builder. |
private static class |
TypeUtils.WildcardTypeImpl
WildcardType implementation class.
|
| Modifier and Type | Field and Description |
|---|---|
static java.lang.reflect.WildcardType |
WILDCARD_ALL
A wildcard instance matching
?. |
| Constructor and Description |
|---|
TypeUtils()
TypeUtils instances should NOT be constructed in standard
programming. |
| Modifier and Type | Method and Description |
|---|---|
private static <T> java.lang.StringBuilder |
appendAllTo(java.lang.StringBuilder buf,
java.lang.String sep,
T... types)
Append
types to buf with separator sep. |
private static void |
appendRecursiveTypes(java.lang.StringBuilder buf,
int[] recursiveTypeIndexes,
java.lang.reflect.Type[] argumentTypes) |
private static java.lang.String |
classToString(java.lang.Class<?> c)
Format a
Class as a String. |
static boolean |
containsTypeVariables(java.lang.reflect.Type type)
Learn, recursively, whether any of the type parameters associated with
type are bound to variables. |
private static boolean |
containsVariableTypeSameParametrizedTypeBound(java.lang.reflect.TypeVariable<?> typeVariable,
java.lang.reflect.ParameterizedType p) |
static java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> |
determineTypeArguments(java.lang.Class<?> cls,
java.lang.reflect.ParameterizedType superType)
Tries to determine the type arguments of a class/interface based on a
super parameterized type's type arguments.
|
private static boolean |
equals(java.lang.reflect.GenericArrayType a,
java.lang.reflect.Type t)
Learn whether
t equals a. |
private static boolean |
equals(java.lang.reflect.ParameterizedType p,
java.lang.reflect.Type t)
Learn whether
t equals p. |
private static boolean |
equals(java.lang.reflect.Type[] t1,
java.lang.reflect.Type[] t2)
Learn whether
t1 equals t2. |
static boolean |
equals(java.lang.reflect.Type t1,
java.lang.reflect.Type t2)
Check equality of types.
|
private static boolean |
equals(java.lang.reflect.WildcardType w,
java.lang.reflect.Type t)
Learn whether
t equals w. |
private static java.lang.reflect.Type[] |
extractTypeArgumentsFrom(java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> mappings,
java.lang.reflect.TypeVariable<?>[] variables)
Helper method to establish the formal parameters for a parameterized type.
|
private static int[] |
findRecursiveTypes(java.lang.reflect.ParameterizedType p) |
static java.lang.reflect.GenericArrayType |
genericArrayType(java.lang.reflect.Type componentType)
Create a generic array type instance.
|
private static java.lang.String |
genericArrayTypeToString(java.lang.reflect.GenericArrayType g)
Format a
GenericArrayType as a String. |
static java.lang.reflect.Type |
getArrayComponentType(java.lang.reflect.Type type)
Get the array component type of
type. |
private static java.lang.reflect.Type |
getClosestParentType(java.lang.Class<?> cls,
java.lang.Class<?> superClass)
Get the closest parent type to the
super class specified by
superClass. |
static java.lang.reflect.Type[] |
getImplicitBounds(java.lang.reflect.TypeVariable<?> typeVariable)
Returns an array containing the sole type of
Object if
TypeVariable.getBounds() returns an empty array. |
static java.lang.reflect.Type[] |
getImplicitLowerBounds(java.lang.reflect.WildcardType wildcardType)
Returns an array containing a single value of
null if
WildcardType.getLowerBounds() returns an empty array. |
static java.lang.reflect.Type[] |
getImplicitUpperBounds(java.lang.reflect.WildcardType wildcardType)
Returns an array containing the sole value of
Object if
WildcardType.getUpperBounds() returns an empty array. |
private static java.lang.Class<?> |
getRawType(java.lang.reflect.ParameterizedType parameterizedType)
Transforms the passed in type to a
Class object. |
static java.lang.Class<?> |
getRawType(java.lang.reflect.Type type,
java.lang.reflect.Type assigningType)
Get the raw type of a Java type, given its context.
|
private static java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> |
getTypeArguments(java.lang.Class<?> cls,
java.lang.Class<?> toClass,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> subtypeVarAssigns)
Return a map of the type arguments of a class in the context of
toClass. |
static java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> |
getTypeArguments(java.lang.reflect.ParameterizedType type)
Retrieves all the type arguments for this parameterized type
including owner hierarchy arguments such as
Outer<K,V>.Inner<T>.DeepInner<E> . |
private static java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> |
getTypeArguments(java.lang.reflect.ParameterizedType parameterizedType,
java.lang.Class<?> toClass,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> subtypeVarAssigns)
Return a map of the type arguments of a parameterized type in the context of
toClass. |
static java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> |
getTypeArguments(java.lang.reflect.Type type,
java.lang.Class<?> toClass)
Gets the type arguments of a class/interface based on a subtype.
|
private static java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> |
getTypeArguments(java.lang.reflect.Type type,
java.lang.Class<?> toClass,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> subtypeVarAssigns)
Return a map of the type arguments of
type in the context of toClass. |
static boolean |
isArrayType(java.lang.reflect.Type type)
Learn whether the specified type denotes an array type.
|
private static boolean |
isAssignable(java.lang.reflect.Type type,
java.lang.Class<?> toClass)
Checks if the subject type may be implicitly cast to the target class
following the Java generics rules.
|
private static boolean |
isAssignable(java.lang.reflect.Type type,
java.lang.reflect.GenericArrayType toGenericArrayType,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeVarAssigns)
Checks if the subject type may be implicitly cast to the target
generic array type following the Java generics rules.
|
private static boolean |
isAssignable(java.lang.reflect.Type type,
java.lang.reflect.ParameterizedType toParameterizedType,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeVarAssigns)
Checks if the subject type may be implicitly cast to the target
parameterized type following the Java generics rules.
|
static boolean |
isAssignable(java.lang.reflect.Type type,
java.lang.reflect.Type toType)
Checks if the subject type may be implicitly cast to the target type
following the Java generics rules.
|
private static boolean |
isAssignable(java.lang.reflect.Type type,
java.lang.reflect.Type toType,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeVarAssigns)
Checks if the subject type may be implicitly cast to the target type
following the Java generics rules.
|
private static boolean |
isAssignable(java.lang.reflect.Type type,
java.lang.reflect.TypeVariable<?> toTypeVariable,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeVarAssigns)
Checks if the subject type may be implicitly cast to the target type
variable following the Java generics rules.
|
private static boolean |
isAssignable(java.lang.reflect.Type type,
java.lang.reflect.WildcardType toWildcardType,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeVarAssigns)
Checks if the subject type may be implicitly cast to the target
wildcard type following the Java generics rules.
|
static boolean |
isInstance(java.lang.Object value,
java.lang.reflect.Type type)
Checks if the given value can be assigned to the target type
following the Java generics rules.
|
private static <T> void |
mapTypeVariablesToArguments(java.lang.Class<T> cls,
java.lang.reflect.ParameterizedType parameterizedType,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeVarAssigns)
Performs a mapping of type variables.
|
static java.lang.reflect.Type[] |
normalizeUpperBounds(java.lang.reflect.Type[] bounds)
This method strips out the redundant upper bound types in type
variable types and wildcard types (or it would with wildcard types if
multiple upper bounds were allowed).
|
static java.lang.reflect.ParameterizedType |
parameterize(java.lang.Class<?> raw,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeArgMappings)
Create a parameterized type instance.
|
static java.lang.reflect.ParameterizedType |
parameterize(java.lang.Class<?> raw,
java.lang.reflect.Type... typeArguments)
Create a parameterized type instance.
|
private static java.lang.String |
parameterizedTypeToString(java.lang.reflect.ParameterizedType p)
Format a
ParameterizedType as a String. |
static java.lang.reflect.ParameterizedType |
parameterizeWithOwner(java.lang.reflect.Type owner,
java.lang.Class<?> raw,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeArgMappings)
Create a parameterized type instance.
|
static java.lang.reflect.ParameterizedType |
parameterizeWithOwner(java.lang.reflect.Type owner,
java.lang.Class<?> raw,
java.lang.reflect.Type... typeArguments)
Create a parameterized type instance.
|
private static java.lang.reflect.Type |
substituteTypeVariables(java.lang.reflect.Type type,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeVarAssigns)
Find the mapping for
type in typeVarAssigns. |
static java.lang.String |
toLongString(java.lang.reflect.TypeVariable<?> var)
Format a
TypeVariable including its GenericDeclaration. |
private static <T> java.lang.String |
toString(T object) |
static java.lang.String |
toString(java.lang.reflect.Type type)
Present a given type as a Java-esque String.
|
static boolean |
typesSatisfyVariables(java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeVarAssigns)
Determines whether or not specified types satisfy the bounds of their
mapped type variables.
|
private static java.lang.String |
typeVariableToString(java.lang.reflect.TypeVariable<?> v)
Format a
TypeVariable as a String. |
private static java.lang.reflect.Type[] |
unrollBounds(java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeArguments,
java.lang.reflect.Type[] bounds)
Local helper method to unroll variables in a type bounds array.
|
private static java.lang.reflect.Type |
unrollVariableAssignments(java.lang.reflect.TypeVariable<?> var,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeVarAssigns)
Look up
var in typeVarAssigns transitively,
i.e. |
static java.lang.reflect.Type |
unrollVariables(java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeArguments,
java.lang.reflect.Type type)
Get a type representing
type with variable assignments "unrolled." |
static TypeUtils.WildcardTypeBuilder |
wildcardType()
|
private static java.lang.String |
wildcardTypeToString(java.lang.reflect.WildcardType w)
Format a
WildcardType as a String. |
static <T> Typed<T> |
wrap(java.lang.Class<T> type)
Wrap the specified
Class in a Typed wrapper. |
static <T> Typed<T> |
wrap(java.lang.reflect.Type type)
Wrap the specified
Type in a Typed wrapper. |
public static final java.lang.reflect.WildcardType WILDCARD_ALL
?.public TypeUtils()
TypeUtils instances should NOT be constructed in standard
programming. Instead, the class should be used as
TypeUtils.isAssignable(cls, toClass).
This constructor is public to permit tools that require a JavaBean instance to operate.
public static boolean isAssignable(java.lang.reflect.Type type,
java.lang.reflect.Type toType)
Checks if the subject type may be implicitly cast to the target type
following the Java generics rules. If both types are Class
objects, the method returns the result of
ClassUtils.isAssignable(Class, Class).
type - the subject type to be assigned to the target typetoType - the target typetrue if type is assignable to toType.private static boolean isAssignable(java.lang.reflect.Type type,
java.lang.reflect.Type toType,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeVarAssigns)
Checks if the subject type may be implicitly cast to the target type following the Java generics rules.
type - the subject type to be assigned to the target typetoType - the target typetypeVarAssigns - optional map of type variable assignmentstrue if type is assignable to toType.private static boolean isAssignable(java.lang.reflect.Type type,
java.lang.Class<?> toClass)
Checks if the subject type may be implicitly cast to the target class following the Java generics rules.
type - the subject type to be assigned to the target typetoClass - the target classtrue if type is assignable to toClass.private static boolean isAssignable(java.lang.reflect.Type type,
java.lang.reflect.ParameterizedType toParameterizedType,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeVarAssigns)
Checks if the subject type may be implicitly cast to the target parameterized type following the Java generics rules.
type - the subject type to be assigned to the target typetoParameterizedType - the target parameterized typetypeVarAssigns - a map with type variablestrue if type is assignable to toType.private static java.lang.reflect.Type unrollVariableAssignments(java.lang.reflect.TypeVariable<?> var,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeVarAssigns)
var in typeVarAssigns transitively,
i.e. keep looking until the value found is not a type variable.var - the type variable to look uptypeVarAssigns - the map used for the look upnull if some variable was not in the mapprivate static boolean isAssignable(java.lang.reflect.Type type,
java.lang.reflect.GenericArrayType toGenericArrayType,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeVarAssigns)
Checks if the subject type may be implicitly cast to the target generic array type following the Java generics rules.
type - the subject type to be assigned to the target typetoGenericArrayType - the target generic array typetypeVarAssigns - a map with type variablestrue if type is assignable to
toGenericArrayType.private static boolean isAssignable(java.lang.reflect.Type type,
java.lang.reflect.WildcardType toWildcardType,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeVarAssigns)
Checks if the subject type may be implicitly cast to the target wildcard type following the Java generics rules.
type - the subject type to be assigned to the target typetoWildcardType - the target wildcard typetypeVarAssigns - a map with type variablestrue if type is assignable to
toWildcardType.private static boolean isAssignable(java.lang.reflect.Type type,
java.lang.reflect.TypeVariable<?> toTypeVariable,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeVarAssigns)
Checks if the subject type may be implicitly cast to the target type variable following the Java generics rules.
type - the subject type to be assigned to the target typetoTypeVariable - the target type variabletypeVarAssigns - a map with type variablestrue if type is assignable to
toTypeVariable.private static java.lang.reflect.Type substituteTypeVariables(java.lang.reflect.Type type,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeVarAssigns)
Find the mapping for type in typeVarAssigns.
type - the type to be replacedtypeVarAssigns - the map with type variablesjava.lang.IllegalArgumentException - if the type cannot be substitutedpublic static java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> getTypeArguments(java.lang.reflect.ParameterizedType type)
Retrieves all the type arguments for this parameterized type
including owner hierarchy arguments such as
Outer<K,V>.Inner<T>.DeepInner<E> .
The arguments are returned in a
Map specifying the argument type for each TypeVariable.
type - specifies the subject parameterized type from which to
harvest the parameters.Map of the type arguments to their respective type
variables.public static java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> getTypeArguments(java.lang.reflect.Type type,
java.lang.Class<?> toClass)
Gets the type arguments of a class/interface based on a subtype. For
instance, this method will determine that both of the parameters for the
interface Map are Object for the subtype
Properties even though the subtype does not
directly implement the Map interface.
This method returns null if type is not assignable to
toClass. It returns an empty map if none of the classes or
interfaces in its inheritance hierarchy specify any type arguments.
A side effect of this method is that it also retrieves the type
arguments for the classes and interfaces that are part of the hierarchy
between type and toClass. So with the above
example, this method will also determine that the type arguments for
Hashtable are also both Object.
In cases where the interface specified by toClass is
(indirectly) implemented more than once (e.g. where toClass
specifies the interface Iterable and
type specifies a parameterized type that implements both
Set and Collection),
this method will look at the inheritance hierarchy of only one of the
implementations/subclasses; the first interface encountered that isn't a
subinterface to one of the others in the type to
toClass hierarchy.
type - the type from which to determine the type parameters of
toClasstoClass - the class whose type parameters are to be determined based
on the subtype typeMap of the type assignments for the type variables in
each type in the inheritance hierarchy from type to
toClass inclusive.private static java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> getTypeArguments(java.lang.reflect.Type type,
java.lang.Class<?> toClass,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> subtypeVarAssigns)
Return a map of the type arguments of type in the context of toClass.
type - the type in questiontoClass - the classsubtypeVarAssigns - a map with type variablesMap with type argumentsprivate static java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> getTypeArguments(java.lang.reflect.ParameterizedType parameterizedType,
java.lang.Class<?> toClass,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> subtypeVarAssigns)
Return a map of the type arguments of a parameterized type in the context of toClass.
parameterizedType - the parameterized typetoClass - the classsubtypeVarAssigns - a map with type variablesMap with type argumentsprivate static java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> getTypeArguments(java.lang.Class<?> cls,
java.lang.Class<?> toClass,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> subtypeVarAssigns)
Return a map of the type arguments of a class in the context of toClass.
cls - the class in questiontoClass - the context classsubtypeVarAssigns - a map with type variablesMap with type argumentspublic static java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> determineTypeArguments(java.lang.Class<?> cls,
java.lang.reflect.ParameterizedType superType)
Tries to determine the type arguments of a class/interface based on a
super parameterized type's type arguments. This method is the inverse of
getTypeArguments(Type, Class) which gets a class/interface's
type arguments based on a subtype. It is far more limited in determining
the type arguments for the subject class's type variables in that it can
only determine those parameters that map from the subject Class
object to the supertype.
Example: TreeSet sets its parameter as the parameter for
NavigableSet, which in turn sets the
parameter of SortedSet, which in turn sets the
parameter of Set, which in turn sets the parameter of
Collection, which in turn sets the parameter of
Iterable. Since TreeSet's parameter maps
(indirectly) to Iterable's parameter, it will be able to
determine that based on the super type Iterable<? extends
Map<Integer, ? extends Collection<?>>>, the parameter of
TreeSet is ? extends Map<Integer, ? extends
Collection<?>>.
cls - the class whose type parameters are to be determined, not nullsuperType - the super type from which cls's type
arguments are to be determined, not nullMap of the type assignments that could be determined
for the type variables in each type in the inheritance hierarchy from
type to toClass inclusive.private static <T> void mapTypeVariablesToArguments(java.lang.Class<T> cls,
java.lang.reflect.ParameterizedType parameterizedType,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeVarAssigns)
Performs a mapping of type variables.
T - the generic type of the class in questioncls - the class in questionparameterizedType - the parameterized typetypeVarAssigns - the map to be filledprivate static java.lang.reflect.Type getClosestParentType(java.lang.Class<?> cls,
java.lang.Class<?> superClass)
Get the closest parent type to the
super class specified by superClass.
cls - the class in questionsuperClass - the super classpublic static boolean isInstance(java.lang.Object value,
java.lang.reflect.Type type)
Checks if the given value can be assigned to the target type following the Java generics rules.
value - the value to be checkedtype - the target typetrue if value is an instance of type.public static java.lang.reflect.Type[] normalizeUpperBounds(java.lang.reflect.Type[] bounds)
This method strips out the redundant upper bound types in type variable types and wildcard types (or it would with wildcard types if multiple upper bounds were allowed).
Example, with the variable type declaration:
<K extends java.util.Collection<String> & java.util.List<String>>
since List is a subinterface of Collection,
this method will return the bounds as if the declaration had been:
<K extends java.util.List<String>>
bounds - an array of types representing the upper bounds of either
WildcardType or TypeVariable, not null.bounds minus the
redundant types.public static java.lang.reflect.Type[] getImplicitBounds(java.lang.reflect.TypeVariable<?> typeVariable)
Returns an array containing the sole type of Object if
TypeVariable.getBounds() returns an empty array. Otherwise, it
returns the result of TypeVariable.getBounds() passed into
normalizeUpperBounds(java.lang.reflect.Type[]).
typeVariable - the subject type variable, not nullpublic static java.lang.reflect.Type[] getImplicitUpperBounds(java.lang.reflect.WildcardType wildcardType)
Returns an array containing the sole value of Object if
WildcardType.getUpperBounds() returns an empty array. Otherwise,
it returns the result of WildcardType.getUpperBounds()
passed into normalizeUpperBounds(java.lang.reflect.Type[]).
wildcardType - the subject wildcard type, not nullpublic static java.lang.reflect.Type[] getImplicitLowerBounds(java.lang.reflect.WildcardType wildcardType)
Returns an array containing a single value of null if
WildcardType.getLowerBounds() returns an empty array. Otherwise,
it returns the result of WildcardType.getLowerBounds().
wildcardType - the subject wildcard type, not nullpublic static boolean typesSatisfyVariables(java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeVarAssigns)
Determines whether or not specified types satisfy the bounds of their
mapped type variables. When a type parameter extends another (such as
<T, S extends T>), uses another as a type parameter (such as
<T, S extends Comparable>>), or otherwise depends on
another type variable to be specified, the dependencies must be included
in typeVarAssigns.
typeVarAssigns - specifies the potential types to be assigned to the
type variables, not null.private static java.lang.Class<?> getRawType(java.lang.reflect.ParameterizedType parameterizedType)
Transforms the passed in type to a Class object. Type-checking method of convenience.
parameterizedType - the type to be convertedClass objectjava.lang.IllegalStateException - if the conversion failspublic static java.lang.Class<?> getRawType(java.lang.reflect.Type type,
java.lang.reflect.Type assigningType)
Get the raw type of a Java type, given its context. Primarily for use
with TypeVariables and GenericArrayTypes, or when you do
not know the runtime type of type: if you know you have a
Class instance, it is already raw; if you know you have a
ParameterizedType, its raw type is only a method call away.
type - to resolveassigningType - type to be resolved againstClass object or null if
the type could not be resolvedpublic static boolean isArrayType(java.lang.reflect.Type type)
type - the type to be checkedtrue if type is an array class or a GenericArrayType.public static java.lang.reflect.Type getArrayComponentType(java.lang.reflect.Type type)
type.type - the type to be checkedpublic static java.lang.reflect.Type unrollVariables(java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeArguments,
java.lang.reflect.Type type)
type with variable assignments "unrolled."typeArguments - as from getTypeArguments(Type, Class)type - the type to unroll variable assignments forprivate static java.lang.reflect.Type[] unrollBounds(java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeArguments,
java.lang.reflect.Type[] bounds)
typeArguments - assignments Mapbounds - in which to expand variablesbounds with any variables reassignedpublic static boolean containsTypeVariables(java.lang.reflect.Type type)
type are bound to variables.type - the type to check for type variablespublic static final java.lang.reflect.ParameterizedType parameterize(java.lang.Class<?> raw,
java.lang.reflect.Type... typeArguments)
raw - the raw class to create a parameterized type instance fortypeArguments - the types used for parameterizationParameterizedTypepublic static final java.lang.reflect.ParameterizedType parameterize(java.lang.Class<?> raw,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeArgMappings)
raw - the raw class to create a parameterized type instance fortypeArgMappings - the mapping used for parameterizationParameterizedTypepublic static final java.lang.reflect.ParameterizedType parameterizeWithOwner(java.lang.reflect.Type owner,
java.lang.Class<?> raw,
java.lang.reflect.Type... typeArguments)
owner - the owning typeraw - the raw class to create a parameterized type instance fortypeArguments - the types used for parameterizationParameterizedTypepublic static final java.lang.reflect.ParameterizedType parameterizeWithOwner(java.lang.reflect.Type owner,
java.lang.Class<?> raw,
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> typeArgMappings)
owner - the owning typeraw - the raw class to create a parameterized type instance fortypeArgMappings - the mapping used for parameterizationParameterizedTypeprivate static java.lang.reflect.Type[] extractTypeArgumentsFrom(java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> mappings,
java.lang.reflect.TypeVariable<?>[] variables)
mappings - map containing the assignmentsvariables - expected map keyspublic static TypeUtils.WildcardTypeBuilder wildcardType()
TypeUtils.WildcardTypeBuilderpublic static java.lang.reflect.GenericArrayType genericArrayType(java.lang.reflect.Type componentType)
componentType - the type of the elements of the array. For example the component type of boolean[]
is booleanGenericArrayTypepublic static boolean equals(java.lang.reflect.Type t1,
java.lang.reflect.Type t2)
t1 - the first typet2 - the second typeprivate static boolean equals(java.lang.reflect.ParameterizedType p,
java.lang.reflect.Type t)
t equals p.p - LHSt - RHSprivate static boolean equals(java.lang.reflect.GenericArrayType a,
java.lang.reflect.Type t)
t equals a.a - LHSt - RHSprivate static boolean equals(java.lang.reflect.WildcardType w,
java.lang.reflect.Type t)
t equals w.w - LHSt - RHSprivate static boolean equals(java.lang.reflect.Type[] t1,
java.lang.reflect.Type[] t2)
t1 equals t2.t1 - LHSt2 - RHSpublic static java.lang.String toString(java.lang.reflect.Type type)
type - the type to create a String representation for, not nullpublic static java.lang.String toLongString(java.lang.reflect.TypeVariable<?> var)
TypeVariable including its GenericDeclaration.var - the type variable to create a String representation for, not nullpublic static <T> Typed<T> wrap(java.lang.reflect.Type type)
Type in a Typed wrapper.T - inferred generic typetype - to wrappublic static <T> Typed<T> wrap(java.lang.Class<T> type)
Class in a Typed wrapper.T - generic typetype - to wrapprivate static java.lang.String classToString(java.lang.Class<?> c)
Class as a String.c - Class to formatprivate static java.lang.String typeVariableToString(java.lang.reflect.TypeVariable<?> v)
TypeVariable as a String.v - TypeVariable to formatprivate static java.lang.String parameterizedTypeToString(java.lang.reflect.ParameterizedType p)
ParameterizedType as a String.p - ParameterizedType to formatprivate static void appendRecursiveTypes(java.lang.StringBuilder buf,
int[] recursiveTypeIndexes,
java.lang.reflect.Type[] argumentTypes)
private static int[] findRecursiveTypes(java.lang.reflect.ParameterizedType p)
private static boolean containsVariableTypeSameParametrizedTypeBound(java.lang.reflect.TypeVariable<?> typeVariable,
java.lang.reflect.ParameterizedType p)
private static java.lang.String wildcardTypeToString(java.lang.reflect.WildcardType w)
WildcardType as a String.w - WildcardType to formatprivate static java.lang.String genericArrayTypeToString(java.lang.reflect.GenericArrayType g)
GenericArrayType as a String.g - GenericArrayType to formatprivate static <T> java.lang.StringBuilder appendAllTo(java.lang.StringBuilder buf,
java.lang.String sep,
T... types)
types to buf with separator sep.buf - destinationsep - separatortypes - to appendbufprivate static <T> java.lang.String toString(T object)