abstract class ReflectionUtils
Simple utility class for working with the reflection API and handling reflection exceptions.
Only intended for internal use.
Author
Juergen Hoeller
Author
Rob Harrop
Author
Rod Johnson
Author
Costin Leau
Author
Sam Brannen
Author
Chris Beams
Since
1.2.2
ReflectionUtils()
Simple utility class for working with the reflection API and handling reflection exceptions. Only intended for internal use. |
static val COPYABLE_FIELDS: FieldFilter
Pre-built FieldFilter that matches all non-static, non-final fields. |
|
static val NON_BRIDGED_METHODS: MethodFilter
Pre-built MethodFilter that matches all non-bridge methods. |
|
static val USER_DECLARED_METHODS: MethodFilter
Pre-built MethodFilter that matches all non-bridge methods which are not declared on |
open static fun <T : Any> accessibleConstructor(clazz: Class<T>, vararg parameterTypes: Class<*>): Constructor<T>
Obtain an accessible constructor for the given class and parameters. |
|
open static fun clearCache(): Unit
Clear the internal method/field cache. |
|
open static fun declaresException(method: Method, exceptionType: Class<*>): Boolean
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. |
|
open static fun doWithFields(clazz: Class<*>, fc: FieldCallback): Unitopen static fun doWithFields(clazz: Class<*>, fc: FieldCallback, ff: FieldFilter): Unit
Invoke the given callback on all fields in the target class, going up the class hierarchy to get all declared fields. |
|
open static fun doWithLocalFields(clazz: Class<*>, fc: FieldCallback): Unit
Invoke the given callback on all fields in the target class, going up the class hierarchy to get all declared fields. |
|
open static fun doWithLocalMethods(clazz: Class<*>, mc: MethodCallback): Unit
Perform the given callback operation on all matching methods of the given class, as locally declared or equivalent thereof (such as default methods on Java 8 based interfaces that the given class implements). |
|
open static fun doWithMethods(clazz: Class<*>, mc: MethodCallback): Unit
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 MethodFilter. open static fun doWithMethods(clazz: Class<*>, mc: MethodCallback, mf: MethodFilter): Unit
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 MethodFilter. |
|
open static fun findField(clazz: Class<*>, name: String): Field
Attempt to find a Field on the supplied Class with the supplied open static fun findField(clazz: Class<*>, name: String, type: Class<*>): Field
Attempt to find a Field on the supplied Class with the supplied |
|
open static fun findMethod(clazz: Class<*>, name: String): Method
Attempt to find a Method on the supplied class with the supplied name and no parameters. Searches all superclasses up to Returns open static fun findMethod(clazz: Class<*>, name: String, vararg paramTypes: Class<*>): Method
Attempt to find a Method on the supplied class with the supplied name and parameter types. Searches all superclasses up to Returns |
|
open static fun getAllDeclaredMethods(leafClass: Class<*>): Array<Method>
Get all declared methods on the leaf class and all superclasses. Leaf class methods are included first. |
|
open static fun getField(field: Field, target: Any): Any
Get the field represented by the supplied Field on the specified Object. In accordance with Thrown exceptions are handled via a call to |
|
open static fun getUniqueDeclaredMethods(leafClass: Class<*>): Array<Method>
Get the unique set of declared methods on the leaf class and all superclasses. Leaf class methods are included first and while traversing the superclass hierarchy any methods found with signatures matching a method already included are filtered out. |
|
open static fun handleInvocationTargetException(ex: InvocationTargetException): Unit
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 UndeclaredThrowableException otherwise. |
|
open static fun handleReflectionException(ex: Exception): Unit
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 or UndeclaredThrowableException otherwise. |
|
open static fun invokeJdbcMethod(method: Method, target: Any): Any
Invoke the specified JDBC API Method against the supplied target object with no arguments. open static fun invokeJdbcMethod(method: Method, target: Any, vararg args: Any): Any
Invoke the specified JDBC API Method against the supplied target object with the supplied arguments. |
|
open static fun invokeMethod(method: Method, target: Any): Any
Invoke the specified Method against the supplied target object with no arguments. The target object can be Thrown exceptions are handled via a call to open static fun invokeMethod(method: Method, target: Any, vararg args: Any): Any
Invoke the specified Method against the supplied target object with the supplied arguments. The target object can be Thrown exceptions are handled via a call to |
|
open static fun isCglibRenamedMethod(renamedMethod: Method): Boolean
Determine whether the given method is a CGLIB 'renamed' method, following the pattern "CGLIB$methodName$0". |
|
open static fun isEqualsMethod(method: Method): Boolean
Determine whether the given method is an "equals" method. |
|
open static fun isHashCodeMethod(method: Method): Boolean
Determine whether the given method is a "hashCode" method. |
|
open static fun isObjectMethod(method: Method): Boolean
Determine whether the given method is originally declared by java.lang.Object. |
|
open static fun isPublicStaticFinal(field: Field): Boolean
Determine whether the given field is a "public static final" constant. |
|
open static fun isToStringMethod(method: Method): Boolean
Determine whether the given method is a "toString" method. |
|
open static fun makeAccessible(field: Field): Unit
Make the given field accessible, explicitly setting it accessible if necessary. The open static fun makeAccessible(method: Method): Unit
Make the given method accessible, explicitly setting it accessible if necessary. The open static fun makeAccessible(ctor: Constructor<*>): Unit
Make the given constructor accessible, explicitly setting it accessible if necessary. The |
|
open static fun rethrowException(ex: Throwable): Unit
Rethrow the given Throwable, 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 UndeclaredThrowableException. |
|
open static fun rethrowRuntimeException(ex: Throwable): Unit
Rethrow the given Throwable, 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 a RuntimeException or Error if appropriate; otherwise, throws an UndeclaredThrowableException. |
|
open static fun setField(field: Field, target: Any, value: Any): Unit
Set the field represented by the supplied Field on the specified Object to the specified Thrown exceptions are handled via a call to |
|
open static fun shallowCopyFieldState(src: Any, dest: Any): Unit
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. |