1 45 package org.exolab.jms.plugins.proxygen; 46 47 import java.lang.reflect.Method ; 48 import java.util.ArrayList ; 49 50 51 59 public final class MethodHelper { 60 61 64 private MethodHelper() { 65 } 66 67 74 public static Method [] getAllInterfaceMethods(Class clazz) { 75 final int size = 10; 76 ArrayList result = new ArrayList (size); 77 getInterfaceMethods(getAllInterfaces(clazz), result); 78 return (Method []) result.toArray(new Method [0]); 79 } 80 81 87 public static Method [] getInterfaceMethods(Class clazz) { 88 final int size = 10; 89 ArrayList result = new ArrayList (size); 90 getInterfaceMethods(clazz.getInterfaces(), result); 91 return (Method []) result.toArray(new Method [0]); 92 } 93 94 101 public static long getMethodID(Method method) { 102 final int shift = 32; 103 long hash = method.getDeclaringClass().getName().hashCode(); 104 hash ^= method.getName().hashCode(); 105 hash ^= method.getReturnType().getName().hashCode(); 106 Class [] args = method.getParameterTypes(); 107 for (int i = 0; i < args.length; ++i) { 108 hash ^= ((long) args[i].getName().hashCode()) << shift; 109 } 110 return hash; 111 } 112 113 120 private static void getInterfaceMethods(Class [] interfaces, 121 ArrayList result) { 122 for (int i = 0; i < interfaces.length; ++i) { 123 Class iface = interfaces[i]; 124 getInterfaceMethods(iface.getInterfaces(), result); 125 Method [] methods = iface.getMethods(); 126 for (int j = 0; j < methods.length; ++j) { 127 if (methods[j].getDeclaringClass() == interfaces[i]) { 128 result.add(methods[j]); 129 } 130 } 131 } 132 } 133 134 140 public static Class [] getAllInterfaces(Class clazz) { 141 ArrayList result = new ArrayList (); 142 getAllInterfaces(clazz, result); 143 return (Class []) result.toArray(new Class [0]); 144 } 145 146 152 private static void getAllInterfaces(Class clazz, ArrayList result) { 153 Class [] interfaces = clazz.getInterfaces(); 154 for (int i = 0; i < interfaces.length; ++i) { 155 if (!result.contains(interfaces[i])) { 156 result.add(interfaces[i]); 157 } 158 } 159 Class superClass = clazz.getSuperclass(); 160 if (superClass != null) { 161 getAllInterfaces(superClass, result); 162 } 163 } 164 } 165 | Popular Tags |