Java Reflection Method Annotation getMethodsAnnotatedWith(final Class type, final Class annotation)

Here you can find the source of getMethodsAnnotatedWith(final Class type, final Class annotation)

Description

get Methods Annotated With

License

Open Source License

Declaration

public static List<Method> getMethodsAnnotatedWith(final Class<?> type,
            final Class<? extends Annotation> annotation) 

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.Arrays;
import java.util.List;

public class Main {
    public static List<Method> getMethodsAnnotatedWith(final Class<?> type,
            final Class<? extends Annotation> annotation) {
        final List<Method> methods = new ArrayList<Method>();
        Class<?> klass = type;
        while (klass != Object.class) {
            final List<Method> allMethods = new ArrayList<Method>(
                    Arrays.asList(klass.getDeclaredMethods()));
            for (final Method method : allMethods) {
                if (annotation == null
                        || method.isAnnotationPresent(annotation)) {
                    Annotation annotInstance = method
                            .getAnnotation(annotation);
                    methods.add(method);
                }//from ww w .  ja v a  2 s  . co m
            }
            klass = klass.getSuperclass();
        }
        return methods;
    }
}

Related

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