java.lang.Object | |
↳ | org.springframework.util.ReflectionUtils |
Simple utility class for working with the reflection API and handling reflection exceptions.
Only intended for internal use.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
ReflectionUtils.FieldCallback | Callback interface invoked on each field in the hierarchy. | ||||||||||
ReflectionUtils.FieldFilter | Callback optionally used to filter fields to be operated on by a field callback. | ||||||||||
ReflectionUtils.MethodCallback | Action to take on each method. | ||||||||||
ReflectionUtils.MethodFilter | Callback optionally used to method fields to be operated on by a method callback. |
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
COPYABLE_FIELDS | Pre-built FieldFilter that matches all non-static, non-final fields. | ||||||||||
NON_BRIDGED_METHODS | Pre-built MethodFilter that matches all non-bridge methods. | ||||||||||
USER_DECLARED_METHODS | Pre-built MethodFilter that matches all non-bridge methods
which are not declared on java.lang.Object . |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Determine whether the given method explicitly declares the given
exception or one of its superclasses, which means that an exception of
that type can be propagated as-is within a reflective invocation.
| |||||||||||
Invoke the given callback on all fields in the target class, going up the
class hierarchy to get all declared fields.
| |||||||||||
Invoke the given callback on all fields in the target class, going up the
class hierarchy to get all declared fields.
| |||||||||||
Perform the given callback operation on all matching methods of the given
class and superclasses (or given interface and super-interfaces).
| |||||||||||
Perform the given callback operation on all matching methods of the given
class and superclasses.
| |||||||||||
Attempt to find a
Method on the supplied class with the supplied name
and no parameters. | |||||||||||
Attempt to find a
Method on the supplied class with the supplied name
and parameter types. | |||||||||||
Get all declared methods on the leaf class and all superclasses.
| |||||||||||
Get the field represented by the supplied
field object on the
specified target object . | |||||||||||
Handle the given invocation target exception.
| |||||||||||
Handle the given reflection exception.
| |||||||||||
Invoke the specified JDBC API
Method against the supplied target
object with no arguments. | |||||||||||
Invoke the specified JDBC API
Method against the supplied target
object with the supplied arguments. | |||||||||||
Invoke the specified
Method against the supplied target object with no arguments. | |||||||||||
Invoke the specified
Method against the supplied target object with the
supplied arguments. | |||||||||||
Determine whether the given method is an "equals" method.
| |||||||||||
Determine whether the given method is a "hashCode" method.
| |||||||||||
Determine whether the given method is originally declared by
Object . | |||||||||||
Determine whether the given field is a "public static final" constant.
| |||||||||||
Determine whether the given method is a "toString" method.
| |||||||||||
Make the given field accessible, explicitly setting it accessible if
necessary.
| |||||||||||
Make the given constructor accessible, explicitly setting it accessible
if necessary.
| |||||||||||
Make the given method accessible, explicitly setting it accessible if
necessary.
| |||||||||||
Rethrow the given
exception , which is presumably the
target exception of an InvocationTargetException . | |||||||||||
Rethrow the given
exception , which is presumably the
target exception of an InvocationTargetException . | |||||||||||
Set the field represented by the supplied
field object on the
specified target object to the specified value . | |||||||||||
Given the source object and the destination, which must be the same class
or a subclass, copy all fields, including inherited fields.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Pre-built FieldFilter that matches all non-static, non-final fields.
Pre-built MethodFilter that matches all non-bridge methods.
Pre-built MethodFilter that matches all non-bridge methods
which are not declared on java.lang.Object
.
Determine whether the given method explicitly declares the given exception or one of its superclasses, which means that an exception of that type can be propagated as-is within a reflective invocation.
method | the declaring method |
---|---|
exceptionType | the exception to throw |
true
if the exception can be thrown as-is;
false
if it needs to be wrapped
Invoke the given callback on all fields in the target class, going up the class hierarchy to get all declared fields.
clazz | the target class to analyze |
---|---|
fc | the callback to invoke for each field |
IllegalArgumentException |
---|
Invoke the given callback on all fields in the target class, going up the class hierarchy to get all declared fields.
clazz | the target class to analyze |
---|---|
fc | the callback to invoke for each field |
ff | the filter that determines the fields to apply the callback to |
IllegalArgumentException |
---|
Perform the given callback operation on all matching methods of the given class and superclasses (or given interface and super-interfaces).
The same named method occurring on subclass and superclass will appear
twice, unless excluded by the specified ReflectionUtils.MethodFilter
.
clazz | class to start looking at |
---|---|
mc | the callback to invoke for each method |
mf | the filter that determines the methods to apply the callback to |
IllegalArgumentException |
---|
Perform the given callback operation on all matching methods of the given class and superclasses.
The same named method occurring on subclass and superclass will appear
twice, unless excluded by a ReflectionUtils.MethodFilter
.
clazz | class to start looking at |
---|---|
mc | the callback to invoke for each method |
IllegalArgumentException |
---|
Attempt to find a field
on the supplied Class
with the
supplied name
and/or type
. Searches all superclasses
up to Object
.
clazz | the class to introspect |
---|---|
name | the name of the field (may be null if type is specified) |
type | the type of the field (may be null if name is specified) |
null
if not found
Attempt to find a Method
on the supplied class with the supplied name
and parameter types. Searches all superclasses up to Object
.
Returns null
if no Method
can be found.
clazz | the class to introspect |
---|---|
name | the name of the method |
paramTypes | the parameter types of the method
(may be null to indicate any signature) |
null
if none found
Get all declared methods on the leaf class and all superclasses. Leaf class methods are included first.
IllegalArgumentException |
---|
Get the field represented by the supplied field object
on the
specified target object
. In accordance with get(Object)
semantics, the returned value is automatically wrapped if the underlying field
has a primitive type.
Thrown exceptions are handled via a call to handleReflectionException(Exception)
.
field | the field to get |
---|---|
target | the target object from which to get the field |
Handle the given invocation target exception. Should only be called if no checked exception is expected to be thrown by the target method.
Throws the underlying RuntimeException or Error in case of such a root cause. Throws an IllegalStateException else.
ex | the invocation target exception to handle |
---|
Handle the given reflection exception. Should only be called if no checked exception is expected to be thrown by the target method.
Throws the underlying RuntimeException or Error in case of an InvocationTargetException with such a root cause. Throws an IllegalStateException with an appropriate message else.
ex | the reflection exception to handle |
---|
Invoke the specified JDBC API Method
against the supplied target
object with no arguments.
method | the method to invoke |
---|---|
target | the target object to invoke the method on |
SQLException | the JDBC API SQLException to rethrow (if any) |
---|
Invoke the specified JDBC API Method
against the supplied target
object with the supplied arguments.
method | the method to invoke |
---|---|
target | the target object to invoke the method on |
args | the invocation arguments (may be null ) |
SQLException | the JDBC API SQLException to rethrow (if any) |
---|
Invoke the specified Method
against the supplied target object with no arguments.
The target object can be null
when invoking a static Method
.
Thrown exceptions are handled via a call to handleReflectionException(Exception)
.
method | the method to invoke |
---|---|
target | the target object to invoke the method on |
Invoke the specified Method
against the supplied target object with the
supplied arguments. The target object can be null
when invoking a
static Method
.
Thrown exceptions are handled via a call to handleReflectionException(Exception)
.
method | the method to invoke |
---|---|
target | the target object to invoke the method on |
args | the invocation arguments (may be null ) |
Determine whether the given method is an "equals" method.
Determine whether the given method is a "hashCode" method.
Determine whether the given method is originally declared by Object
.
Determine whether the given field is a "public static final" constant.
field | the field to check |
---|
Determine whether the given method is a "toString" method.
Make the given field accessible, explicitly setting it accessible if
necessary. The setAccessible(true)
method is only called
when actually necessary, to avoid unnecessary conflicts with a JVM
SecurityManager (if active).
field | the field to make accessible |
---|
Make the given constructor accessible, explicitly setting it accessible
if necessary. The setAccessible(true)
method is only called
when actually necessary, to avoid unnecessary conflicts with a JVM
SecurityManager (if active).
ctor | the constructor to make accessible |
---|
Make the given method accessible, explicitly setting it accessible if
necessary. The setAccessible(true)
method is only called
when actually necessary, to avoid unnecessary conflicts with a JVM
SecurityManager (if active).
method | the method to make accessible |
---|
Rethrow the given exception
, which is presumably the
target exception of an InvocationTargetException
. Should
only be called if no checked exception is expected to be thrown by the
target method.
Rethrows the underlying exception cast to an Exception
or
Error if appropriate; otherwise, throws an
IllegalStateException
.
ex | the exception to rethrow |
---|
Exception | the rethrown exception (in case of a checked exception) |
---|
Rethrow the given exception
, which is presumably the
target exception of an InvocationTargetException
. Should
only be called if no checked exception is expected to be thrown by the
target method.
Rethrows the underlying exception cast to an RuntimeException
or
Error if appropriate; otherwise, throws an
IllegalStateException
.
ex | the exception to rethrow |
---|
RuntimeException | the rethrown exception |
---|
Set the field represented by the supplied field object
on the
specified target object
to the specified value
.
In accordance with set(Object, Object)
semantics, the new value
is automatically unwrapped if the underlying field has a primitive type.
Thrown exceptions are handled via a call to handleReflectionException(Exception)
.
field | the field to set |
---|---|
target | the target object on which to set the field |
value | the value to set; may be null
|
Given the source object and the destination, which must be the same class or a subclass, copy all fields, including inherited fields. Designed to work on objects with public no-arg constructors.
IllegalArgumentException | if the arguments are incompatible |
---|