Package org.jboss.resteasy.spi.util
Class Types
- java.lang.Object
-
- org.jboss.resteasy.spi.util.Types
-
public final class Types extends Object
Type conversions and generic type manipulations- Version:
- $Revision: 1 $
- Author:
- Bill Burke
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Types.ResteasyParameterizedType
-
Constructor Summary
Constructors Constructor Description Types()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Type
boxPrimitives(Type genericType)
static Type[]
findClassParameterizedTypes(Class<?> root, ParameterizedType rootType, Class<?> searchedForClass)
static Type[]
findInterfaceParameterizedTypes(Class<?> root, ParameterizedType rootType, Class<?> searchedForInterface)
static Method
findOverriddenMethod(Class<?> root, Class<?> superClass, Method implementation)
Find the by a method implementation overridden superclass method.static Type[]
findParameterizedTypes(Class<?> root, Class<?> searchedFor)
Search for the given interface or class within the root's class/interface hierarchy.static Type[]
getActualTypeArgumentsOfAnInterface(Class<?> classToSearch, Class<?> interfaceToFind)
Given a class and an interfaces, go through the class hierarchy to find the interface and return its type arguments.static Class
getArgumentType(ParameterizedType pType, int index)
Gets the index-th type argument.static Class
getCollectionBaseType(Class type, Type genericType)
static Method
getImplementedInterfaceMethod(Class<?> root, Class<?> iface, Method implementation)
Find the by a method implementation implemented interface method.static Method
getImplementingMethod(Class clazz, Method intfMethod)
Given a method and a root class, find the actual method declared in the root that implements the method.static Class
getMapKeyType(Type genericType)
static Class
getMapValueType(Type genericType)
static Class<?>
getRawType(Type type)
static Class<?>
getRawTypeNoException(Type type)
static Class
getTemplateParameterOfInterface(Class base, Class desiredInterface)
static Class<?>
getTypeArgument(Type genericType)
Returns the type argument from a parameterized type.static boolean
hasPostConstruct(Class<?> clazz)
static boolean
hasPostConstruct(Class<?> clazz, Function<Method,Boolean> validateParameterCount)
static boolean
isA(Class clazz, ParameterizedType pType)
Is the genericType of a certain class?static boolean
isCompatible(Method method, Method intfMethod)
See if the two methods are compatible, that is they have the same relative signature.static boolean
isGenericTypeInstanceOf(Class<?> c, Type type)
Checks that the given class,c
, is the generic type of the given type.static Map<TypeVariable<?>,Type>
populateParameterizedMap(Class<?> root, Class<?> superClass)
Create a mapping for generic types to actual types between two classes / interfaces of a type hierarchy.static Type
resolveTypeVariable(Class<?> root, TypeVariable<?> typeVariable)
Finds an actual value of a type variable.static Type
resolveTypeVariables(Class<?> root, Type type)
-
-
-
Method Detail
-
isA
public static boolean isA(Class clazz, ParameterizedType pType)
Is the genericType of a certain class?- Parameters:
clazz
- classpType
- type- Returns:
- boolean result
-
getArgumentType
public static Class getArgumentType(ParameterizedType pType, int index)
Gets the index-th type argument.- Parameters:
pType
- typeindex
- index- Returns:
- the type of argument at index position
-
getTemplateParameterOfInterface
public static Class getTemplateParameterOfInterface(Class base, Class desiredInterface)
-
isCompatible
public static boolean isCompatible(Method method, Method intfMethod)
See if the two methods are compatible, that is they have the same relative signature.- Parameters:
method
- first methodintfMethod
- second method- Returns:
- boolean result
-
getImplementingMethod
public static Method getImplementingMethod(Class clazz, Method intfMethod)
Given a method and a root class, find the actual method declared in the root that implements the method.- Parameters:
clazz
- classintfMethod
- method- Returns:
- method in the root class
-
getImplementedInterfaceMethod
public static Method getImplementedInterfaceMethod(Class<?> root, Class<?> iface, Method implementation)
Find the by a method implementation implemented interface method.- Parameters:
root
- The root class of the class hierarchy.iface
- The containing interface of the implemented method in the class hierarchy.implementation
- The method implementation.- Returns:
- The implemented method.
-
findOverriddenMethod
public static Method findOverriddenMethod(Class<?> root, Class<?> superClass, Method implementation)
Find the by a method implementation overridden superclass method.- Parameters:
root
- The root class of the class hierarchy.superClass
- The containing class of the overridden method in the class hierarchy.implementation
- The method implementation.- Returns:
- The overridden method.
-
getTypeArgument
public static Class<?> getTypeArgument(Type genericType)
Returns the type argument from a parameterized type.- Parameters:
genericType
- type- Returns:
- null if there is no type parameter
-
isGenericTypeInstanceOf
public static boolean isGenericTypeInstanceOf(Class<?> c, Type type)
Checks that the given class,c
, is the generic type of the given type.- Parameters:
c
- the class the type is checked againsttype
- the type to check- Returns:
true
if the type is notnull
and is assignable from the class- See Also:
Class.isAssignableFrom(Class)
-
resolveTypeVariable
public static Type resolveTypeVariable(Class<?> root, TypeVariable<?> typeVariable)
Finds an actual value of a type variable. The method looks in a class hierarchy for a class defining the variable and returns the value if present.- Parameters:
root
- root classtypeVariable
- type variable- Returns:
- actual type of the type variable
-
getActualTypeArgumentsOfAnInterface
public static Type[] getActualTypeArgumentsOfAnInterface(Class<?> classToSearch, Class<?> interfaceToFind)
Given a class and an interfaces, go through the class hierarchy to find the interface and return its type arguments.- Parameters:
classToSearch
- classinterfaceToFind
- interface to find- Returns:
- type arguments of the interface
-
findParameterizedTypes
public static Type[] findParameterizedTypes(Class<?> root, Class<?> searchedFor)
Search for the given interface or class within the root's class/interface hierarchy. If the searched for class/interface is a generic return an array of real types that fill it out.- Parameters:
root
- root classsearchedFor
- searched class- Returns:
- for generic class/interface returns array of real types
-
findClassParameterizedTypes
public static Type[] findClassParameterizedTypes(Class<?> root, ParameterizedType rootType, Class<?> searchedForClass)
-
populateParameterizedMap
public static Map<TypeVariable<?>,Type> populateParameterizedMap(Class<?> root, Class<?> superClass)
Create a mapping for generic types to actual types between two classes / interfaces of a type hierarchy.- Parameters:
root
- The root class / interface of the type hierarchy.superClass
- A superclass / interface of the type hierarchy.- Returns:
- The Mapping for generic types to actual types.
-
findInterfaceParameterizedTypes
public static Type[] findInterfaceParameterizedTypes(Class<?> root, ParameterizedType rootType, Class<?> searchedForInterface)
-
hasPostConstruct
public static boolean hasPostConstruct(Class<?> clazz)
-
-