Remove flexible method search

This commit is contained in:
Roman Zhuravlev 2025-12-11 18:09:51 +05:00
parent 288287c96d
commit d5cfd33756

View file

@ -7,7 +7,6 @@ import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.function.Consumer;
@ -33,20 +32,6 @@ public class ReflectionUtils {
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 {
if (requiredType == null || requiredType.isAssignableFrom(method.getReturnType())) return 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);
} catch (IllegalStateException e) {
exception = e;
} catch (NoSuchMethodException ignored) {
}
}
if (parameterTypes.length > 0) {
for (Method m : type.getDeclaredMethods()) {
if (compareParameters(parameterTypes, m.getParameterTypes())) {
return checkMethodType(m, returnType);
}
}
} catch (NoSuchMethodException ignored) {}
}
if (exception != null) {