From 5ba837e409c797d4edcb71b07026a994fc173d76 Mon Sep 17 00:00:00 2001 From: Henri Yandell Date: Mon, 22 Mar 2010 05:59:31 +0000 Subject: [PATCH] Moving most of the methods over to varargs. A couple can't change because they are Object[], Class[] with both end parameters ideally wanting to be vararg. LANG-396 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@925961 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/lang3/reflect/MethodUtils.java | 142 +----------------- 1 file changed, 8 insertions(+), 134 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java b/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java index c88bef10c..d270b38cd 100644 --- a/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java +++ b/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java @@ -67,34 +67,6 @@ public MethodUtils() { super(); } - /** - *

Invoke a named method whose parameter type matches the object type.

- * - *

This method delegates the method search to {@link #getMatchingAccessibleMethod(Class, String, Class[])}.

- * - *

This method supports calls to methods taking primitive parameters - * via passing in wrapping classes. So, for example, a Boolean object - * would match a boolean primitive.

- * - *

This is a convenient wrapper for - * {@link #invokeMethod(Object object, String methodName, Object[] args)}. - *

- * - * @param object invoke method on this object - * @param methodName get method with this name - * @param arg use this argument - * @return The value returned by the invoked method - * - * @throws NoSuchMethodException if there is no such accessible method - * @throws InvocationTargetException wraps an exception thrown by the method invoked - * @throws IllegalAccessException if the requested method is not accessible via reflection - */ - public static Object invokeMethod(Object object, String methodName, - Object arg) throws NoSuchMethodException, IllegalAccessException, - InvocationTargetException { - return invokeMethod(object, methodName, new Object[] { arg }); - } - /** *

Invoke a named method whose parameter type matches the object type.

* @@ -118,7 +90,7 @@ public static Object invokeMethod(Object object, String methodName, * @throws IllegalAccessException if the requested method is not accessible via reflection */ public static Object invokeMethod(Object object, String methodName, - Object[] args) throws NoSuchMethodException, + Object... args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { if (args == null) { args = ArrayUtils.EMPTY_OBJECT_ARRAY; @@ -170,31 +142,6 @@ public static Object invokeMethod(Object object, String methodName, return method.invoke(object, args); } - /** - *

Invoke a method whose parameter type matches exactly the object - * type.

- * - *

This is a convenient wrapper for - * {@link #invokeExactMethod(Object object,String methodName,Object [] args)}. - *

- * - * @param object invoke method on this object - * @param methodName get method with this name - * @param arg use this argument - * @return The value returned by the invoked method - * - * @throws NoSuchMethodException if there is no such accessible method - * @throws InvocationTargetException wraps an exception thrown by the - * method invoked - * @throws IllegalAccessException if the requested method is not accessible - * via reflection - */ - public static Object invokeExactMethod(Object object, String methodName, - Object arg) throws NoSuchMethodException, IllegalAccessException, - InvocationTargetException { - return invokeExactMethod(object, methodName, new Object[] { arg }); - } - /** *

Invoke a method whose parameter types match exactly the object * types.

@@ -214,7 +161,7 @@ public static Object invokeExactMethod(Object object, String methodName, * via reflection */ public static Object invokeExactMethod(Object object, String methodName, - Object[] args) throws NoSuchMethodException, + Object... args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { if (args == null) { args = ArrayUtils.EMPTY_OBJECT_ARRAY; @@ -303,36 +250,6 @@ public static Object invokeExactStaticMethod(Class cls, String methodName, return method.invoke(null, args); } - /** - *

Invoke a named static method whose parameter type matches the object type.

- * - *

This method delegates the method search to {@link #getMatchingAccessibleMethod(Class, String, Class[])}.

- * - *

This method supports calls to methods taking primitive parameters - * via passing in wrapping classes. So, for example, a Boolean class - * would match a boolean primitive.

- * - *

This is a convenient wrapper for - * {@link #invokeStaticMethod(Class objectClass,String methodName,Object [] args)}. - *

- * - * @param cls invoke static method on this class - * @param methodName get method with this name - * @param arg use this argument - * @return The value returned by the invoked method - * - * @throws NoSuchMethodException if there is no such accessible method - * @throws InvocationTargetException wraps an exception thrown by the - * method invoked - * @throws IllegalAccessException if the requested method is not accessible - * via reflection - */ - public static Object invokeStaticMethod(Class cls, String methodName, - Object arg) throws NoSuchMethodException, IllegalAccessException, - InvocationTargetException { - return invokeStaticMethod(cls, methodName, new Object[] { arg }); - } - /** *

Invoke a named static method whose parameter type matches the object type.

* @@ -358,7 +275,7 @@ public static Object invokeStaticMethod(Class cls, String methodName, * via reflection */ public static Object invokeStaticMethod(Class cls, String methodName, - Object[] args) throws NoSuchMethodException, + Object... args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { if (args == null) { args = ArrayUtils.EMPTY_OBJECT_ARRAY; @@ -412,31 +329,6 @@ public static Object invokeStaticMethod(Class cls, String methodName, return method.invoke(null, args); } - /** - *

Invoke a static method whose parameter type matches exactly the object - * type.

- * - *

This is a convenient wrapper for - * {@link #invokeExactStaticMethod(Class objectClass,String methodName,Object [] args)}. - *

- * - * @param cls invoke static method on this class - * @param methodName get method with this name - * @param arg use this argument - * @return The value returned by the invoked method - * - * @throws NoSuchMethodException if there is no such accessible method - * @throws InvocationTargetException wraps an exception thrown by the - * method invoked - * @throws IllegalAccessException if the requested method is not accessible - * via reflection - */ - public static Object invokeExactStaticMethod(Class cls, String methodName, - Object arg) throws NoSuchMethodException, IllegalAccessException, - InvocationTargetException { - return invokeExactStaticMethod(cls, methodName, new Object[] { arg }); - } - /** *

Invoke a static method whose parameter types match exactly the object * types.

@@ -456,7 +348,7 @@ public static Object invokeExactStaticMethod(Class cls, String methodName, * via reflection */ public static Object invokeExactStaticMethod(Class cls, String methodName, - Object[] args) throws NoSuchMethodException, + Object... args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { if (args == null) { args = ArrayUtils.EMPTY_OBJECT_ARRAY; @@ -469,24 +361,6 @@ public static Object invokeExactStaticMethod(Class cls, String methodName, return invokeExactStaticMethod(cls, methodName, args, parameterTypes); } - /** - *

Return an accessible method (that is, one that can be invoked via - * reflection) with given name and a single parameter. If no such method - * can be found, return null. - * Basically, a convenience wrapper that constructs a Class - * array for you.

- * - * @param cls get method from this class - * @param methodName get method with this name - * @param parameterType taking this type of parameter - * @return The accessible method - */ - public static Method getAccessibleMethod(Class cls, String methodName, - Class parameterType) { - return getAccessibleMethod(cls, methodName, - new Class[] { parameterType }); - } - /** *

Return an accessible method (that is, one that can be invoked via * reflection) with given name and parameters. If no such method @@ -500,7 +374,7 @@ public static Method getAccessibleMethod(Class cls, String methodName, * @return The accessible method */ public static Method getAccessibleMethod(Class cls, String methodName, - Class[] parameterTypes) { + Class... parameterTypes) { try { return getAccessibleMethod(cls.getMethod(methodName, parameterTypes)); @@ -552,7 +426,7 @@ public static Method getAccessibleMethod(Method method) { * @return the accessible method or null if not found */ private static Method getAccessibleMethodFromSuperclass(Class cls, - String methodName, Class[] parameterTypes) { + String methodName, Class... parameterTypes) { Class parentClass = cls.getSuperclass(); while (parentClass != null) { if (Modifier.isPublic(parentClass.getModifiers())) { @@ -583,7 +457,7 @@ private static Method getAccessibleMethodFromSuperclass(Class cls, * @return the accessible method or null if not found */ private static Method getAccessibleMethodFromInterfaceNest(Class cls, - String methodName, Class[] parameterTypes) { + String methodName, Class... parameterTypes) { Method method = null; // Search up the superclass chain @@ -641,7 +515,7 @@ private static Method getAccessibleMethodFromInterfaceNest(Class cls, * @return The accessible method */ public static Method getMatchingAccessibleMethod(Class cls, - String methodName, Class[] parameterTypes) { + String methodName, Class... parameterTypes) { try { Method method = cls.getMethod(methodName, parameterTypes); MemberUtils.setAccessibleWorkaround(method);