Returns an annotation by type from a method.

@param method is the method to find
@param annotationClass is the type of annotation
@param <A> is the type of annotation
@return annotation if it is found
196211
public static <A extends Annotation> A getAnnotation(Method method, Class<A> annotationClass) {
        A annotation = method.getAnnotation(annotationClass);
        if (annotation == null) {
            for (Annotation metaAnnotation : method.getAnnotations()) {
                annotation = metaAnnotation.annotationType().getAnnotation(annotationClass);
                if (annotation != null) {
                    return annotation;
                }
            }
            Method superclassMethod = getOverriddenMethod(method);
            if (superclassMethod != null) {
                annotation = getAnnotation(superclassMethod, annotationClass);
            }
        }
        return annotation;
    }
934108
private static Set<Annotation> httpMethodAnnotations(Method method) {
        return getAnnotations(method, FindOption.LOOKUP_SUPER_CLASSES)
                .stream()
                .filter(annotation -> HTTP_METHOD_MAP.containsKey(annotation.annotationType()))
                .collect(Collectors.toSet());
    }
947644
public static boolean hasMethodWithAnnotation(Class<?> type,
                                                  Class<? extends Annotation> annotationType,
                                                  boolean checkMetaAnnotations) {
        try {
            do {
                Method[] methods = type.getDeclaredMethods();
                for (Method method : methods) {
                    if (hasAnnotation(method, annotationType, checkMetaAnnotations)) {
                        return true;
                    }
                }
                type = type.getSuperclass();
            } while (type != null);
        } catch (Throwable e) {
            // ignore a class loading issue
        }
        return false;
    }
1201290
@Override
	@Nullable
	public String getMapping(Class<?> type, Method method) {

		Assert.notNull(type, "Type must not be null!");
		Assert.notNull(method, "Method must not be null!");

		String[] mapping = getMappingFrom(findMergedAnnotation(method, annotationType));
		String typeMapping = getMapping(type);

		if (mapping.length == 0) {
			return typeMapping;
		}

		return typeMapping == null || "/".equals(typeMapping) ? mapping[0] : join(typeMapping, mapping[0]);
	}
1212610
@SuppressWarnings("unchecked")
    public <T extends Annotation> T getParameterAnnotation(Class<T> annotationType) {
        Annotation[] anns = getParameterAnnotations();
        for (Annotation ann : anns) {
            if (annotationType.isInstance(ann)) {
                return (T) ann;
            }
        }
        return null;
    }
1258956
public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
        return method.getAnnotation(annotationType);
    }
1248792
public <A extends Annotation> A findAnnotationOnBean(Class<A> annotationType) {
        return applicationContext.findAnnotationOnBean(beanName, annotationType);
    }
424226
public static <T extends Annotation> T getAnnotation(Method method, Class<T> type) {
		for (Annotation a : getAnnotations(method)) {
			if (type.isInstance(a)) {
				return type.cast(a);
			}
		}
		return null;
	}
107030
public static boolean isAnnotationPresent(final Class<? extends Annotation> annotation, final Method method) {
        final Annotation e = DaemonScanner.getAnnotation(annotation, method);
        return e != null;
    }
405969
@DefinedBy(Api.LANGUAGE_MODEL)
    public <A extends Annotation> A[] getAnnotationsByType(Class<A> annoType) {

        if (!annoType.isAnnotation())
            throw new IllegalArgumentException("Not an annotation type: "
                                               + annoType);
        // If annoType does not declare a container this is equivalent to wrapping
        // getAnnotation(...) in an array.
        Class <? extends Annotation> containerType = getContainer(annoType);
        if (containerType == null) {
            A res = getAnnotation(annoType);
            int size = res == null ? 0 : 1;

            @SuppressWarnings("unchecked") // annoType is the Class for A
            A[] arr = (A[])java.lang.reflect.Array.newInstance(annoType, size);
            if (res != null)
                arr[0] = res;
            return arr;
        }

        // So we have a containing type
        String annoTypeName = annoType.getName();
        String containerTypeName = containerType.getName();
        int directIndex = -1, containerIndex = -1;
        Attribute.Compound direct = null, container = null;
        // Find directly (explicit or implicit) present annotations
        int index = -1;
        for (Attribute.Compound attribute : getAnnotationMirrors()) {
            index++;
            if (attribute.type.tsym.flatName().contentEquals(annoTypeName)) {
                directIndex = index;
                direct = attribute;
            } else if(containerTypeName != null &&
                      attribute.type.tsym.flatName().contentEquals(containerTypeName)) {
                containerIndex = index;
                container = attribute;
            }
        }

        // Deal with inherited annotations
        if (direct == null && container == null &&
                annoType.isAnnotationPresent(Inherited.class))
            return getInheritedAnnotations(annoType);

        Attribute.Compound[] contained = unpackContained(container);

        // In case of an empty legacy container we might need to look for
        // inherited annos as well
        if (direct == null && contained.length == 0 &&
                annoType.isAnnotationPresent(Inherited.class))
            return getInheritedAnnotations(annoType);

        int size = (direct == null ? 0 : 1) + contained.length;
        @SuppressWarnings("unchecked") // annoType is the Class for A
        A[] arr = (A[])java.lang.reflect.Array.newInstance(annoType, size);

        // if direct && container, which is first?
        int insert = -1;
        int length = arr.length;
        if (directIndex >= 0 && containerIndex >= 0) {
            if (directIndex < containerIndex) {
                arr[0] = AnnotationProxyMaker.generateAnnotation(direct, annoType);
                insert = 1;
            } else {
                arr[arr.length - 1] = AnnotationProxyMaker.generateAnnotation(direct, annoType);
                insert = 0;
                length--;
            }
        } else if (directIndex >= 0) {
            arr[0] = AnnotationProxyMaker.generateAnnotation(direct, annoType);
            return arr;
        } else {
            // Only container
            insert = 0;
        }

        for (int i = 0; i + insert < length; i++)
            arr[insert + i] = AnnotationProxyMaker.generateAnnotation(contained[i], annoType);

        return arr;
    }
69536
@SuppressWarnings("unchecked")
	public <T extends Annotation> T getMethodAnnotation(Class<T> annotationType) {
		return (this.method != null ? this.method.getAnnotation(annotationType) :
				(T) this.constructor.getAnnotation(annotationType));
	}
846895
public static Annotation getAnnotation(Annotation[] annotations, Class<?> annotationClass) {
        return Arrays.stream(annotations).filter(annotation -> annotation.annotationType().equals(annotationClass)).findFirst().orElse(null);
    }
632957
private static <T extends Annotation, R> Builder<R> getAnnotatedInstances(
            AnnotatedElement method, AnnotatedElement clazz, Class<T> annotationType, Class<R> resultType) {
        final Builder<R> builder = new Builder<>();
        Stream.concat(findAll(method, annotationType).stream(),
                      findAll(clazz, annotationType).stream())
              .forEach(annotation -> builder.add(getInstance(annotation, resultType)));
        return builder;
    }
1061772
public Method findAnnotatedMethod(Class<?> clazz, Class<? extends Annotation> anno) {
    for (Method meth : clazz.getMethods()) {
      if (meth.isAnnotationPresent(anno)) {
        return meth;
      }
    }
    return null;
  }
924445
protected static <A> A getAnnotation(Class<A> annotationClass, Class endpointClass) {
        if (endpointClass == Object.class || endpointClass == null) return null;
        A annotation = _getAnnotation(annotationClass, endpointClass);
        if (annotation == null) {
            Class sCls = endpointClass.getSuperclass();
            if (sCls != null) {
                annotation = _getAnnotation(annotationClass, sCls);
            }

            if (annotation == null) {
                Class[] inces = endpointClass.getInterfaces();
                for (Class infc : inces) {
                    annotation = _getAnnotation(annotationClass, infc);
                    if (annotation != null) {
                        return annotation;
                    }
                }
                annotation = getAnnotation(annotationClass, sCls);
                if (annotation == null) {
                    for (Class infc : inces) {
                        annotation = getAnnotation(annotationClass, infc);
                        if (annotation != null) {
                            return annotation;
                        }
                    }
                }
            }
        }
        return annotation;
    }
370234
public static Annotation[] getAnnotations(Method method) {
		try {
			return BridgeMethodResolver.findBridgedMethod(method).getAnnotations();
		}
		catch (Exception ex) {
			// Assuming nested Class values not resolvable within annotation attributes...
			logIntrospectionFailure(method, ex);
			return null;
		}
	}
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;
    }