ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject svn commit: r540435 - /ant/core/trunk/src/main/org/apache/tools/ant/util/ReflectUtil.java
Date Tue, 22 May 2007 06:11:55 GMT
Author: kevj
Date: Mon May 21 23:11:54 2007
New Revision: 540435

URL: http://svn.apache.org/viewvc?view=rev&rev=540435
Log:
-add invokeStatic for static/class methods

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/util/ReflectUtil.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/ReflectUtil.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/ReflectUtil.java?view=diff&rev=540435&r1=540434&r2=540435
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/ReflectUtil.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/ReflectUtil.java Mon May 21 23:11:54
2007
@@ -45,7 +45,7 @@
         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 @@
         }
     }
 
+    /**
+     * 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.



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message