/** * Obtain a Method by name from class declaringClass. * Simplified version of {@link net.minecraftforge.fml.relauncher.ReflectionHelper#findMethod(Class, Object, String[], Class...)}. */ public static final Method getDeclaredMethod(final Class<?> declaringClass, String[] methodNames, Class<?>... parameterTypes) { Exception failed = null; for (String methodName : methodNames) { try { Method method = declaringClass.getDeclaredMethod(methodName, parameterTypes); method.setAccessible(true); return method; } catch (Exception ex) { failed = ex; } } throw new UnableToFindMethodException(methodNames, failed); }
public static <E> Method reflectMethod(Class<? super E> clazz, String[] methodNames, Class<?>... methodTypes) { Exception failed = null; for (String methodName : methodNames) { try { Method m = clazz.getDeclaredMethod(methodName, methodTypes); m.setAccessible(true); return m; } catch (Exception e) { failed = e; } } throw new UnableToFindMethodException(methodNames, failed); }