Remove flexible method search
This commit is contained in:
parent
288287c96d
commit
d5cfd33756
1 changed files with 1 additions and 25 deletions
|
|
@ -7,7 +7,6 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
@ -33,20 +32,6 @@ public class ReflectionUtils {
|
||||||
return constructor;
|
return constructor;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean compareParameters(Class<?>[] required, Class<?>... parameters) {
|
|
||||||
if (required.length != parameters.length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < required.length; i++) {
|
|
||||||
if (!parameters[i].isAssignableFrom(required[i])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Method checkMethodType(Method method, Class<?> requiredType) throws IllegalStateException {
|
private static Method checkMethodType(Method method, Class<?> requiredType) throws IllegalStateException {
|
||||||
if (requiredType == null || requiredType.isAssignableFrom(method.getReturnType())) return method;
|
if (requiredType == null || requiredType.isAssignableFrom(method.getReturnType())) return method;
|
||||||
throw new IllegalStateException(requiredType + " is not assignable from type of " + method);
|
throw new IllegalStateException(requiredType + " is not assignable from type of " + method);
|
||||||
|
|
@ -113,16 +98,7 @@ public class ReflectionUtils {
|
||||||
return checkMethodType(getMethod0(type, methodName, parameterTypes), returnType);
|
return checkMethodType(getMethod0(type, methodName, parameterTypes), returnType);
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
exception = e;
|
exception = e;
|
||||||
} catch (NoSuchMethodException ignored) {
|
} catch (NoSuchMethodException ignored) {}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parameterTypes.length > 0) {
|
|
||||||
for (Method m : type.getDeclaredMethods()) {
|
|
||||||
if (compareParameters(parameterTypes, m.getParameterTypes())) {
|
|
||||||
return checkMethodType(m, returnType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exception != null) {
|
if (exception != null) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue