From 052d306a1440a682d373b72e1a71c08f64fe2225 Mon Sep 17 00:00:00 2001 From: Kevin Jackson Date: Tue, 22 May 2007 06:11:54 +0000 Subject: [PATCH] -add invokeStatic for static/class methods git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@540435 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/util/ReflectUtil.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/org/apache/tools/ant/util/ReflectUtil.java b/src/main/org/apache/tools/ant/util/ReflectUtil.java index 425ae8831..1ffb3c290 100644 --- a/src/main/org/apache/tools/ant/util/ReflectUtil.java +++ b/src/main/org/apache/tools/ant/util/ReflectUtil.java @@ -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.