Lookup a method annotation.

@param annotationClass the annotation class.
@return the annotation object or {@literal null} if not found.
760047
@Override
    public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
        return method.getAnnotation(annotationClass);
    }
1248792
public <A extends Annotation> A findAnnotationOnBean(Class<A> annotationType) {
        return applicationContext.findAnnotationOnBean(beanName, annotationType);
    }
1373676
private List<Class<?>> getValidJPAAnnotationsFromMethod(Class<?> clazz, Method method, int numberOfParams,
            Class<?> entityClazz)
    {
        List<Class<?>> annotations = new ArrayList<Class<?>>();

        for (Annotation methodAnnotation : method.getAnnotations())
        {
            Class<?> methodAnnotationType = methodAnnotation.annotationType();

            if (isValidJPAEntityListenerAnnotation(methodAnnotationType))
            {

                // verify method signature

                // verify exceptions
                boolean hasUncheckedExceptions = false;
                for (Class<?> exception : method.getExceptionTypes())
                {
                    if (!ReflectUtils.hasSuperClass(RuntimeException.class, exception))
                    {
                        hasUncheckedExceptions = true;
                        break;
                    }
                }

                if (hasUncheckedExceptions)
                {
                    log.info("Skipped method(" + clazz.getName() + "." + method.getName()
                            + ") Must not throw unchecked exceptions.");
                    continue;
                }

                // return type must be "void"
                if (!method.getReturnType().getSimpleName().equals("void"))
                {
                    log.info("Skipped method(" + clazz.getName() + "." + method.getName()
                            + ") Must have \"void\" return type.");
                    continue;
                }
                // argument must be an Entity or Object
                Class<?>[] paramTypes = method.getParameterTypes();
                if (paramTypes.length != numberOfParams)
                {
                    log.info("Skipped method(" + clazz.getName() + "." + method.getName() + ") Must have "
                            + numberOfParams + " parameter.");
                    continue;
                }

                if (numberOfParams == 1)
                {
                    Class<?> parameter = paramTypes[0];
                    if (!(parameter != null && parameter.isAssignableFrom(entityClazz)))
                    {
                        log.info("Skipped method(" + clazz.getName() + "." + method.getName()
                                + ") Must have only 1 \"Object\" type parameter.");
                        continue;
                    }
                }

                annotations.add(methodAnnotationType);
            }
        }
        return annotations;
    }
846895
public static Annotation getAnnotation(Annotation[] annotations, Class<?> annotationClass) {
        return Arrays.stream(annotations).filter(annotation -> annotation.annotationType().equals(annotationClass)).findFirst().orElse(null);
    }
915544
private void callAnnotatedMethod(final Class<? extends Annotation> annotationClass) {
        if (this.lifecycleMethod.get(annotationClass.getName()) != null) {
            for (final Method method : this.lifecycleMethod.get(annotationClass.getName())) {

                try {
                    ClassUtility.callMethod(method, this);
                } catch (final CoreException e) {
                    LOGGER.error(CALL_ANNOTATED_METHOD_ERROR, e);
                }
            }
        }
    }
840502
@SuppressWarnings("unchecked")
    public <T> List<T> getAnnotations(final Class<? extends Annotation> clazz) {
        return (List<T>) foundAnnotations.get(clazz);
    }
530666
public static <A extends Annotation> List<A> getRepeatableAnnotations(Method method, Class<A> annotationClass) {
        A[] annotations = method.getAnnotationsByType(annotationClass);
        if (annotations == null || annotations.length == 0) {
            for (Annotation metaAnnotation : method.getAnnotations()) {
                annotations = metaAnnotation.annotationType().getAnnotationsByType(annotationClass);
                if (annotations != null && annotations.length > 0) {
                    return Arrays.asList(annotations);
                }
            }
            Method superclassMethod = getOverriddenMethod(method);
            if (superclassMethod != null) {
                return getRepeatableAnnotations(superclassMethod, annotationClass);
            }
        }
        if (annotations == null) {
            return null;
        }
        return Arrays.asList(annotations);
    }
609918
public Set<Method> getMethodsAnnotatedWith(final Annotation annotation) {
        return filter(getMethodsAnnotatedWith(annotation.annotationType()), withAnnotation(annotation));
    }
38529
protected static <T extends Annotation> T getAnnotationFromContext(InvocationContext context, Class<T> clazz) {
        T result = context.getMethod().getAnnotation(clazz);
        return result != null ? result : context.getTarget().getClass().getAnnotation(clazz);
    }
798975
@SuppressWarnings("unchecked")
    private static Method getMethodOfInterest(Object cmp, Class<? extends Annotation> ann) {
        Class cmpClass = cmp.getClass();
        Class infoClass = infoClass(cmpClass);
        Method[] ms = infoClass.getMethods();
        for (Method m : ms) {
            if (m.getAnnotation(ann) != null) {
                if (m.getReturnType() != Void.TYPE || m.getParameterTypes().length > 0) {
                    throw new IllegalArgumentException("Invalid Method signature: " + m);
                }
                try {
                    return cmpClass.getMethod(m.getName());
                } catch (Exception ex) {
                    throw new ComponentException("Cannot find/access method: " + m);
                }
            }
        }
        throw new IllegalArgumentException("No " + ann.getCanonicalName() + " found in " + cmp.getClass());
    }
487900
public static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationType) {
		if (clazz == null) throw new IllegalArgumentException("Clazz parameter can't be null");
		
		A annotation = clazz.getAnnotation(annotationType);
		if (annotation != null) return annotation;
		
		for (Class<?> ifc : clazz.getInterfaces()) {
			annotation = findAnnotation(ifc, annotationType);
			if (annotation != null) return annotation;
		}
		
		if (!Annotation.class.isAssignableFrom(clazz))
			for (Annotation ann : clazz.getAnnotations()) {
				annotation = findAnnotation(ann.annotationType(), annotationType);
				if (annotation != null) return annotation;
			}
		
		Class<?> superClass = clazz.getSuperclass();
		if (superClass == null || superClass == Object.class) return null;
		return findAnnotation(superClass, annotationType);
	}
175577
private static <A extends Annotation> A getParameterAnnotation(Method method,
            int index, Class<A> annotationClass) {
        for (Annotation a : method.getParameterAnnotations()[index]) {
            if (annotationClass.isInstance(a)) {
                return annotationClass.cast(a);
            }
        }
        return null;
    }
485877
public static <T extends Annotation> T getAnnotation(Method method, Class<T> annotationClass) {
        T annotation = method.getAnnotation(annotationClass);
        if (annotation == null) {
            annotation = getAnnotation(method.getDeclaringClass(), annotationClass);
        }

        return annotation;
    }
1139076
public List<DetailParam> getParameterFromClassWithAnnotation(Class<?> baseClass, Class<?> annotationClass) {
        List<DetailParam> params = new ArrayList<>();
        Arrays.stream(baseClass.getDeclaredMethods()).forEach(method -> params.addAll(this.getParameterFromMethodWithAnnotation(baseClass, method, annotationClass)));
        return params;
    }
69867
public static <A extends Annotation> A getAnnotation(final Class<?> clazz, Class<A> annoClazz) {
        if (clazz == null || annoClazz == null) {
            return null;
        }

        return clazz.getAnnotation(annoClazz);
    }
290188
public static final <T extends Annotation> T getAnnotation(Object bean, String property, Class<T> annotationClass)
    {
        return (T) doFor(
            bean, 
            property, 
            null,
            (Object a, int i)->{Object o=Array.get(a, i);return o!=null?o.getClass().getAnnotation(annotationClass):null;},
            (List l, int i)->{return l.get(i).getClass().getAnnotation(annotationClass);},
            (Object b, Class c, String p)->{return getField(c, p).getAnnotation(annotationClass);}, 
            (Object b, Method m)->{return m.getAnnotation(annotationClass);});
    }
1310964
public Annotation getAnnotation(final Class<? extends Annotation> clazz) {
        final List<Annotation> found = foundAnnotations.get(clazz);
        return found == null || found.isEmpty() ? null : found.get(found.size() - 1);
    }