Revert changes from r1166233: [LANG-750] Add MethodUtil APIs to call methods without parameters.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1166253 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6a82ecae17
commit
613e988c80
|
@ -58,33 +58,6 @@ public class MethodUtils {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Invokes a named method without parameters.</p>
|
|
||||||
*
|
|
||||||
* <p>This method delegates the method search to {@link #getMatchingAccessibleMethod(Class, String, Class[])}.</p>
|
|
||||||
*
|
|
||||||
* <p>This method supports calls to methods taking primitive parameters
|
|
||||||
* via passing in wrapping classes. So, for example, a <code>Boolean</code> object
|
|
||||||
* would match a <code>boolean</code> primitive.</p>
|
|
||||||
*
|
|
||||||
* <p>This is a convenient wrapper for
|
|
||||||
* {@link #invokeMethod(Object object,String methodName, Object[] args, Class[] parameterTypes)}.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param object invoke method on this object
|
|
||||||
* @param methodName get method with this name
|
|
||||||
* @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
|
|
||||||
* @since 3.0.2
|
|
||||||
*/
|
|
||||||
public static Object invokeMethod(Object object, String methodName) throws NoSuchMethodException,
|
|
||||||
IllegalAccessException, InvocationTargetException {
|
|
||||||
return invokeMethod(object, methodName, ArrayUtils.EMPTY_OBJECT_ARRAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Invokes a named method whose parameter type matches the object type.</p>
|
* <p>Invokes a named method whose parameter type matches the object type.</p>
|
||||||
*
|
*
|
||||||
|
@ -160,28 +133,6 @@ public class MethodUtils {
|
||||||
return method.invoke(object, args);
|
return method.invoke(object, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Invokes a method without parameters.</p>
|
|
||||||
*
|
|
||||||
* <p>This uses reflection to invoke the method obtained from a call to
|
|
||||||
* <code>getAccessibleMethod()</code>.</p>
|
|
||||||
*
|
|
||||||
* @param object invoke method on this object
|
|
||||||
* @param methodName get method with this name
|
|
||||||
* @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
|
|
||||||
* @since 3.0.2
|
|
||||||
*/
|
|
||||||
public static Object invokeExactMethod(Object object, String methodName) throws NoSuchMethodException,
|
|
||||||
IllegalAccessException, InvocationTargetException {
|
|
||||||
return invokeExactMethod(object, methodName, ArrayUtils.EMPTY_OBJECT_ARRAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Invokes a method whose parameter types match exactly the object
|
* <p>Invokes a method whose parameter types match exactly the object
|
||||||
* types.</p>
|
* types.</p>
|
||||||
|
@ -290,35 +241,6 @@ public class MethodUtils {
|
||||||
return method.invoke(null, args);
|
return method.invoke(null, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Invokes a named static method without parameters.</p>
|
|
||||||
*
|
|
||||||
* <p>This method delegates the method search to {@link #getMatchingAccessibleMethod(Class, String, Class[])}.</p>
|
|
||||||
*
|
|
||||||
* <p>This method supports calls to methods taking primitive parameters
|
|
||||||
* via passing in wrapping classes. So, for example, a <code>Boolean</code> class
|
|
||||||
* would match a <code>boolean</code> primitive.</p>
|
|
||||||
*
|
|
||||||
* <p>This is a convenient wrapper for
|
|
||||||
* {@link #invokeStaticMethod(Class objectClass,String methodName,Object [] args,Class[] parameterTypes)}.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param cls invoke static method on this class
|
|
||||||
* @param methodName get method with this name
|
|
||||||
* @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
|
|
||||||
* @since 3.0.2
|
|
||||||
*/
|
|
||||||
public static Object invokeStaticMethod(Class<?> cls, String methodName) throws NoSuchMethodException,
|
|
||||||
IllegalAccessException, InvocationTargetException {
|
|
||||||
return invokeStaticMethod(cls, methodName, ArrayUtils.EMPTY_OBJECT_ARRAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Invokes a named static method whose parameter type matches the object type.</p>
|
* <p>Invokes a named static method whose parameter type matches the object type.</p>
|
||||||
*
|
*
|
||||||
|
@ -398,28 +320,6 @@ public class MethodUtils {
|
||||||
return method.invoke(null, args);
|
return method.invoke(null, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Invokes a static method without parameters.</p>
|
|
||||||
*
|
|
||||||
* <p>This uses reflection to invoke the method obtained from a call to
|
|
||||||
* {@link #getAccessibleMethod(Class, String, Class[])}.</p>
|
|
||||||
*
|
|
||||||
* @param cls invoke static method on this class
|
|
||||||
* @param methodName get method with this name
|
|
||||||
* @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
|
|
||||||
* @since 3.0.2
|
|
||||||
*/
|
|
||||||
public static Object invokeExactStaticMethod(Class<?> cls, String methodName) throws NoSuchMethodException,
|
|
||||||
IllegalAccessException, InvocationTargetException {
|
|
||||||
return invokeExactStaticMethod(cls, methodName, ArrayUtils.EMPTY_OBJECT_ARRAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Invokes a static method whose parameter types match exactly the object
|
* <p>Invokes a static method whose parameter types match exactly the object
|
||||||
* types.</p>
|
* types.</p>
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<release version="3.0.2" date="unreleased" description="September release">
|
<release version="3.0.2" date="unreleased" description="September release">
|
||||||
<action type="add" issue="LANG-750">Add MethodUtil APIs to call methods without parameters</action>
|
|
||||||
<action type="fix" issue="LANG-746">NumberUtils does not handle upper-case hex: 0X and -0X</action>
|
<action type="fix" issue="LANG-746">NumberUtils does not handle upper-case hex: 0X and -0X</action>
|
||||||
<action type="update" issue="LANG-736">CharUtils static final array CHAR_STRING is not needed to compute CHAR_STRING_ARRAY</action>
|
<action type="update" issue="LANG-736">CharUtils static final array CHAR_STRING is not needed to compute CHAR_STRING_ARRAY</action>
|
||||||
<action type="fix" issue="LANG-744">StringUtils throws java.security.AccessControlException on Google App Engine</action>
|
<action type="fix" issue="LANG-744">StringUtils throws java.security.AccessControlException on Google App Engine</action>
|
||||||
|
|
|
@ -161,16 +161,6 @@ public class MethodUtilsTest {
|
||||||
NumberUtils.DOUBLE_ONE));
|
NumberUtils.DOUBLE_ONE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testInvokeMethodNoParam() throws Exception {
|
|
||||||
assertEquals("foo()", MethodUtils.invokeMethod(testBean, "foo"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = NoSuchMethodException.class)
|
|
||||||
public void testInvokeMethodNoParamFailure() throws Exception {
|
|
||||||
assertEquals("oneParameter()", MethodUtils.invokeMethod(testBean, "oneParameter"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvokeExactMethod() throws Exception {
|
public void testInvokeExactMethod() throws Exception {
|
||||||
assertEquals("foo()", MethodUtils.invokeExactMethod(testBean, "foo",
|
assertEquals("foo()", MethodUtils.invokeExactMethod(testBean, "foo",
|
||||||
|
@ -208,16 +198,6 @@ public class MethodUtilsTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testInvokeExactMethodNoParam() throws Exception {
|
|
||||||
assertEquals("foo()", MethodUtils.invokeExactMethod(testBean, "foo"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = NoSuchMethodException.class)
|
|
||||||
public void testInvokeExactMethodNoParamFailure() throws Exception {
|
|
||||||
MethodUtils.invokeExactMethod(testBean, "oneParameter");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvokeStaticMethod() throws Exception {
|
public void testInvokeStaticMethod() throws Exception {
|
||||||
assertEquals("bar()", MethodUtils.invokeStaticMethod(TestBean.class,
|
assertEquals("bar()", MethodUtils.invokeStaticMethod(TestBean.class,
|
||||||
|
@ -248,16 +228,6 @@ public class MethodUtilsTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testInvokeStaticMethodNoParam() throws Exception {
|
|
||||||
assertEquals("bar()", MethodUtils.invokeStaticMethod(TestBean.class, "bar"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = NoSuchMethodException.class)
|
|
||||||
public void testInvokeStaticMethodNoParamFailure() throws Exception {
|
|
||||||
assertEquals("oneParameter()", MethodUtils.invokeStaticMethod(TestBean.class, "oneParameter"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvokeExactStaticMethod() throws Exception {
|
public void testInvokeExactStaticMethod() throws Exception {
|
||||||
assertEquals("bar()", MethodUtils.invokeExactStaticMethod(TestBean.class,
|
assertEquals("bar()", MethodUtils.invokeExactStaticMethod(TestBean.class,
|
||||||
|
@ -296,16 +266,6 @@ public class MethodUtilsTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testInvokeExactStaticMethodNoParam() throws Exception {
|
|
||||||
assertEquals("bar()", MethodUtils.invokeExactStaticMethod(TestBean.class, "bar"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = NoSuchMethodException.class)
|
|
||||||
public void testInvokeExactStaticMethodNoParamFailure() throws Exception {
|
|
||||||
assertEquals("oneParameterStatic()", MethodUtils.invokeExactStaticMethod(TestBean.class, "oneParameterStatic"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAccessibleInterfaceMethod() throws Exception {
|
public void testGetAccessibleInterfaceMethod() throws Exception {
|
||||||
Class<?>[][] p = { ArrayUtils.EMPTY_CLASS_ARRAY, null };
|
Class<?>[][] p = { ArrayUtils.EMPTY_CLASS_ARRAY, null };
|
||||||
|
|
Loading…
Reference in New Issue