|
|
@@ -28,7 +28,7 @@ import java.lang.reflect.Field; |
|
|
* methods, catch any exceptions, converting them |
|
|
* methods, catch any exceptions, converting them |
|
|
* to BuildExceptions. |
|
|
* to BuildExceptions. |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
// CheckStyle:FinalClassCheck OFF - backward compatible |
|
|
public class ReflectUtil { |
|
|
public class ReflectUtil { |
|
|
|
|
|
|
|
|
/** private constructor */ |
|
|
/** private constructor */ |
|
|
@@ -64,7 +64,7 @@ public class ReflectUtil { |
|
|
public static Object invokeStatic(Object obj, String methodName) { |
|
|
public static Object invokeStatic(Object obj, String methodName) { |
|
|
try { |
|
|
try { |
|
|
Method method; |
|
|
Method method; |
|
|
method = ((Class)obj).getMethod( |
|
|
|
|
|
|
|
|
method = ((Class) obj).getMethod( |
|
|
methodName, (Class[]) null); |
|
|
methodName, (Class[]) null); |
|
|
return method.invoke(obj, (Object[]) null); |
|
|
return method.invoke(obj, (Object[]) null); |
|
|
} catch (Exception t) { |
|
|
} catch (Exception t) { |
|
|
@@ -152,6 +152,7 @@ public class ReflectUtil { |
|
|
* A method to convert an invocationTargetException to |
|
|
* A method to convert an invocationTargetException to |
|
|
* a buildexception. |
|
|
* a buildexception. |
|
|
* @param t the invocation target exception. |
|
|
* @param t the invocation target exception. |
|
|
|
|
|
* @return the converted exception. |
|
|
* @since ant 1.7.1 |
|
|
* @since ant 1.7.1 |
|
|
*/ |
|
|
*/ |
|
|
public static BuildException toBuildException(Exception t) { |
|
|
public static BuildException toBuildException(Exception t) { |
|
|
@@ -172,20 +173,20 @@ public class ReflectUtil { |
|
|
* message (method call) |
|
|
* message (method call) |
|
|
* @param o the object |
|
|
* @param o the object |
|
|
* @param methodName the method to check for |
|
|
* @param methodName the method to check for |
|
|
* @return |
|
|
|
|
|
* @throws BuildException |
|
|
|
|
|
|
|
|
* @return true if the object has the method. |
|
|
|
|
|
* @throws BuildException if there is a problem. |
|
|
*/ |
|
|
*/ |
|
|
public static boolean respondsTo(Object o, String methodName) |
|
|
public static boolean respondsTo(Object o, String methodName) |
|
|
throws BuildException { |
|
|
throws BuildException { |
|
|
try { |
|
|
try { |
|
|
Method[] methods = o.getClass().getMethods(); |
|
|
Method[] methods = o.getClass().getMethods(); |
|
|
for(int i=0; i<methods.length; i++) { |
|
|
|
|
|
if(methods[i].getName().equals(methodName)) { |
|
|
|
|
|
|
|
|
for (int i = 0; i < methods.length; i++) { |
|
|
|
|
|
if (methods[i].getName().equals(methodName)) { |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return false; |
|
|
return false; |
|
|
} catch(Exception t) { |
|
|
|
|
|
|
|
|
} catch (Exception t) { |
|
|
throw toBuildException(t); |
|
|
throw toBuildException(t); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |