/** * Given a specific method, finds all declared methods with the same name and arguments on all * superclasses and interfaces. * * @param m The method to find matches against. * @return * All matching methods including the input method itself. * Methods are ordered from child-to-parent order. */ public static List<Method> findMatchingMethods(Method m) { return findMatchingMethods(new ArrayList<Method>(), m); }
/** * Given a specific method, finds all declared methods with the same name and arguments on all * superclasses and interfaces. * * @param m The method to find matches against. * @return * All matching methods including the input method itself. * Methods are ordered from child-to-parent order. */ public static List<Method> findMatchingMethods(Method m) { return findMatchingMethods(new ArrayList<Method>(), m); }
/** * Given a specific method, finds all declared methods with the same name and arguments on all * superclasses and interfaces. * * @param m The method to find matches against. * @return * All matching methods including the input method itself. * Methods are ordered from child-to-parent order. */ public static List<Method> findMatchingMethods(Method m) { return findMatchingMethods(new ArrayList<Method>(), m); }
private static List<Method> findMatchingMethods(List<Method> l, Method m) { l.add(m); Class<?> c = m.getDeclaringClass(); Class<?> pc = c.getSuperclass(); if (pc != null) for (Method m2 : pc.getDeclaredMethods()) if (isSameMethod(m, m2)) findMatchingMethods(l, m2); for (Class<?> ic : c.getInterfaces()) for (Method m2 : ic.getDeclaredMethods()) if (isSameMethod(m, m2)) findMatchingMethods(l, m2); return l; }
private static List<Method> findMatchingMethods(List<Method> l, Method m) { l.add(m); Class<?> c = m.getDeclaringClass(); Class<?> pc = c.getSuperclass(); if (pc != null) for (Method m2 : pc.getDeclaredMethods()) if (isSameMethod(m, m2)) findMatchingMethods(l, m2); for (Class<?> ic : c.getInterfaces()) for (Method m2 : ic.getDeclaredMethods()) if (isSameMethod(m, m2)) findMatchingMethods(l, m2); return l; }
private static List<Method> findMatchingMethods(List<Method> l, Method m) { l.add(m); Class<?> c = m.getDeclaringClass(); Class<?> pc = c.getSuperclass(); if (pc != null) for (Method m2 : pc.getDeclaredMethods()) if (isSameMethod(m, m2)) findMatchingMethods(l, m2); for (Class<?> ic : c.getInterfaces()) for (Method m2 : ic.getDeclaredMethods()) if (isSameMethod(m, m2)) findMatchingMethods(l, m2); return l; }
public static <T extends Annotation> List<T> getAnnotations(Class<T> a, Method m, boolean searchParentMethods, boolean searchReturnType, boolean parentFirst) { List<T> l = new ArrayList<>(); List<Method> methods = searchParentMethods ? findMatchingMethods(m) : Collections.singletonList(m); for (Method m2 : methods) for (Annotation a2 : m2.getAnnotations())
public static <T extends Annotation> List<T> getAnnotations(Class<T> a, Method m, int index, boolean searchParentMethods, boolean searchArgType, boolean parentFirst) { List<T> l = new ArrayList<>(); List<Method> methods = searchParentMethods ? findMatchingMethods(m) : Collections.singletonList(m); for (Method m2 : methods) for (Annotation a2 : m2.getParameterAnnotations()[index])
public static <T extends Annotation> List<T> getAnnotations(Class<T> a, Method m, boolean searchParentMethods, boolean searchReturnType, boolean parentFirst) { List<T> l = new ArrayList<>(); List<Method> methods = searchParentMethods ? findMatchingMethods(m) : Collections.singletonList(m); for (Method m2 : methods) for (Annotation a2 : m2.getAnnotations())
public static <T extends Annotation> List<T> getAnnotations(Class<T> a, Method m, boolean searchParentMethods, boolean searchReturnType, boolean parentFirst) { List<T> l = new ArrayList<>(); List<Method> methods = searchParentMethods ? findMatchingMethods(m) : Collections.singletonList(m); for (Method m2 : methods) for (Annotation a2 : m2.getAnnotations())
/** * Finds the annotation of the specified type defined on the specified method. * * @param a * The annotation to search for. * @param m * The method to find the annotation on. * @param searchParentMethods * If <jk>true</jk>, searches methods with the same signature on the parent classes or interfaces. * <br>The search is performed in child-to-parent order. * @param searchReturnType * If <jk>true</jk>, searches the return type on the method for the specified annotation. * @return * The annotation if found, or <jk>null</jk> if not. */ @SuppressWarnings("unchecked") public static <T extends Annotation> T getAnnotation(Class<T> a, Method m, boolean searchParentMethods, boolean searchReturnType) { List<Method> methods = searchParentMethods ? findMatchingMethods(m) : Collections.singletonList(m); for (Method m2 : methods) for (Annotation a2 : m2.getAnnotations()) if (a.isInstance(a2)) return (T)a2; if (searchReturnType) { Type t = m.getGenericReturnType(); if (Value.isType(t)) return getAnnotation(a, Value.getParameterType(t)); return getAnnotation(a, t); } return null; }
public static <T extends Annotation> List<T> getAnnotations(Class<T> a, Method m, int index, boolean searchParentMethods, boolean searchArgType, boolean parentFirst) { List<T> l = new ArrayList<>(); List<Method> methods = searchParentMethods ? findMatchingMethods(m) : Collections.singletonList(m); for (Method m2 : methods) for (Annotation a2 : m2.getParameterAnnotations()[index])
/** * Finds the annotation of the specified type defined on the specified method. * * @param a * The annotation to search for. * @param m * The method to find the annotation on. * @param searchParentMethods * If <jk>true</jk>, searches methods with the same signature on the parent classes or interfaces. * <br>The search is performed in child-to-parent order. * @param searchReturnType * If <jk>true</jk>, searches the return type on the method for the specified annotation. * @return * The annotation if found, or <jk>null</jk> if not. */ @SuppressWarnings("unchecked") public static <T extends Annotation> T getAnnotation(Class<T> a, Method m, boolean searchParentMethods, boolean searchReturnType) { List<Method> methods = searchParentMethods ? findMatchingMethods(m) : Collections.singletonList(m); for (Method m2 : methods) for (Annotation a2 : m2.getAnnotations()) if (a.isInstance(a2)) return (T)a2; if (searchReturnType) { Type t = m.getGenericReturnType(); if (Value.isType(t)) return getAnnotation(a, Value.getParameterType(t)); return getAnnotation(a, t); } return null; }
public static <T extends Annotation> List<T> getAnnotations(Class<T> a, Method m, int index, boolean searchParentMethods, boolean searchArgType, boolean parentFirst) { List<T> l = new ArrayList<>(); List<Method> methods = searchParentMethods ? findMatchingMethods(m) : Collections.singletonList(m); for (Method m2 : methods) for (Annotation a2 : m2.getParameterAnnotations()[index])
List<Method> methods = searchParentMethods ? findMatchingMethods(m) : Collections.singletonList(m); for (Method m2 : methods) for (Annotation a2 : m2.getParameterAnnotations()[index])
/** * Finds the annotation of the specified type defined on the specified method. * * @param a * The annotation to search for. * @param m * The method to find the annotation on. * @param searchParentMethods * If <jk>true</jk>, searches methods with the same signature on the parent classes or interfaces. * <br>The search is performed in child-to-parent order. * @param searchReturnType * If <jk>true</jk>, searches the return type on the method for the specified annotation. * @return * The annotation if found, or <jk>null</jk> if not. */ @SuppressWarnings("unchecked") public static <T extends Annotation> T getAnnotation(Class<T> a, Method m, boolean searchParentMethods, boolean searchReturnType) { List<Method> methods = searchParentMethods ? findMatchingMethods(m) : Collections.singletonList(m); for (Method m2 : methods) for (Annotation a2 : m2.getAnnotations()) if (a.isInstance(a2)) return (T)a2; if (searchReturnType) { Type t = m.getGenericReturnType(); if (Value.isType(t)) return getAnnotation(a, Value.getParameterType(t)); return getAnnotation(a, t); } return null; }
List<Method> methods = searchParentMethods ? findMatchingMethods(m) : Collections.singletonList(m); for (Method m2 : methods) for (Annotation a2 : m2.getParameterAnnotations()[index])
List<Method> methods = searchParentMethods ? findMatchingMethods(m) : Collections.singletonList(m); for (Method m2 : methods) for (Annotation a2 : m2.getParameterAnnotations()[index])
@Test public void findMatchingMethods() throws Exception { assertObjectEquals("['public int org.apache.juneau.utils.ClassUtilsTest$I3.foo(int)','public int org.apache.juneau.utils.ClassUtilsTest$I2.foo(int)','public abstract int org.apache.juneau.utils.ClassUtilsTest$I1.foo(int)']", ClassUtils.findMatchingMethods(I3.class.getMethod("foo", int.class))); }