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
*/
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);
}
@ -194,6 +194,7 @@ public static Object invokeMethod(final Object object, final boolean forceAccess
* @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.5
*/
public static Object invokeMethod(final Object object, final boolean forceAccess, final String methodName,
Object[] args, Class<?>[] parameterTypes)
@ -209,18 +210,18 @@ public static Object invokeMethod(final Object object, final boolean forceAccess
try {
if (forceAccess) {
messagePrefix = "No such method: ";
method = getMatchingMethod(object.getClass(),
messagePrefix = "No such method: ";
method = getMatchingMethod(object.getClass(),
methodName, parameterTypes);
if (method != null) {
isOriginallyAccessible = method.isAccessible();
if (!isOriginallyAccessible) {
method.setAccessible(true);
}
}
} else {
messagePrefix = "No such accessible method: ";
method = getMatchingAccessibleMethod(object.getClass(),
if (method != null) {
isOriginallyAccessible = method.isAccessible();
if (!isOriginallyAccessible) {
method.setAccessible(true);
}
}
} else {
messagePrefix = "No such accessible method: ";
method = getMatchingAccessibleMethod(object.getClass(),
methodName, parameterTypes);
}
@ -265,7 +266,7 @@ public static Object invokeMethod(final Object object, final String methodName,
Object[] args, Class<?>[] parameterTypes)
throws NoSuchMethodException, IllegalAccessException,
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
* via reflection
*
* @since 3.4
* @since 3.4
*/
public static Object invokeExactMethod(final Object object, final String methodName) throws NoSuchMethodException,
IllegalAccessException, InvocationTargetException {
@ -725,33 +726,33 @@ public static Method getMatchingAccessibleMethod(final Class<?> cls,
*/
public static Method getMatchingMethod(final Class<?> cls, final String methodName,
final Class<?>... parameterTypes) {
Validate.notNull(cls, "Null class not allowed.");
Validate.notEmpty(methodName, "Null or blank methodName not allowed.");
Validate.notNull(cls, "Null class not allowed.");
Validate.notEmpty(methodName, "Null or blank methodName not allowed.");
// Address methods in superclasses
Method[] methodArray = cls.getDeclaredMethods();
List<Class<?>> superclassList = ClassUtils.getAllSuperclasses(cls);
for (Class<?> klass: superclassList) {
methodArray = ArrayUtils.addAll(methodArray, klass.getDeclaredMethods());
}
// Address methods in superclasses
Method[] methodArray = cls.getDeclaredMethods();
List<Class<?>> superclassList = ClassUtils.getAllSuperclasses(cls);
for (Class<?> klass : superclassList) {
methodArray = ArrayUtils.addAll(methodArray, klass.getDeclaredMethods());
}
Method inexactMatch = null;
for (Method method: methodArray) {
if (methodName.equals(method.getName()) &&
ArrayUtils.isEquals(parameterTypes, method.getParameterTypes())) {
return method;
} else if (methodName.equals(method.getName()) &&
ClassUtils.isAssignable(parameterTypes, method.getParameterTypes(), true)) {
if (inexactMatch == null) {
inexactMatch = method;
} else if (distance(parameterTypes, method.getParameterTypes())
< distance(parameterTypes, inexactMatch.getParameterTypes())) {
inexactMatch = method;
}
}
Method inexactMatch = null;
for (Method method : methodArray) {
if (methodName.equals(method.getName()) &&
ArrayUtils.isEquals(parameterTypes, method.getParameterTypes())) {
return method;
} else if (methodName.equals(method.getName()) &&
ClassUtils.isAssignable(parameterTypes, method.getParameterTypes(), true)) {
if (inexactMatch == null) {
inexactMatch = method;
} else if (distance(parameterTypes, method.getParameterTypes())
< distance(parameterTypes, inexactMatch.getParameterTypes())) {
inexactMatch = method;
}
}
}
return inexactMatch;
}
return inexactMatch;
}
/**