(no commit message)
authorErik Brakkee <erik@brakkee.org>
Tue, 10 Jun 2008 21:42:51 +0000 (21:42 +0000)
committerErik Brakkee <erik@brakkee.org>
Tue, 10 Jun 2008 21:42:51 +0000 (21:42 +0000)
support/general/src/main/java/org/wamblee/reflection/ReflectionUtils.java

index 1788f7402d569629b4789a50d619a866ea1e181a..a1fa5522b8f68bd0da7a8271a9168ef73421bd7c 100644 (file)
@@ -1,5 +1,12 @@
 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 {
 
        /**
@@ -39,4 +46,34 @@ 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);
+               }
+       }
 }