public class ReflectUtil
extends java.lang.Object
Modifier and Type | Method | Description |
---|---|---|
static <T> T |
getField(java.lang.Object obj,
java.lang.String fieldName) |
Get the value of a field in an object.
|
static <T> T |
invoke(java.lang.Object obj,
java.lang.String methodName) |
Call a method on the object with no parameters.
|
static <T> T |
invoke(java.lang.Object obj,
java.lang.String methodName,
java.lang.Class<?> argType,
java.lang.Object arg) |
Call a method on the object with one argument.
|
static <T> T |
invoke(java.lang.Object obj,
java.lang.String methodName,
java.lang.Class<?> argType1,
java.lang.Object arg1,
java.lang.Class<?> argType2,
java.lang.Object arg2) |
Call a method on the object with two argument.
|
static <T> T |
invokeStatic(java.lang.Object obj,
java.lang.String methodName) |
Call a method on the object with no parameters.
|
static <T> T |
newInstance(java.lang.Class<T> ofClass,
java.lang.Class<?>[] argTypes,
java.lang.Object[] args) |
Create an instance of a class using the constructor matching
the given arguments.
|
static boolean |
respondsTo(java.lang.Object o,
java.lang.String methodName) |
A method to test if an object responds to a given
message (method call)
|
static void |
throwBuildException(java.lang.Exception t) |
A method to convert an invocationTargetException to
a BuildException and throw it.
|
static BuildException |
toBuildException(java.lang.Exception t) |
A method to convert an invocationTargetException to
a BuildException.
|
public static <T> T newInstance(java.lang.Class<T> ofClass, java.lang.Class<?>[] argTypes, java.lang.Object[] args)
T
- desired typeofClass
- Class<T>argTypes
- Class<?>[]args
- Object[]public static <T> T invoke(java.lang.Object obj, java.lang.String methodName)
T
- desired typeobj
- the object to invoke the method on.methodName
- the name of the method to callpublic static <T> T invokeStatic(java.lang.Object obj, java.lang.String methodName)
T
- desired typeobj
- the object to invoke the method on.methodName
- the name of the method to callpublic static <T> T invoke(java.lang.Object obj, java.lang.String methodName, java.lang.Class<?> argType, java.lang.Object arg)
T
- desired typeobj
- the object to invoke the method on.methodName
- the name of the method to callargType
- the type of argument.arg
- the value of the argument.public static <T> T invoke(java.lang.Object obj, java.lang.String methodName, java.lang.Class<?> argType1, java.lang.Object arg1, java.lang.Class<?> argType2, java.lang.Object arg2)
T
- desired typeobj
- the object to invoke the method on.methodName
- the name of the method to callargType1
- the type of the first argument.arg1
- the value of the first argument.argType2
- the type of the second argument.arg2
- the value of the second argument.public static <T> T getField(java.lang.Object obj, java.lang.String fieldName) throws BuildException
T
- desired typeobj
- the object to look at.fieldName
- the name of the field in the object.BuildException
- if there is an error.public static void throwBuildException(java.lang.Exception t) throws BuildException
t
- the invocation target exception.BuildException
- the converted exception.public static BuildException toBuildException(java.lang.Exception t)
t
- the invocation target exception.public static boolean respondsTo(java.lang.Object o, java.lang.String methodName) throws BuildException
o
- the objectmethodName
- the method to check forBuildException
- if there is a problem.