Here you can find the source of getMethodsIncludingHierarchy(Object comp, Class extends Annotation> annotation)
Parameter | Description |
---|---|
comp | a parameter |
annotation | a parameter |
public static List<Method> getMethodsIncludingHierarchy(Object comp, Class<? extends Annotation> annotation)
//package com.java2s; //License from project: LGPL import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.LinkedList; import java.util.List; public class Main { /**//from w ww . j a va 2s . c om * same as getMethod but uses while loop to check hierarchy * @param comp * @param annotation * @return */ public static List<Method> getMethodsIncludingHierarchy(Object comp, Class<? extends Annotation> annotation) { LinkedList<Method> result = new LinkedList<Method>(); Class<?> current = comp.getClass(); while (current != null) { result.addLast(getMethod(current, annotation)); current = current.getSuperclass(); } return result; } /** * Checks for annotation of the class * @param compClassOrSuper * @param annotation * @return */ private static Method getMethod(Class<?> compClassOrSuper, Class<? extends Annotation> annotation) { for (Method m : compClassOrSuper.getMethods()) { if (m.getAnnotation(annotation) != null) { return m; } } return null; } }