Fix whitespaces, add missing @since tag

This commit is contained in:
Benedikt Ritter 2016-09-11 16:06:32 +02:00
parent d0049e1ac3
commit ab60f735c7
1 changed files with 52 additions and 51 deletions

View File

@ -109,11 +109,11 @@ public class MethodUtils {
* @throws NoSuchMethodException if there is no such accessible method * @throws NoSuchMethodException if there is no such accessible method
* @throws InvocationTargetException wraps an exception thrown by the method invoked * @throws InvocationTargetException wraps an exception thrown by the method invoked
* @throws IllegalAccessException if the requested method is not accessible via reflection * @throws IllegalAccessException if the requested method is not accessible via reflection
* *
* @since 3.5 * @since 3.5
*/ */
public static Object invokeMethod(final Object object, final boolean forceAccess, final String methodName) public static Object invokeMethod(final Object object, final boolean forceAccess, final String methodName)
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
return invokeMethod(object, forceAccess, methodName, ArrayUtils.EMPTY_OBJECT_ARRAY, null); return invokeMethod(object, forceAccess, methodName, ArrayUtils.EMPTY_OBJECT_ARRAY, null);
} }
@ -166,7 +166,7 @@ public class MethodUtils {
* @throws NoSuchMethodException if there is no such accessible method * @throws NoSuchMethodException if there is no such accessible method
* @throws InvocationTargetException wraps an exception thrown by the method invoked * @throws InvocationTargetException wraps an exception thrown by the method invoked
* @throws IllegalAccessException if the requested method is not accessible via reflection * @throws IllegalAccessException if the requested method is not accessible via reflection
* *
* @since 3.5 * @since 3.5
*/ */
public static Object invokeMethod(final Object object, final boolean forceAccess, final String methodName, public static Object invokeMethod(final Object object, final boolean forceAccess, final String methodName,
@ -194,6 +194,7 @@ public class MethodUtils {
* @throws NoSuchMethodException if there is no such accessible method * @throws NoSuchMethodException if there is no such accessible method
* @throws InvocationTargetException wraps an exception thrown by the method invoked * @throws InvocationTargetException wraps an exception thrown by the method invoked
* @throws IllegalAccessException if the requested method is not accessible via reflection * @throws IllegalAccessException if the requested method is not accessible via reflection
* @since 3.5
*/ */
public static Object invokeMethod(final Object object, final boolean forceAccess, final String methodName, public static Object invokeMethod(final Object object, final boolean forceAccess, final String methodName,
Object[] args, Class<?>[] parameterTypes) Object[] args, Class<?>[] parameterTypes)
@ -201,36 +202,36 @@ public class MethodUtils {
InvocationTargetException { InvocationTargetException {
parameterTypes = ArrayUtils.nullToEmpty(parameterTypes); parameterTypes = ArrayUtils.nullToEmpty(parameterTypes);
args = ArrayUtils.nullToEmpty(args); args = ArrayUtils.nullToEmpty(args);
final String messagePrefix; final String messagePrefix;
Method method = null; Method method = null;
boolean isOriginallyAccessible = false; boolean isOriginallyAccessible = false;
Object result = null; Object result = null;
try { try {
if (forceAccess) { if (forceAccess) {
messagePrefix = "No such method: "; messagePrefix = "No such method: ";
method = getMatchingMethod(object.getClass(), method = getMatchingMethod(object.getClass(),
methodName, parameterTypes); methodName, parameterTypes);
if (method != null) { if (method != null) {
isOriginallyAccessible = method.isAccessible(); isOriginallyAccessible = method.isAccessible();
if (!isOriginallyAccessible) { if (!isOriginallyAccessible) {
method.setAccessible(true); method.setAccessible(true);
} }
} }
} else { } else {
messagePrefix = "No such accessible method: "; messagePrefix = "No such accessible method: ";
method = getMatchingAccessibleMethod(object.getClass(), method = getMatchingAccessibleMethod(object.getClass(),
methodName, parameterTypes); methodName, parameterTypes);
} }
if (method == null) { if (method == null) {
throw new NoSuchMethodException(messagePrefix throw new NoSuchMethodException(messagePrefix
+ methodName + "() on object: " + methodName + "() on object: "
+ object.getClass().getName()); + object.getClass().getName());
} }
args = toVarArgs(method, args); args = toVarArgs(method, args);
result = method.invoke(object, args); result = method.invoke(object, args);
} }
finally { finally {
@ -238,10 +239,10 @@ public class MethodUtils {
method.setAccessible(isOriginallyAccessible); method.setAccessible(isOriginallyAccessible);
} }
} }
return result; return result;
} }
/** /**
* <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>
* *
@ -265,7 +266,7 @@ public class MethodUtils {
Object[] args, Class<?>[] parameterTypes) Object[] args, Class<?>[] parameterTypes)
throws NoSuchMethodException, IllegalAccessException, throws NoSuchMethodException, IllegalAccessException,
InvocationTargetException { InvocationTargetException {
return invokeMethod(object, false, methodName, args, parameterTypes); return invokeMethod(object, false, methodName, args, parameterTypes);
} }
/** /**
@ -284,8 +285,8 @@ public class MethodUtils {
* method invoked * method invoked
* @throws IllegalAccessException if the requested method is not accessible * @throws IllegalAccessException if the requested method is not accessible
* via reflection * via reflection
* *
* @since 3.4 * @since 3.4
*/ */
public static Object invokeExactMethod(final Object object, final String methodName) throws NoSuchMethodException, public static Object invokeExactMethod(final Object object, final String methodName) throws NoSuchMethodException,
IllegalAccessException, InvocationTargetException { IllegalAccessException, InvocationTargetException {
@ -725,33 +726,33 @@ public class MethodUtils {
*/ */
public static Method getMatchingMethod(final Class<?> cls, final String methodName, public static Method getMatchingMethod(final Class<?> cls, final String methodName,
final Class<?>... parameterTypes) { final Class<?>... parameterTypes) {
Validate.notNull(cls, "Null class not allowed."); Validate.notNull(cls, "Null class not allowed.");
Validate.notEmpty(methodName, "Null or blank methodName not allowed."); Validate.notEmpty(methodName, "Null or blank methodName not allowed.");
// Address methods in superclasses // Address methods in superclasses
Method[] methodArray = cls.getDeclaredMethods(); Method[] methodArray = cls.getDeclaredMethods();
List<Class<?>> superclassList = ClassUtils.getAllSuperclasses(cls); List<Class<?>> superclassList = ClassUtils.getAllSuperclasses(cls);
for (Class<?> klass: superclassList) { for (Class<?> klass : superclassList) {
methodArray = ArrayUtils.addAll(methodArray, klass.getDeclaredMethods()); methodArray = ArrayUtils.addAll(methodArray, klass.getDeclaredMethods());
} }
Method inexactMatch = null; Method inexactMatch = null;
for (Method method: methodArray) { for (Method method : methodArray) {
if (methodName.equals(method.getName()) && if (methodName.equals(method.getName()) &&
ArrayUtils.isEquals(parameterTypes, method.getParameterTypes())) { ArrayUtils.isEquals(parameterTypes, method.getParameterTypes())) {
return method; return method;
} else if (methodName.equals(method.getName()) && } else if (methodName.equals(method.getName()) &&
ClassUtils.isAssignable(parameterTypes, method.getParameterTypes(), true)) { ClassUtils.isAssignable(parameterTypes, method.getParameterTypes(), true)) {
if (inexactMatch == null) { if (inexactMatch == null) {
inexactMatch = method; inexactMatch = method;
} else if (distance(parameterTypes, method.getParameterTypes()) } else if (distance(parameterTypes, method.getParameterTypes())
< distance(parameterTypes, inexactMatch.getParameterTypes())) { < distance(parameterTypes, inexactMatch.getParameterTypes())) {
inexactMatch = method; inexactMatch = method;
} }
} }
} }
return inexactMatch; return inexactMatch;
} }
/** /**