public final class ReflectionUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static void |
assertNoParameters(java.lang.reflect.Method method)
Assert that the given method takes no parameters.
|
static void |
assertReturnValue(java.lang.reflect.Method method,
java.lang.Class<?> expectedReturnType)
Assert that the given method returns the expected return type.
|
static java.lang.Object |
createInstanceNoArgs(java.lang.Class<?> clazz)
Creates an instance of this class through reflection.
|
static java.lang.reflect.Method |
getNoArgsMethod(java.lang.Class<?> clazz,
java.lang.String methodName)
Returns a method with the provided name that takes no-args.
|
static <T> T |
invokeNoArgs(java.lang.Object instance,
java.lang.reflect.Method method)
Invokes the method, using the provided instance as 'this'.
|
static java.lang.reflect.Method |
lookupMethod(java.lang.Class<?> clazz,
java.lang.String methodName)
Find the first encountered method with the provided name.
|
static java.util.List<ReflectionParameter> |
reflectMethodParameters(java.lang.reflect.Method method)
Returns basic information about a method's parameters obtained via reflection.
|
public static java.lang.Object createInstanceNoArgs(java.lang.Class<?> clazz)
clazz - Class to instantiate.java.lang.RuntimeException - If an error occurred while instantiating an object of the class (for example, if the
class doesn't have a no-args constructor).public static java.lang.reflect.Method getNoArgsMethod(java.lang.Class<?> clazz,
java.lang.String methodName)
clazz - Class to search.methodName - Method name.java.lang.RuntimeException - If the class doesn't contain a no-args method with the given name.public static java.lang.reflect.Method lookupMethod(java.lang.Class<?> clazz,
java.lang.String methodName)
clazz - Class to search.methodName - Method name.java.lang.IllegalArgumentException - If the class doesn't contain a method with the provided name.public static <T> T invokeNoArgs(java.lang.Object instance,
java.lang.reflect.Method method)
T.
If the method is private, it will be made accessible outside of it's class.T - Return type.instance - Instance to use as 'this' for invocation.method - Method to invoke.java.lang.RuntimeException - If an error occurred invoking the method.public static void assertReturnValue(java.lang.reflect.Method method,
java.lang.Class<?> expectedReturnType)
method - Method to assert.expectedReturnType - Expected return type of the method.java.lang.IllegalArgumentException - If the method's return type doesn't match the expected type.public static void assertNoParameters(java.lang.reflect.Method method)
method - Method to assert.java.lang.IllegalArgumentException - If the method takes any parameters.public static java.util.List<ReflectionParameter> reflectMethodParameters(java.lang.reflect.Method method)
method - Method to reflect parameters for.