X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=support%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Freflection%2FReflectionUtils.java;h=a1fa5522b8f68bd0da7a8271a9168ef73421bd7c;hb=4a6250add2687ebe7d87797571a2f36bd5d7e85c;hp=1788f7402d569629b4789a50d619a866ea1e181a;hpb=68dcdd00b0448fb1c791268c43e634ccf1c0fcff;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); + } + } }