Browse Source

-add invokeStatic for static/class methods

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@540435 13f79535-47bb-0310-9956-ffa450edef68
master
Kevin Jackson 18 years ago
parent
commit
052d306a14
1 changed files with 21 additions and 1 deletions
  1. +21
    -1
      src/main/org/apache/tools/ant/util/ReflectUtil.java

+ 21
- 1
src/main/org/apache/tools/ant/util/ReflectUtil.java View File

@@ -45,7 +45,7 @@ public class ReflectUtil {
try {
Method method;
method = obj.getClass().getMethod(
methodName, (Class[]) null);
methodName, (Class[]) null);
return method.invoke(obj, (Object[]) null);
} catch (Exception t) {
throwBuildException(t);
@@ -53,6 +53,26 @@ public class ReflectUtil {
}
}

/**
* Call a method on the object with no parameters.
* Note: Unlike the invoke method above, this
* calls class or static methods, not instance methods.
* @param obj the object to invoke the method on.
* @param methodName the name of the method to call
* @return the object returned by the method
*/
public static Object invokeStatic(Object obj, String methodName) {
try {
Method method;
method = ((Class)obj).getMethod(
methodName, (Class[]) null);
return method.invoke(obj, (Object[]) null);
} catch (Exception t) {
throwBuildException(t);
return null; // NotReached
}
}
/**
* Call a method on the object with one argument.
* @param obj the object to invoke the method on.


Loading…
Cancel
Save