From: erik Date: Tue, 10 Jun 2008 21:42:51 +0000 (+0000) Subject: (no commit message) X-Git-Tag: wamblee-utils-0.2~1^2~74 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=4a6250add2687ebe7d87797571a2f36bd5d7e85c;p=utils --- diff --git a/support/general/src/main/java/org/wamblee/reflection/ReflectionUtils.java b/support/general/src/main/java/org/wamblee/reflection/ReflectionUtils.java index 1788f740..a1fa5522 100644 --- a/support/general/src/main/java/org/wamblee/reflection/ReflectionUtils.java +++ b/support/general/src/main/java/org/wamblee/reflection/ReflectionUtils.java @@ -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 getAllMethods(Class aClass) { + + Map found = new HashMap(); + getAllMethods(aClass, found); + return new ArrayList(found.values()); + } + + private static void getAllMethods(Class aClass, Map aFound) { + List 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); + } + } }