package org.wamblee.reflection;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
public class ReflectionUtils {
/**
}
return aClass;
}
+
+
+ public static List<Method> getAllMethods(Class aClass) {
+
+ Map<String,Method> found = new HashMap<String, Method>();
+ getAllMethods(aClass, found);
+ return new ArrayList<Method>(found.values());
+ }
+
+ private static void getAllMethods(Class aClass, Map<String,Method> aFound) {
+ List<Method> declared = Arrays.asList(aClass.getDeclaredMethods());
+ for (Method method: declared) {
+ Method superMethod = aFound.get(method.getName());
+ if ( superMethod == null ) {
+ // no superclass method
+ aFound.put(method.getName(), method);
+ }
+ else {
+ // super class method. Check for override.
+ if ( !Arrays.equals(superMethod.getParameterTypes(), method.getParameterTypes())) {
+ // parameters differ so this is a new method.
+ aFound.put(method.getName(), method);
+ }
+ }
+ }
+ Class superClass = aClass.getSuperclass();
+ if (superClass != null) {
+ getAllMethods(superClass, aFound);
+ }
+ }
}