ReflectionUtil { public static Method[] getAllMethodsOfClass(final Class<?> clazz) { if (clazz == null) { return null; } Method[] methods = null; Class<?> itr = clazz; while (itr != null && !itr.equals(Object.class)) { methods = (Method[]) ArrayUtil.addAll(itr.getDeclaredMethods(), methods); itr = itr.getSuperclass(); } return methods; }  static Method[] getAllMethodsOfClass(final Class<?> clazz); static Method[] getAllMethodsOfClass(Class<?> clazz, boolean accessible); static Method[] getAllInstanceMethods(final Class<?> clazz); static Method[] getAllInstanceMethods(Class<?> clazz, boolean accessible); static List<A> findAllMethodAnnotation(Class<T> clazz, Class<A> annotationType); static List<Method> getAnnotationMethods(Class<T> clazz, Class<A> annotationType); static Object invokeMethod(Method method, Object target, Object...args); static Object invokeMethod(Object object, String methodName, Object[] args, Class<?>...parameterTypes); static Object invokeStaticMethod(Class<?> clazz, String methodName, Object[] args, Class<?>...parameterTypes); static Method getMethod(Class<?> clazz, String methodName, Class<?>...parameterTypes); static Method getMethod(Object object, String methodName, Class<?>...parameterTypes); static Method[] getAccessibleMethods(Class<?> clazz); static Method[] getAccessibleMethods(Class<?> clazz, Class<?> limit); static boolean hasAnnotation(Method method, Class<A> annotationType); static Field[] getAllFieldsOfClass(Class<?> clazz); static Field[] getAllInstanceFields(Class<?> clazz); static Field[] getAllFieldsOfClass(Class<?> clazz, boolean accessible); static Field[] getAllFieldsOfClass(Object object); static Field[] getAllFieldsOfClass(Object object, boolean accessible); static Field[] getAllInstanceFields(Class<?> clazz, boolean accessible); static Field[] getAllInstanceFields(Object object); static Field[] getAllInstanceFields(Object object, boolean accessible); static Field[] getInstanceFields(Class<?> clazz, String[] includes); static Field[] getAnnotationFields(Class<?> clazz, Class<? extends Annotation> annotationClass); static Field getField(Object object, String fieldName); static Field getField(Class<?> clazz, String fieldName); @Deprecated static Field getFieldOfClass(Object object, String fieldName); static Field getField(Object object, String fieldName, boolean accessible); static Field getField(Class<?> clazz, String fieldName, boolean accessible); @Deprecated static Field getFieldOfClass(Class<?> clazz, String fieldName); @Deprecated static Field getFieldOfClass(Object object, String fieldName, boolean accessible); static Field[] getAccessibleFields(Class<?> clazz); static Field[] getAccessibleFields(Class<?> clazz, Class<?> limit); static T readField(Field field, Object target); static Object readField(String fieldName, Object target); static void writeField(Field field, Object target, Object value); static void writeField(Object target, String fieldName, Object value); static Object readStaticField(Field field); static Object readStaticField(Class<?> clazz, String fieldName); static void writeStaticField(Field field, Object value); static void writeStaticField(Class<?> clazz, String fieldName, Object value); static boolean notWriter(Field field); static boolean isFinal(Field field); static boolean hasSuperClass(Class<?> clazz); static boolean hasAnnotation(Field field, Class<A> annotationType); static Class<?> getComponentType(Class<?> clazz); static Class<?> getComponentType(Class<?> clazz, int index); static Class<?>[] getComponentTypes(Class<?> clazz); static Class<?>[] getComponentTypesRecursion(Class<?> clazz); static Class<?> getComponentTypeRecursion(Class<?> clazz); static Class<?> getComponentTypeRecursion(Class<?> clazz, int index); static Class<?> getComponentType(Type type); static Class<?> getComponentType(Type type, Class<?> implClass); static Class<?>[] getComponentTypes(Type type); static Class<?>[] getComponentTypes(Type type, Class<?> implClass); static Class<?>[] getGenericSuperTypes(Class<?> type); static Class<?> getGenericSuperType(Class<?> type); static Class<?> getRawType(Type type); static Class<?> getRawType(Type type, Class<?> implClass); static Type resolveVariable(TypeVariable<?> variable, final Class<?> implClass); static boolean isAccessible(Member m); static boolean isPublic(Member m); static void forceAccess(AccessibleObject object);  }
@Test public void getAllMethodsOfClass() { assertNull(ReflectionUtil.getAllMethodsOfClass(null)); Method[] methods = ReflectionUtil.getAllMethodsOfClass(MLet.class); assertTrue(methods.length > 0); Method equalsMethod = ReflectionUtil.getMethod(Object.class, "equals", Object.class); assertTrue(methods.length > 0); List<Method> methodList = Arrays.asList(methods); assertFalse(methodList.contains(equalsMethod)); List<Class<?>> list = ClassUtil.getAllInterfaces(MLet.class); int interMethodLength = 0; for (Class<?> clazz : list) { Method[] interMethods = ReflectionUtil.getAllMethodsOfClass(clazz); interMethodLength += interMethods.length; } assertTrue(methods.length > interMethodLength); }