public class GenericTypeReflector extends Object
Constructor and Description |
---|
GenericTypeReflector() |
Modifier and Type | Method and Description |
---|---|
static Type |
addWildcardParameters(Class<?> clazz)
Returns a type representing the class, with all type parameters the unbound wildcard ("?").
|
static AnnotatedType |
annotate(Type type)
Recursively wraps a
Type into an AnnotatedType using the annotations found on
the erasure classes. |
static AnnotatedType |
annotate(Type type,
Annotation[] annotations)
Recursively wraps a
Type into an AnnotatedType using the annotations found on
the erasure classes, plus adding the provided annotations to the top level Type only. |
static AnnotatedParameterizedType |
capture(AnnotatedParameterizedType type)
Applies capture conversion to the given type.
|
static AnnotatedType |
capture(AnnotatedType type)
Applies capture conversion to the given type.
|
static AnnotatedType |
clone(AnnotatedType type)
Creates a new
AnnotatedType of the same structure and with the same annotations as the
provided one. |
static boolean |
equals(AnnotatedType t1,
AnnotatedType t2)
Checks whether the two provided types are of the same structure and annotations on all levels.
|
static Class<?> |
erase(Type type)
Returns the erasure of the given type.
|
static AnnotatedType |
getArrayComponentType(AnnotatedType type)
If type is an array type, returns the type of the component of the array.
|
static Type |
getArrayComponentType(Type type) |
static AnnotatedType |
getExactFieldType(Field f,
AnnotatedType type)
Returns the exact type of the given field in the given type.
|
static Type |
getExactFieldType(Field f,
Type type) |
static AnnotatedType[] |
getExactParameterTypes(Method m,
AnnotatedType type)
Returns the exact parameter types of the given method in the given type.
|
static Type[] |
getExactParameterTypes(Method m,
Type type) |
static AnnotatedType |
getExactReturnType(Method m,
AnnotatedType type)
Returns the exact return type of the given method in the given type.
|
static Type |
getExactReturnType(Method m,
Type type) |
static AnnotatedType |
getExactSuperType(AnnotatedType type,
Class<?> searchClass)
Finds the most specific supertype of type whose erasure is searchClass.
|
static Type |
getExactSuperType(Type type,
Class<?> searchClass) |
static Annotation[] |
getMergedAnnotations(AnnotatedType... types)
Returns an array containing all annotations declared by the given annotated types, without duplicates.
|
static String |
getTypeName(Type type)
Returns the display name of a Type.
|
static AnnotatedType |
getTypeParameter(AnnotatedType type,
TypeVariable<? extends Class<?>> variable)
Gets the type parameter for a given type that is the value for a given type variable.
|
static Type |
getTypeParameter(Type type,
TypeVariable<? extends Class<?>> variable) |
static List<Class<?>> |
getUpperBoundClassAndInterfaces(Type type)
Returns list of classes and interfaces that are supertypes of the given type.
|
static boolean |
isMissingTypeParameters(Type type)
Checks if the given type is a class that is supposed to have type parameters, but doesn't.
|
static boolean |
isSuperType(Type superType,
Type subType)
Checks if the capture of subType is a subtype of superType
|
static AnnotatedType |
mapTypeParameters(AnnotatedType toMapType,
AnnotatedType typeAndParams)
Maps type parameters in a type to their values.
|
static Annotation[] |
merge(Annotation[]... annotations)
Merges an arbitrary number of annotations arrays, and removes duplicates.
|
static AnnotatedType |
replaceAnnotations(AnnotatedType original,
Annotation[] annotations)
Creates a new
AnnotatedType of the same type as the original, but with its annotations
replaced with the provided ones. |
static boolean |
typeArraysEqual(AnnotatedType[] t1,
AnnotatedType[] t2) |
static AnnotatedType |
updateAnnotations(AnnotatedType original,
Annotation[] annotations)
Creates a new
AnnotatedType of the same structure as the original, but with its annotations
replaced with the provided ones. |
public static AnnotatedType mapTypeParameters(AnnotatedType toMapType, AnnotatedType typeAndParams)
toMapType
- Type possibly containing type argumentstypeAndParams
- must be either ParameterizedType, or (in case there are no type arguments, or it's a raw type) Classpublic static boolean isMissingTypeParameters(Type type)
public static Type addWildcardParameters(Class<?> clazz)
public static AnnotatedType getExactSuperType(AnnotatedType type, Class<?> searchClass)
ParameterizedType
if searchClass is a real class or interface and type has parameters for itGenericArrayType
if searchClass is an array type, and type has type parameters for itClass
if type is a raw type, or has no type parameters for searchClassFor example, with class StringList implements List<String>, getExactSuperType(StringList.class, Collection.class)
returns a ParameterizedType
representing Collection<String>.
public static AnnotatedType getTypeParameter(AnnotatedType type, TypeVariable<? extends Class<?>> variable)
type
- The type to inspect.variable
- The type variable to find the value for.public static Type getTypeParameter(Type type, TypeVariable<? extends Class<?>> variable)
public static boolean isSuperType(Type superType, Type subType)
public static AnnotatedType getArrayComponentType(AnnotatedType type)
public static AnnotatedType getExactReturnType(Method m, AnnotatedType type)
public static AnnotatedType getExactFieldType(Field f, AnnotatedType type)
public static AnnotatedType[] getExactParameterTypes(Method m, AnnotatedType type)
public static AnnotatedType capture(AnnotatedType type)
public static AnnotatedParameterizedType capture(AnnotatedParameterizedType type)
capture(AnnotatedType)
public static List<Class<?>> getUpperBoundClassAndInterfaces(Type type)
This is mostly useful if you get a type from one of the other methods in GenericTypeReflector, but you don't want to deal with all the different sorts of types, and you are only really interested in concrete classes and interfaces.
public static AnnotatedType annotate(Type type)
Type
into an AnnotatedType
using the annotations found on
the erasure classes.type
- Type to annotatepublic static AnnotatedType annotate(Type type, Annotation[] annotations)
Type
into an AnnotatedType
using the annotations found on
the erasure classes, plus adding the provided annotations to the top level Type
only.type
- Type to annotateSee annotate(Type)
public static AnnotatedType replaceAnnotations(AnnotatedType original, Annotation[] annotations)
AnnotatedType
of the same type as the original, but with its annotations
replaced with the provided ones.original
- The type whose structure is to be copiedannotations
- Annotations to use instead of the ones found on the original
public static AnnotatedType updateAnnotations(AnnotatedType original, Annotation[] annotations)
AnnotatedType
of the same structure as the original, but with its annotations
replaced with the provided ones.original
- The type whose structure is to be copiedannotations
- Annotations to use instead of the ones found on the original
public static AnnotatedType clone(AnnotatedType type)
AnnotatedType
of the same structure and with the same annotations as the
provided one.type
- The type from which the structure and annotations are to be copiedpublic static Annotation[] getMergedAnnotations(AnnotatedType... types)
types
- Annotated types whose annotations are to be extracted and mergedpublic static Annotation[] merge(Annotation[]... annotations)
annotations
- Annotation arrays to merge and deduplicatepublic static boolean typeArraysEqual(AnnotatedType[] t1, AnnotatedType[] t2)
public static boolean equals(AnnotatedType t1, AnnotatedType t2)
t1
- The first type to be comparedt2
- The second type to be comparedCopyright © 2016. All rights reserved.