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

public Class Reflections

extends Object
Class Inheritance
Imports
java.beans.Introspector, java.io.Serializable, java.lang.annotation.Annotation, java.lang.reflect.AccessibleObject, .Constructor, .Field, .InvocationTargetException, .Member, .Method, .Modifier, .ParameterizedType, .Type, .TypeVariable, .WildcardType, java.security.AccessController, java.util.Arrays, .HashMap, .HashSet, .List, .Map, .Set

Utility class for working with JDK Reflection and also CDI's {link Annotated} metadata.

Field Summary

Modifier and TypeField and Description
public static final Annotation[]
EMPTY_ANNOTATION_ARRAY

An empty array of type java.lang.annotation.Annotation, useful converting lists to arrays.

public static final Class<?>[]
public static final Object[]
EMPTY_OBJECT_ARRAY

An empty array of type Object, useful for converting lists to arrays.

public static final Type[]

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static String
private static String
private static String
public static Map<Class<?>, Type>
public static <
the type to cast to
T
>
T

Returns:

the casted object
cast
(Object
the object to perform the cast on
obj
)

Perform a runtime cast.

public static <T> Class<T>

Returns:

the class object
classForName
(String
the name of the class to load
name
,
ClassLoader...
additional classloaders to use to attempt to load the class
loaders
)

Loads and initializes a class for the given name.

public static boolean
public static Constructor<?>

Returns:

The constructor found, or null if no constructor is found
findDeclaredConstructor
(Class<?>
The class to search
clazz
,
Class<?>...
The arguments of the constructor to search for
args
)

Search the class hierarchy for a constructor with the given arguments.

public static Field

Returns:

The field found, or null if no field is found
findDeclaredField
(Class<?>
The class to search
clazz
,
String
The name of the field to search for
name
)

Search the class hierarchy for a field with the given name.

public static Method

Returns:

The method found, or null if no method is found
findDeclaredMethod
(Class<?>
The class to search
clazz
,
String
The name of the method to search for
name
,
Class<?>...
The arguments of the method to search for
args
)

Search the class hierarchy for a method with the given name and arguments.

public static Set<Constructor<?>>

Returns:

the set of all declared constructors or an empty set if there are none
getAllDeclaredConstructors
(Class<?>
The class to search
clazz
)

Get all the declared constructors on the class hierarchy.

public static Set<Field>

Returns:

the set of all declared fields or an empty set if there are none
getAllDeclaredFields
(Class<?>
The class to search
clazz
)

Get all the declared fields on the class hierarchy.

public static Set<Method>

Returns:

the set of all declared methods or an empty set if there are none
getAllDeclaredMethods
(Class<?>
The class to search
clazz
)

Get all the declared methods on the class hierarchy.

public static Set<Annotation>

Returns:

The set of annotations with the specified meta annotation, or an empty set if none are found
getAnnotationsWithMetaAnnotation
(Set<Annotation>
The annotation set to search
annotations
,
Class<? extends Annotation>
The type of the meta annotation to search for
metaAnnotationType
)

Search for annotations with the specified meta annotation type

public static Object
getFieldValue(Field field, Object instance)

public static <
the type of the field's value
T
>
T

Returns:

the value of the field
getFieldValue
(Field
the field to operate on
field
,
Object
the instance from which to retrieve the value
instance
,
Class<T>
the expected type of the field's value
expectedType
)

Get the value of the field, on the specified instance, casting the value of the field to the expected type.

public static Class<?>

Returns:

The type of the member
getMemberType
(Member
The member
member
)

Get the type of the member

public static int
getNesting(Class<?> clazz)

public static Object
public static String

Returns:

The name of the property. Returns null if method wasn't JavaBean getter-styled
getPropertyName
(Method
The getter method
method
)

Gets the property name from a getter method.

public static <
the type
T
>
Class<T>

Returns:

the raw type, or null if the raw type cannot be determined.
getRawType
(Type
the type to extract the raw type from
type
)

Extract the raw type, given a type.

public static Object
invokeMethod(Method method, Object instance, Object... args)

Invoke the specified method on the provided instance, passing any additional arguments included in this method as arguments to the specified method.

public static Object
invokeMethod(boolean setAccessible, Method method, Object instance, Object... args)

Invoke the specified method on the provided instance, passing any additional arguments included in this method as arguments to the specified method.

public static <T> T
invokeMethod(Method method, Class<T> expectedReturnType, Object instance, Object... args)

Invoke the specified method on the provided instance, passing any additional arguments included in this method as arguments to the specified method.

public static <T> T

Returns:

the result of invoking the method, or null if the method's return type is void
invokeMethod
(boolean
flag indicating whether method should first be set as accessible
setAccessible
,
Method
the method to invoke
method
,
Class<T> expectedReturnType, Object
the instance to invoke the method
instance
,
Object...
the arguments to the method
args
)

Invoke the method on the instance, with any arguments specified, casting the result of invoking the method to the expected return type.

public static boolean
isAbstract(Method method)

Checks if a method is abstract

public static boolean

Returns:

True if array, false otherwise
isArrayType
(Class<?>
The raw type to check
rawType
)

Checks if raw type is array type

public static boolean
isAssignableFrom(Class<?>
the raw type of the class to check
rawType1
,
Type[]
the actual type arguements to check, or an empty array if not a parameterized type
actualTypeArguments1
,
Class<?>
the raw type of the class to check
rawType2
,
Type[]
the actual type arguements to check, or an empty array if not a parameterized type
actualTypeArguments2
)

Check the assignability of one type to another, taking into account the actual type arguements

public static boolean
isAssignableFrom(Type[] actualTypeArguments1, Type[] actualTypeArguments2)

public static boolean
isAssignableFrom(Type type1, Set<? extends Type> types2)

public static boolean
isAssignableFrom(Type type1, Type[] types2)

public static boolean
isAssignableFrom(Type type1, Type type2)

public static boolean
isAssignableFrom(Class<?> rawType1, Type[] actualTypeArguments1, Type type2)

public static boolean
isAssignableFrom(Set<Type> types1, Set<Type> types2)

Check the assiginability of a set of flattened types.

public static boolean
isAssignableFrom(Set<Type> types1, Type type2)

Check the assignability of a set of flattened types.

public static boolean
isAssignableFrom(Type[] types1, Type type2)

public static boolean
isCacheable(Set<Annotation> annotations)

public static boolean
isCacheable(Annotation[] annotations)

public static boolean

Returns:

True if final, false otherwise
isFinal
(Class<?>
The class to check
clazz
)

Checks if class is final

public static boolean

Returns:

True if final, false otherwise
isFinal
(Member
The member to check
member
)

Checks if member is final

public static boolean
public static boolean
public static boolean

Returns:

True if parameterized, false otherwise
isParameterizedType
(Class<?>
The type to check
type
)

Checks if type is parameterized type

public static boolean
public static boolean

Returns:

True if final, false otherwise
isPrivate
(Member
The member to check
member
)

Checks if member is private

public static boolean

Returns:

true if the class implements serializable or is a primitive
isSerializable
(Class<?>
The class to check
clazz
)

Check if a class is serializable.

public static boolean

Returns:

True if static, false otherwise
isStatic
(Class<?>
Type to check
type
)

Checks if type is static

public static boolean

Returns:

True if static, false otherwise
isStatic
(Member
Member to check
member
)

Checks if member is static

public static boolean
public static boolean
isTypeBounded(Type type, Type[] lowerBounds, Type[] upperBounds)

public static boolean

Returns:

True if final, false otherwise
isTypeOrAnyMethodFinal
(Class<?>
Type or member
type
)

Checks if type or member is final

public static boolean
matches(Class<?> rawType1, Type[] actualTypeArguments1, Class<?> rawType2, Type[] actualTypeArguments2)

public static boolean
matches(Type type1, Set<? extends Type> types2)

public static boolean
matches(Type type1, Type type2)

public static boolean
matches(Class<?> rawType1, Type[] actualTypeArguments1, Type type2)

public static boolean
matches(Set<Type> types1, Set<Type> types2)

Check whether whether any of the types1 matches a type in types2

public static boolean

Returns:

true if a method is found, otherwise false
methodExists
(Class<?>
The class to search
clazz
,
String
The name of the method
name
)

Determine if a method exists in a specified class hierarchy

public static <T> T

Returns:

A newly allocated instance of the class.
newInstance
(final Class<T>
The class from where the instance should be created.
fromClass
)

Creates a new instance of a class.

public static <T> T

Returns:

A newly allocated instance of the class.
newInstance
(final Class<?>
The class that will be used to get the class loader from.
type
,
final String
The full qualified name of the class from which the instance will be created.
fullQualifiedName
)

Creates a new instance of a class given its fullQualifiedName.

public static Class<?>

Returns:

if the field is not a List, it returns null. Otherwise the type of items of the list. If the type for items can not be inferred, the Object type is returned.
resolveListType
(Field
the field declared as List
field
,
Object
the instance that should be used to obtain infer the type in case no parametrized type is found in the field.
instance
)

Resolves the type of items for a Field declared as a List.

public static <
member the accessible object type
A extends AccessibleObject
>
A

Returns:

the accessible object after the accessible flag has been altered
setAccessible
(A
the accessible object
member
)

Set the accessibility flag on the AccessibleObject as described in AccessibleObject#setAccessible(boolean) within the context of a {link PrivilegedAction}.

public static <
member the accessible object type
A extends AccessibleObject
>
A

Returns:

the accessible object after the accessible flag has been altered
unsetAccessible
(A
the accessible object
member
)

Set the accessibility flag on the AccessibleObject to false as described in AccessibleObject#setAccessible(boolean) within the context of a {link PrivilegedAction}.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait