Java Reflection Annotation Find findAnnotationFromMethodOrClass(final Method method, final Class annotationClass)

Here you can find the source of findAnnotationFromMethodOrClass(final Method method, final Class annotationClass)

Description

find Annotation From Method Or Class

License

Apache License

Declaration

public static <T extends Annotation> T findAnnotationFromMethodOrClass(final Method method,
            final Class<T> annotationClass) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class Main {
    public static <T extends Annotation> T findAnnotationFromMethodOrClass(final Method method,
            final Class<T> annotationClass) {
        final T annotation = method.getAnnotation(annotationClass);
        if (annotation != null) {
            return annotation;
        }//from   w w w. j a  v a  2  s.  c o m

        final Class<?> originClass = method.getDeclaringClass();
        return originClass.getAnnotation(annotationClass);
    }
}

Related

  1. findAnnotationClass( Class c, Class base)
  2. findAnnotationDeclaringClass(Class annotationType, Class clazz)
  3. findAnnotationDeclaringClass(Class annotationType, Class classToFind)
  4. findAnnotationDeclaringClass(Class annotationType, Class clazz)
  5. findAnnotationFromClass(Class target, Class annotation)
  6. findAnnotationHelper( Class base, Type iface)
  7. findAnnotationIn(List modifiers, Class clazz)
  8. findAnnotationInAnnotations(AnnotatedElement annotatedElement, Class annotationClass)
  9. findAnnotationInAnyParameter(Method method, Class annotationClass)