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

@ -113,7 +113,7 @@ public static Object invokeMethod(final Object object, final String methodName)
* @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);
} }
@ -194,6 +194,7 @@ public static Object invokeMethod(final Object object, final boolean forceAccess
* @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)
@ -209,18 +210,18 @@ public static Object invokeMethod(final Object object, final boolean forceAccess
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);
} }
@ -265,7 +266,7 @@ public static Object invokeMethod(final Object object, final String methodName,
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);
} }
/** /**
@ -285,7 +286,7 @@ public static Object invokeMethod(final Object object, final String methodName,
* @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 static Method getMatchingAccessibleMethod(final Class<?> cls,
*/ */
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;
} }
/** /**