Top Description Fields Constructors Methods
org.keycloak.common.util.reflections

public Class Types

extends Object
Class Inheritance
Imports
java.lang.reflect.Array, .GenericArrayType, .Method, .ParameterizedType, .Type, .TypeVariable, java.util.HashMap, .Map

Utility class for Types

Field Summary

Modifier and TypeField and Description
private static final Type[]

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Class<?>
boxedClass(Class<?> type)

public static Type

Returns:

The boxed type
boxedType
(Type
The type
type
)

Gets the boxed type of a class

private static Type[]
extractTypes(Map<String, Type> typeVarMap, Type genericSub)

private static Type[]
extractTypeVariables(Map<String, Type> typeVarMap, Type[] types)

public static Type[]
findClassParameterizedTypes(Class<?> root, ParameterizedType rootType, Class<?> searchedForClass)

public static Type[]
findInterfaceParameterizedTypes(Class<?> root, ParameterizedType rootType, Class<?> searchedForInterface)

public static Type[]
findParameterizedTypes(Class<?> root, Class<?> searchedFor)

Search for the given interface or class within the root's class/interface hierarchy.

public static Type[]

Returns:

type arguments of the interface
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.

public static Class<T>
getArgumentType(ParameterizedType pType, int index)

Gets the index-th type argument.

public static Class<T>
getCollectionBaseType(Class<T> type, Type genericType)

public static Method
getImplementingMethod(Class<T> clazz, Method intfMethod)

Given a method and a root class, find the actual method declared in the root that implements the method.

public static Class<T>
getMapKeyType(Type genericType)

public static Class<T>
getMapValueType(Type genericType)

public static Class<?>
public static Class<?>
public static Class<T>
getTemplateParameterOfInterface(Class<T> base, Class<T> desiredInterface)

public static Class<?>

Returns:

null if there is no type parameter
getTypeArgument
(Type genericType)

Returns the type argument from a parameterized type

public static boolean
isA(Class<T> clazz, ParameterizedType pType)

Is the genericType of a certain class?

public static boolean
isCompatible(Method method, Method intfMethod)

See if the two methods are compatible, that is they have the same relative signature

private static Map<String, Type>
private static Type[]
recurseSuperclassForInterface(Class<?> searchedForInterface, Map<String, Type> typeVarMap, Type genericSub, Class<?> sub)

public static Type

Returns:

actual type of the type variable
resolveTypeVariable
(Class<?> root, TypeVariable<?> typeVariable)

Finds an actual value of a type variable.

public static Type
private static Object
searchForInterfaceTemplateParameter(Class<T> base, Class<T> desiredInterface)

public static <T> boolean
supports(Class<T> type, Object object, Class<?> fromInterface)

Grabs the parameterized type of fromInterface that object implements and sees if it is assignable from type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTY_TYPE_ARRAYback to summary
private static final Type[] EMPTY_TYPE_ARRAY

Constructor Detail

Typesback to summary
private Types()

Method Detail

boxedClassback to summary
public static Class<?> boxedClass(Class<?> type)
boxedTypeback to summary
public static Type boxedType(Type type)

Gets the boxed type of a class

Parameters
type:Type

The type

Returns:Type

The boxed type

extractTypesback to summary
private static Type[] extractTypes(Map<String, Type> typeVarMap, Type genericSub)
extractTypeVariablesback to summary
private static Type[] extractTypeVariables(Map<String, Type> typeVarMap, Type[] types)
findClassParameterizedTypesback to summary
public static Type[] findClassParameterizedTypes(Class<?> root, ParameterizedType rootType, Class<?> searchedForClass)
findInterfaceParameterizedTypesback to summary
public static Type[] findInterfaceParameterizedTypes(Class<?> root, ParameterizedType rootType, Class<?> searchedForInterface)
findParameterizedTypesback to summary
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.

getActualTypeArgumentsOfAnInterfaceback to summary
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.

Returns:Type[]

type arguments of the interface

getArgumentTypeback to summary
public static Class<T> getArgumentType(ParameterizedType pType, int index)

Gets the index-th type argument.

getCollectionBaseTypeback to summary
public static Class<T> getCollectionBaseType(Class<T> type, Type genericType)
getImplementingMethodback to summary
public static Method getImplementingMethod(Class<T> clazz, Method intfMethod)

Given a method and a root class, find the actual method declared in the root that implements the method.

getMapKeyTypeback to summary
public static Class<T> getMapKeyType(Type genericType)
getMapValueTypeback to summary
public static Class<T> getMapValueType(Type genericType)
getRawTypeback to summary
public static Class<?> getRawType(Type type)
getRawTypeNoExceptionback to summary
public static Class<?> getRawTypeNoException(Type type)
getTemplateParameterOfInterfaceback to summary
public static Class<T> getTemplateParameterOfInterface(Class<T> base, Class<T> desiredInterface)
getTypeArgumentback to summary
public static Class<?> getTypeArgument(Type genericType)

Returns the type argument from a parameterized type

Returns:Class<?>

null if there is no type parameter

isAback to summary
public static boolean isA(Class<T> clazz, ParameterizedType pType)

Is the genericType of a certain class?

isCompatibleback to summary
public static boolean isCompatible(Method method, Method intfMethod)

See if the two methods are compatible, that is they have the same relative signature

populateParameterizedMapback to summary
private static Map<String, Type> populateParameterizedMap(Class<?> root, ParameterizedType rootType)
recurseSuperclassForInterfaceback to summary
private static Type[] recurseSuperclassForInterface(Class<?> searchedForInterface, Map<String, Type> typeVarMap, Type genericSub, Class<?> sub)
resolveTypeVariableback to summary
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.

Returns:Type

actual type of the type variable

resolveTypeVariablesback to summary
public static Type resolveTypeVariables(Class<?> root, Type type)
searchForInterfaceTemplateParameterback to summary
private static Object searchForInterfaceTemplateParameter(Class<T> base, Class<T> desiredInterface)
supportsback to summary
public static <T> boolean supports(Class<T> type, Object object, Class<?> fromInterface)

Grabs the parameterized type of fromInterface that object implements and sees if it is assignable from type.