Java Reflection Method Annotation getMethodsWithAnnotation(Class annotation, Class clazz)

Here you can find the source of getMethodsWithAnnotation(Class annotation, Class clazz)

Description

Gets a list of methods with the given annotation

License

Open Source License

Parameter

Parameter Description
annotation The annotation to search for
clazz The class to search in

Return

The methods with the annotation

Declaration

public static List<Method> getMethodsWithAnnotation(Class<? extends Annotation> annotation, Class clazz) 

Method Source Code

//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.  j  a  v  a 2  s .com
     * Gets a list of methods with the given annotation
     * @param annotation The annotation to search for
     * @param clazz The class to search in
     * @return The methods with the annotation
     */
    public static List<Method> getMethodsWithAnnotation(Class<? extends Annotation> annotation, Class clazz) {
        Method[] methods = clazz.getMethods();
        List<Method> annotated = new ArrayList<Method>();
        for (Method m : methods)
            if (m.isAnnotationPresent(annotation))
                annotated.add(m);
        return annotated;
    }
}

Related

  1. getMethodsAnnotatedWith(Class owner, Class annotationClass, boolean includeSuper)
  2. getMethodsAnnotatedWith(Class clazz, Class annotClazz)
  3. getMethodsAnnotatedWith(Class clazz, Class annotation)
  4. getMethodsAnnotatedWith(final Class type, final Class annotation)
  5. getMethodsInAnnotation(Annotation anno)
  6. getMethodsWithAnnotation(Class type, Class obj)
  7. getMethodsWithAnnotation(Class clazz, Class annotationType)
  8. getMethodsWithAnnotation(Class type, Class annotation, boolean checkSuper)
  9. getMethodsWithAnnotation(final Class clazz, final Class... annotationClasses)