/** * Perform the given callback operation on all matching methods of the given * class and superclasses. * <p> * The same named method occurring on subclass and superclass will appear * twice, unless excluded by the specified {@link MethodFilter}. * * @param targetClass class to start looking at * @param mc the callback to invoke for each method * @param mf the filter that determines the methods to apply the callback to */ public static void doWithMethods(Class<?> targetClass, final MethodCallback mc, final MethodFilter mf) throws IllegalArgumentException { // Keep backing up the inheritance hierarchy. do { final Method[] methods = targetClass.getDeclaredMethods(); for (final Method method : methods) { if (mf != null && !mf.matches(method)) { continue; } try { mc.doWith(method); } catch (final IllegalAccessException ex) { throw new IllegalStateException("Shouldn't be illegal to access method '" + method.getName() + "': " + ex); } } targetClass = targetClass.getSuperclass(); } while (targetClass != null); }