Package org.apache.tools.ant.util
Class ReflectUtil
- java.lang.Object
- 
- org.apache.tools.ant.util.ReflectUtil
 
- 
 public class ReflectUtil extends java.lang.ObjectUtility class to handle reflection on java objects. The class contains static methods to call reflection methods, catch any exceptions, converting them to BuildExceptions.
- 
- 
Method SummaryModifier and Type Method Description static <T> TgetField(java.lang.Object obj, java.lang.String fieldName)Get the value of a field in an object.static <T> Tinvoke(java.lang.Object obj, java.lang.String methodName)Call a method on the object with no parameters.static <T> Tinvoke(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> Tinvoke(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> TinvokeStatic(java.lang.Object obj, java.lang.String methodName)Call a method on the object with no parameters.static <T> TnewInstance(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 booleanrespondsTo(java.lang.Object o, java.lang.String methodName)A method to test if an object responds to a given message (method call)static voidthrowBuildException(java.lang.Exception t)A method to convert an invocationTargetException to a BuildException and throw it.static BuildExceptiontoBuildException(java.lang.Exception t)A method to convert an invocationTargetException to a BuildException.
 
- 
- 
- 
Method Detail- 
newInstancepublic 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.- Type Parameters:
- T- desired type
- Parameters:
- ofClass- Class<T>
- argTypes- Class<?>[]
- args- Object[]
- Returns:
- class instance
- Since:
- Ant 1.8.0
 
 - 
invokepublic static <T> T invoke(java.lang.Object obj, java.lang.String methodName)Call a method on the object with no parameters.- Type Parameters:
- T- desired type
- Parameters:
- obj- the object to invoke the method on.
- methodName- the name of the method to call
- Returns:
- the object returned by the method
 
 - 
invokeStaticpublic static <T> T invokeStatic(java.lang.Object obj, java.lang.String methodName)Call a method on the object with no parameters. Note: Unlike the invoke method above, this calls class or static methods, not instance methods.- Type Parameters:
- T- desired type
- Parameters:
- obj- the object to invoke the method on.
- methodName- the name of the method to call
- Returns:
- the object returned by the method
 
 - 
invokepublic 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.- Type Parameters:
- T- desired type
- Parameters:
- obj- the object to invoke the method on.
- methodName- the name of the method to call
- argType- the type of argument.
- arg- the value of the argument.
- Returns:
- the object returned by the method
 
 - 
invokepublic 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.- Type Parameters:
- T- desired type
- Parameters:
- obj- the object to invoke the method on.
- methodName- the name of the method to call
- argType1- 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.
- Returns:
- the object returned by the method
 
 - 
getFieldpublic static <T> T getField(java.lang.Object obj, java.lang.String fieldName) throws BuildExceptionGet the value of a field in an object.- Type Parameters:
- T- desired type
- Parameters:
- obj- the object to look at.
- fieldName- the name of the field in the object.
- Returns:
- the value of the field.
- Throws:
- BuildException- if there is an error.
 
 - 
throwBuildExceptionpublic static void throwBuildException(java.lang.Exception t) throws BuildExceptionA method to convert an invocationTargetException to a BuildException and throw it.- Parameters:
- t- the invocation target exception.
- Throws:
- BuildException- the converted exception.
 
 - 
toBuildExceptionpublic static BuildException toBuildException(java.lang.Exception t) A method to convert an invocationTargetException to a BuildException.- Parameters:
- t- the invocation target exception.
- Returns:
- the converted exception.
- Since:
- ant 1.7.1
 
 - 
respondsTopublic static boolean respondsTo(java.lang.Object o, java.lang.String methodName) throws BuildExceptionA method to test if an object responds to a given message (method call)- Parameters:
- o- the object
- methodName- the method to check for
- Returns:
- true if the object has the method.
- Throws:
- BuildException- if there is a problem.
 
 
- 
 
-