1 package org.wamblee.reflection;
 
   3 import java.lang.reflect.Method;
 
   4 import java.util.ArrayList;
 
   5 import java.util.Arrays;
 
   6 import java.util.HashMap;
 
  10 public class ReflectionUtils {
 
  13          * Wraps a type by the corresponding wrapper type if it is a primitive
 
  15          * @param aClass Type to wrap. 
 
  16          * @return Wrapped type for primitives or the provided argument value. 
 
  18         public static Class wrapIfNeeded(Class aClass) {
 
  20                 if (aClass == boolean.class) {
 
  23                 if (aClass == byte.class) {
 
  26                 if (aClass == char.class) {
 
  27                         return Character.class;
 
  29                 if (aClass == short.class) {
 
  32                 if (aClass == int.class) {
 
  35                 if (aClass == long.class) {
 
  38                 if (aClass == float.class) {
 
  41                 if (aClass == double.class) {
 
  44                 if (aClass == void.class) {
 
  51         public static List<Method> getAllMethods(Class aClass) {
 
  53                 Map<String,Method> found = new HashMap<String, Method>();
 
  54                 getAllMethods(aClass, found);
 
  55                 return new ArrayList<Method>(found.values());
 
  58         private static void getAllMethods(Class aClass, Map<String,Method> aFound) { 
 
  59                 List<Method> declared = Arrays.asList(aClass.getDeclaredMethods());
 
  60                 for (Method method: declared) { 
 
  61                         Method superMethod = aFound.get(method.getName());
 
  62                         if ( superMethod == null ) { 
 
  63                                 // no superclass method
 
  64                                 aFound.put(method.getName(), method);
 
  67                                 // super class method. Check for override.
 
  68                                 if ( !Arrays.equals(superMethod.getParameterTypes(), method.getParameterTypes())) { 
 
  69                                         // parameters differ so this is a new method.
 
  70                                         aFound.put(method.getName(), method);
 
  74                 Class superClass = aClass.getSuperclass();
 
  75                 if (superClass != null) {
 
  76                         getAllMethods(superClass, aFound);