Here you can find the source of getMethodsWithAnnotation(Class> type, Class extends Annotation> annotation, boolean checkSuper)
Parameter | Description |
---|---|
type | the class to search |
annotation | the annotation to match |
checkSuper | whether or not to check all of the class' supertypes |
public static List<Method> getMethodsWithAnnotation(Class<?> type, Class<? extends Annotation> annotation, boolean checkSuper)
//package com.java2s; //License from project: Open Source License import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; public class Main { /**/*www .jav a2 s . com*/ * Gets a list of all methods within a class that are marked with an annotation. * * @param type the class to search * @param annotation the annotation to match * @param checkSuper whether or not to check all of the class' supertypes * @return the relevant list of methods */ public static List<Method> getMethodsWithAnnotation(Class<?> type, Class<? extends Annotation> annotation, boolean checkSuper) { List<Method> methods = new ArrayList<>(); Class<?> clazz = type; while (clazz != Object.class) { for (Method method : clazz.getDeclaredMethods()) { if (method.isAnnotationPresent(annotation)) { methods.add(method); } } if (!checkSuper) { break; } clazz = clazz.getSuperclass(); } return methods; } /** * Gets a list of all methods within a class that are marked with an annotation. * * @param type the class to search * @param annotation the annotation to match * @return the relevant list of methods */ public static List<Method> getMethodsWithAnnotation(Class<?> type, Class<? extends Annotation> annotation) { return getMethodsWithAnnotation(type, annotation, false); } }