Finds a method annotated with the specified annotation. This method can
be defined in the specified class, or one of its parents.

@return the matching method, or <tt>null</tt> if any
189913
public static <T extends Annotation> Method findMethodWithAnnotation(Class<?> clazz, Class<T> annotationType) {
        Method annotatedMethod = null;
        for (Method method : clazz.getDeclaredMethods()) {
            T annotation = AnnotationUtils.findAnnotation(method, annotationType);
            if (annotation != null) {
                if (annotatedMethod != null) {
                    throw new BeanCreationException("Only ONE method with @" + annotationType.getName()
                          + " is allowed on " + clazz.getName() + ".");
                }
                annotatedMethod = method;
            }
        }

        if((annotatedMethod != null) || clazz.equals(Object.class)){
            return annotatedMethod;
        } else {
            return findMethodWithAnnotation(clazz.getSuperclass(), annotationType);
        }
    }
54715
@SuppressWarnings("unchecked")
	private static Method findMainMethod(Class clazz) {
		try {
			Method mainMethod = clazz.getMethod("main", new Class[] { String[].class });
			int modifiers = mainMethod.getModifiers();
			if (Modifier.isPublic(modifiers) && 
				Modifier.isStatic(modifiers)) {
				return mainMethod;
			}
		} catch (NoSuchMethodException nsme) {
		}
		return null;
	}
290133
<A extends Annotation> A findAnnotation(TypeElement element, Class<A> anno) {

    final A annotation = element.getAnnotation(anno);
    if (annotation != null) {
      return annotation;
    }
    final TypeMirror typeMirror = element.getSuperclass();
    if (typeMirror.getKind() == TypeKind.NONE) {
      return null;
    }
    final TypeElement element1 = (TypeElement)typeUtils.asElement(typeMirror);
    return findAnnotation(element1, anno);
  }
459151
public static Method getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) {
        if (clazz == null || methodName == null || methodName.length() == 0) {
            return null;
        }

        for (Class<?> itr = clazz; hasSuperClass(itr); ) {
            Method[] methods = itr.getDeclaredMethods();

            for (Method method : methods) {
                if (method.getName().equals(methodName) && Arrays.equals(method.getParameterTypes(), parameterTypes)) {
                    return method;
                }
            }

            itr = itr.getSuperclass();
        }
        return null;
    }
684085
public Hints findHint(Method method) {
        Hints hints = new Hints();
        for (Annotation annotation : method.getDeclaredAnnotations()) {
            findAllow(hints, annotation);
            findFormats(hints, annotation);
        }
        return hints;
    }
157633
public static List<Method> getAllAnnotationPresentMethod(Class<?> type,
                                                             Class<? extends Annotation> annotation) {
        List<Method> methods = getAllMethod(type);

        if (methods.isEmpty()) {
            return Collections.emptyList();
        }

        return methods.stream().filter(method -> method.isAnnotationPresent(annotation))
            .collect(Collectors.toList());
    }
1106851
public static Method findMethod(Object obj, String methodName, Object... params) {
        Class<?>[] classArray = new Class<?>[params.length];
        for (int i = 0; i < params.length; i++) {
            classArray[i] = params[i].getClass();
        }
        try {
            //look on all the public, protected, default and private methods of the class hierarchy.
            Class<?> klass = obj.getClass();
            while (klass != null) {
                for (Method method : klass.getDeclaredMethods()) {
                    //check if the method name matches along with the number of parameters
                    if (method.getName().equals(methodName) && method.getParameterCount() == classArray.length) {
                        Class<?>[] paramClasses = method.getParameterTypes();

                        //Then check one by one all the provided parameters and see if they match the defined ones.
                        boolean parametersMatch = true;
                        for(int i = 0; i < params.length; i++) {
                            if(!paramClasses[i].isAssignableFrom(classArray[i])) {
                                parametersMatch = false;
                                break;
                            }
                        }

                        if(parametersMatch) { //exact match, return the method
                            return method;
                        }
                    }
                }
                klass = klass.getSuperclass();
            }

            //nothing found
            throw new NoSuchMethodException();
        }
        catch (NoSuchMethodException ex) {
            throw new RuntimeException(ex);
        }
    }
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;
    }
126605
public static Method findMatchingMethod(Method originalMethod, String methodName) {
        Class<?> originalClass = originalMethod.getDeclaringClass();

        return AccessController.doPrivileged(new PrivilegedAction<Method>() {
            @Override
            public Method run() {
                return findMatchingMethod(originalMethod, methodName, originalClass, new ResolutionContext(), originalClass);
            }
        });
    }
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;
    }
946610
public Optional<? extends MethodExecutionHandle<?, Object>> findFallbackMethod(MethodInvocationContext<Object, Object> context) {
        Class<?> declaringType = context.getDeclaringType();
        Optional<? extends MethodExecutionHandle<?, Object>> result = beanContext
                .findExecutionHandle(declaringType, Qualifiers.byStereotype(Fallback.class), context.getMethodName(), context.getArgumentTypes());
        if (!result.isPresent()) {
            Set<Class> allInterfaces = ReflectionUtils.getAllInterfaces(declaringType);
            for (Class i : allInterfaces) {
                result = beanContext
                    .findExecutionHandle(i, Qualifiers.byStereotype(Fallback.class), context.getMethodName(), context.getArgumentTypes());
                if (result.isPresent()) {
                    return result;
                }
            }
        }
        return result;
    }
1135594
public MethodDoc findMatchingMethod(MethodDoc method, MethodFinder mf) {

        // Look in this class's interface set
        MethodDoc md = findMatchingInterfaceMethod(method, mf);

        if (md != null) {
            return md;
        }

        // Look in this class's superclass ancestry
        ClassDoc superClass = getSuperclass();
        if (superClass != null) {

            md = superClass.getMatchingMethod(method, mf);
            if (md != null) {
                return md;
            }

            return superClass.findMatchingMethod(method, mf);
        }

        return null;
    }
853836
static <T extends Annotation> T findAnnotation(Method method, Class<T> clazz) {
		T annotation = AnnotationUtils.findAnnotation(method, clazz);
		if (annotation == null) {
			try {
				annotation = AnnotationUtils.findAnnotation(method.getDeclaringClass()
						.getMethod(method.getName(), method.getParameterTypes()), clazz);
			}
			catch (NoSuchMethodException | SecurityException ex) {
				if (log.isDebugEnabled()) {
					log.debug("Exception occurred while tyring to find the annotation",
							ex);
				}
			}
		}
		return annotation;
	}
1169361
public Set<Method> getMethodsWithAnyParamAnnotated(Class<? extends Annotation> annotation) {
        return getMethodsFromDescriptors(store.get(index(MethodParameterScanner.class), annotation.getName()), loaders());

    }
1251148
public Set<Method> getMethodsWithAnyParamAnnotated(Annotation annotation) {
        return filter(getMethodsWithAnyParamAnnotated(annotation.annotationType()), withAnyParameterAnnotation(annotation));
    }
591981
public static <A extends Annotation> A getAnnotation(final Class<A> annotation, final Method method) {
        try {
            return DaemonScanner.isAnnotationPresent(annotation, method.getDeclaringClass(), method.getName(), method.getParameterTypes());
        } catch(final NoSuchMethodException e) {
            return null;
        }
    }
205943
private static Method getMethod(String methodName, Class<?> clazz, Class<?>... args) {
        Method method;
        try {
            method = clazz.getMethod(methodName, args);
        } catch (NoSuchMethodException e1) {
            method = null;
        }
        return method;
    }