From 9924b70a3b4fbf582d9d10f16194ab690d3b82b9 Mon Sep 17 00:00:00 2001 From: erik Date: Tue, 10 Jun 2008 21:42:51 +0000 Subject: [PATCH] --- .../wamblee/reflection/ReflectionUtils.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/trunk/support/general/src/main/java/org/wamblee/reflection/ReflectionUtils.java b/trunk/support/general/src/main/java/org/wamblee/reflection/ReflectionUtils.java index 1788f740..a1fa5522 100644 --- a/trunk/support/general/src/main/java/org/wamblee/reflection/ReflectionUtils.java +++ b/trunk/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); + } + } } -- 2.31.1