public class ReflectionUtils extends org.springframework.util.ReflectionUtils
org.springframework.util.ReflectionUtils.FieldCallback, org.springframework.util.ReflectionUtils.FieldFilter, org.springframework.util.ReflectionUtils.MethodCallback, org.springframework.util.ReflectionUtils.MethodFilter
Constructor and Description |
---|
ReflectionUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
copyProperty(Object bean,
String name,
Object value) |
static Map<String,Object> |
describe(Object bean) |
static com.google.common.base.Optional<Object> |
extractFieldValue(Field field,
Object instance)
Unconditionally attempt to get the value of this field on this bean.
|
static com.google.common.base.Optional<Object> |
get(Field field,
Object instance)
Deprecated.
Use extractFieldValue instead
|
static Set<Field> |
getAllFields(Class<?> type)
Recursively examine the type hierarchy and extract every field encountered anywhere in the hierarchy into an immutable set
|
static List<Field> |
getAllFieldsList(Class<?> type)
Recursively examine the type hierarchy and extract every field encountered anywhere in the hierarchy into an immutable list
|
static List<Type> |
getAllGenericInterfaces(Class<?> type)
Return a list containing every interface implemented by
type , includes interfaces implemented by super classes. |
static Map<Class<?>,ParameterizedType> |
getAllParameterizedInterfaces(Class<?> type)
Return a map containing every parameterized interface implemented by
type , includes interfaces implemented by super classes |
static <T extends Annotation> |
getAnnotation(Class<?> type,
Class<T> annotationClass)
Deprecated.
Use Annotations.get() instead
|
static <T extends Annotation> |
getAnnotation(Field field,
Class<T> annotationClass)
Deprecated.
Use Annotations.get() instead
|
static Class<?> |
getClass(String className) |
static List<Class<?>> |
getDeclarationHierarchy(Class<?> type) |
static String |
getDeclarationPath(Class<?> type) |
static Set<Field> |
getFields(Class<?> type)
Get fields declared directly on this type as an immutable set.
|
static Set<Field> |
getFields(Class<?> type,
boolean includeInheritedFields)
Get fields for a given type with the option to include all inherited fields
|
static Map<String,Field> |
getFields(Class<?> type,
Set<String> fieldNames)
Return the field corresponding
|
static Map<String,Field> |
getNameMap(List<Field> fields)
Convert the list of fields into a Map keyed by field name.
|
static Map<String,Field> |
getNameMap(Set<Field> fields)
Deprecated.
use getNameMap(List) instead
|
static <T> Class<? extends T> |
getTypedClass(String className) |
static List<Class<?>> |
getTypeHierarchy(Class<?> type)
Returns the path from
java.lang.Object , to type . |
static Map<String,Field> |
getUniqueFieldNames(Class<?> type)
Get a list of all fields contained anywhere in the type hierarchy keyed by field name.
|
protected static boolean |
hasMatchingActualTypeArguments(ParameterizedType type,
Class<?>... expectedTypeArguments) |
static boolean |
hasMatchingParameterizedArgTypes(Field field,
Class<?>... expectedTypeArguments)
Return true if this field is a generic whose argument types match
expectedTypeArguments |
static boolean |
hasUniqueFieldNames(Class<?> type)
Return true if every single field in the recursive type hiearchy has a unique name, false otherwise
|
static boolean |
hasUniqueFieldNames(List<Field> fields) |
static boolean |
hasUniqueFieldNames(Set<Field> fields)
Return true if the fields in this set can be uniquely represented by field name alone
|
static Object |
invoke(org.springframework.util.MethodInvoker invoker) |
static Object |
invokeMethod(Class<?> targetClass,
String targetMethod,
Object... arguments) |
static Object |
invokeMethod(Object targetObject,
String targetMethod,
Object... arguments) |
static boolean |
isCharSequence(Class<?> type)
Return true if this field is a CharSequence
|
static boolean |
isCharSequence(Field field)
Return true if this field is a CharSequence
|
static boolean |
isCollection(Field field)
Return true if this field is a
java.util.Collection |
static boolean |
isFinal(Class<?> type)
Return true if this class is declared as final
|
static boolean |
isFinal(Field field)
Return true if this field is declared as final
|
static boolean |
isImmutableGuavaCollection(Class<?> type)
Return true if this class is an immutable Guava collection
|
static boolean |
isImmutableGuavaMap(Class<?> type)
Return true if this class is an immutable Guava map
|
static boolean |
isMap(Field field)
Return true if this field is a
java.util.Map |
static boolean |
isOptional(Field field)
Return true iff this field is a Guava
com.google.common.base.Optional |
static boolean |
isOptionalString(Field field)
Return true iff this field is a Guava
com.google.common.base.Optional<String> |
static boolean |
isString(Field field)
Return true if this field is a
java.lang.String |
static boolean |
isStringCollection(Field field)
Return true if this field is a
java.util.Collection<String> |
static boolean |
isStringKeyedMap(Field field)
Return true if this field extends from
java.util.Map and uses String for its keys |
static boolean |
isSuperType(Class<?> superType,
Class<?> type)
Return true if
type descends from superType OR is the same as superType . |
static <T> T |
newInstance(Class<T> instanceClass) |
static <T> T |
newInstance(String className) |
static void |
set(Object instance,
Field field,
Object value)
Unconditionally attempt to set a value on this field of this instance.
|
static void |
validateIsSuperType(Class<?> superType,
Class<?> type)
Throw an exception unless
child is the same as parent OR descends from parent . |
declaresException, doWithFields, doWithFields, doWithMethods, doWithMethods, findField, findField, findMethod, findMethod, getAllDeclaredMethods, getField, getUniqueDeclaredMethods, handleInvocationTargetException, handleReflectionException, invokeJdbcMethod, invokeJdbcMethod, invokeMethod, invokeMethod, isCglibRenamedMethod, isEqualsMethod, isHashCodeMethod, isObjectMethod, isPublicStaticFinal, isToStringMethod, makeAccessible, makeAccessible, makeAccessible, rethrowException, rethrowRuntimeException, setField, shallowCopyFieldState
public ReflectionUtils()
public static List<Class<?>> getTypeHierarchy(Class<?> type)
java.lang.Object
, to type
. The last element in the list is type
.public static Map<Class<?>,ParameterizedType> getAllParameterizedInterfaces(Class<?> type)
type
, includes interfaces implemented by super classespublic static List<Type> getAllGenericInterfaces(Class<?> type)
type
, includes interfaces implemented by super classes. Type objects returned accurately reflect the actual
type parameters used in the source code.public static boolean isImmutableGuavaCollection(Class<?> type)
public static boolean isImmutableGuavaMap(Class<?> type)
public static boolean isCollection(Field field)
java.util.Collection
public static boolean isStringCollection(Field field)
java.util.Collection<String>
public static boolean isStringKeyedMap(Field field)
java.util.Map
and uses String
for its keys
Map<String,String> returns true Map<String,Object> returns true Map<String,Integer> returns true Map<Integer,String> returns false
public static boolean isString(Field field)
java.lang.String
public static boolean isCharSequence(Field field)
public static boolean isCharSequence(Class<?> type)
public static boolean isOptional(Field field)
com.google.common.base.Optional
public static boolean isOptionalString(Field field)
com.google.common.base.Optional<String>
public static boolean hasMatchingParameterizedArgTypes(Field field, Class<?>... expectedTypeArguments)
Return true if this field is a generic whose argument types match expectedTypeArguments
Collection<String>
hasMatchingParameterizedArgTypes(myField, String.class)
protected static boolean hasMatchingActualTypeArguments(ParameterizedType type, Class<?>... expectedTypeArguments)
public static void validateIsSuperType(Class<?> superType, Class<?> type)
Throw an exception unless child
is the same as parent
OR descends from parent
. If child
is a primitive type, throw an exception unless
both child
and parent
are the exact same primitive type.
IllegalArgumentException
- if equalsOrDescendsFrom(child,parent)
returns false
equalsOrDescendsFrom
public static boolean isSuperType(Class<?> superType, Class<?> type)
Return true if type
descends from superType
OR is the same as superType
. If type
is a primitive type, return true
only if both
type
and superType
are the exact same primitive type.
@Deprecated public static <T extends Annotation> com.google.common.base.Optional<T> getAnnotation(Class<?> type, Class<T> annotationClass)
@Deprecated public static <T extends Annotation> com.google.common.base.Optional<T> getAnnotation(Field field, Class<T> annotationClass)
public static List<Class<?>> getDeclarationHierarchy(Class<?> type)
public static String getDeclarationPath(Class<?> type)
public static com.google.common.base.Optional<Object> extractFieldValue(Field field, Object instance)
@Deprecated public static com.google.common.base.Optional<Object> get(Field field, Object instance)
public static void set(Object instance, Field field, Object value)
public static Set<Field> getFields(Class<?> type)
public static Set<Field> getFields(Class<?> type, boolean includeInheritedFields)
NOTE: field.getName() is not necessarily unique for the elements in the set if includeInheritedFields is true
@Deprecated public static Map<String,Field> getNameMap(Set<Field> fields)
public static Map<String,Field> getNameMap(List<Field> fields)
public static Map<String,Field> getUniqueFieldNames(Class<?> type)
IllegalArgumentException
- if type
contains duplicate field namespublic static Map<String,Field> getFields(Class<?> type, Set<String> fieldNames)
type
- fieldNames
- public static Set<Field> getAllFields(Class<?> type)
Recursively examine the type hierarchy and extract every field encountered anywhere in the hierarchy into an immutable set
NOTE: field.getName() is not necessarily unique for the elements in the set
public static List<Field> getAllFieldsList(Class<?> type)
Recursively examine the type hierarchy and extract every field encountered anywhere in the hierarchy into an immutable list
NOTE: field.getName() is not necessarily unique for the elements in the list
public static boolean hasUniqueFieldNames(Class<?> type)
public static boolean hasUniqueFieldNames(Set<Field> fields)
public static boolean hasUniqueFieldNames(List<Field> fields)
public static void copyProperty(Object bean, String name, Object value)
public static Object invokeMethod(Class<?> targetClass, String targetMethod, Object... arguments)
public static Object invokeMethod(Object targetObject, String targetMethod, Object... arguments)
public static <T> Class<? extends T> getTypedClass(String className)
public static <T> T newInstance(String className)
public static <T> T newInstance(Class<T> instanceClass)
Copyright © 2010–2014 The Kuali Foundation. All rights reserved.