Asserts only one method is annotated with annotation.

@param method collection of methods to validate
@param annotation annotation to propagate in exception message
495366
public static void assertOnlyOneMethod(final Collection<Method> methods, Class<? extends Annotation> annotation)
   {
      if (methods.size() > 1)
      {
         throw annotation == null ? MESSAGES.onlyOneMethodCanExist() : MESSAGES.onlyOneMethodCanExist2(annotation);
      }
   }
270900
private static boolean exemptedByAnnotation(
      List<? extends AnnotationTree> annotations,
      VisitorState state) {
    for (AnnotationTree annotation : annotations) {
      if (((JCAnnotation) annotation).type != null) {
        TypeSymbol tsym = ((JCAnnotation) annotation).type.tsym;
        if (EXEMPTING_METHOD_ANNOTATIONS.contains(tsym.getQualifiedName().toString())) {
          return true;
        }
      }
    }
    return false;
  }
561072
public static void validateMethodOrThrow(Method method) {
    Class<?> returnType = method.getReturnType();
    if (returnType.equals(Void.TYPE)) {
      return;
    } else if (!Publisher.class.isAssignableFrom(returnType)) {
      throw new UnsupportedOperationException("Service method return type can be Publisher only");
    }
    if (method.getParameterCount() > 1) {
      throw new UnsupportedOperationException("Service method can accept 0 or 1 parameters only");
    }
  }
107030
public static boolean isAnnotationPresent(final Class<? extends Annotation> annotation, final Method method) {
        final Annotation e = DaemonScanner.getAnnotation(annotation, method);
        return e != null;
    }
684085
public Hints findHint(Method method) {
        Hints hints = new Hints();
        for (Annotation annotation : method.getDeclaredAnnotations()) {
            findAllow(hints, annotation);
            findFormats(hints, annotation);
        }
        return hints;
    }
1145112
public static List<List<Annotation>> findAndMergeParameterAnnotations(Method method) {
        List<List<Annotation>> res = new ArrayList<List<Annotation>>(method.getParameterTypes().length);
        for (int i = 0; i < method.getParameterTypes().length; i++) {
            res.add(new LinkedList<Annotation>());
        }
        findAndMergeAnnotations(method.getDeclaringClass(), method, res);
        return res;
    }
636902
@SuppressWarnings("unchecked")
	public List<MethodParameter> getParametersWith(Class<? extends Annotation> annotation) {

		Assert.notNull(annotation, "Annotation must not be null!");

		return parametersWithAnnotationCache.computeIfAbsent(annotation, key -> {

			return getParameters().stream()//
					.filter(it -> it.hasParameterAnnotation((Class<? extends Annotation>) key))//
					.collect(Collectors.toList());
		});
	}
451180
public static void validateArgument(Method method, Class<? extends Annotation> annotationType,
                                        Class<?> expectedParameterType) {
        if (method.getParameterTypes().length != 1 || !method.getParameterTypes()[0].equals(expectedParameterType)) {
            throw new BeanCreationException(String.format(
                  "Method %s with @%s MUST take a single argument of type %s",
                  method,
                  annotationType.getName(),
                  expectedParameterType.getName()
            ));
        }
    }
209314
public Set<Method> getMethodsAnnotatedWith(final Class<? extends Annotation> annotation) {
        Iterable<String> methods = store.get(index(MethodAnnotationsScanner.class), annotation.getName());
        return getMethodsFromDescriptors(methods, loaders());
    }
1251148
public Set<Method> getMethodsWithAnyParamAnnotated(Annotation annotation) {
        return filter(getMethodsWithAnyParamAnnotated(annotation.annotationType()), withAnyParameterAnnotation(annotation));
    }
1288899
@SuppressWarnings({"ThrowableInstanceNeverThrown"})
    public static void validateIsStatic(Method method, List<Throwable> errors)
    {
        if (!Modifier.isStatic(method.getModifiers()))
        {
            errors.add(new Exception("Method " + method.getName() + "() should be static"));
        }
        if (!Modifier.isPublic(method.getDeclaringClass().getModifiers()))
        {
            errors.add(new Exception("Class " + method.getDeclaringClass().getName() + " should be public"));
        }
    }
389327
@SuppressWarnings("unchecked")
    public <A extends Annotation> A getAnnotation(final Method method, final Class<A> annClas) throws AnnotationReadException {
        
        final Class<?> clazz = method.getDeclaringClass();
        
        if(xmlInfo != null && xmlInfo.containsClassInfo(clazz.getName())) {
            final ClassInfo classInfo = xmlInfo.getClassInfo(clazz.getName());
            
            if(classInfo.containsMethodInfo(method.getName())) {
                MethodInfo methodInfo = classInfo.getMethodInfo(method.getName());
                if(methodInfo != null && methodInfo.containsAnnotationInfo(annClas.getName())) {
                    AnnotationInfo annInfo = methodInfo.getAnnotationInfo(annClas.getName());
                    try {
                        return (A)annotationBuilder.buildAnnotation(Class.forName(annInfo.getClassName()), annInfo);
                    } catch (ClassNotFoundException e) {
                        throw new AnnotationReadException(String.format("not found class '%s'", annInfo.getClassName()), e);
                    }
                }
            }
        }
        return method.getAnnotation(annClas);
    }
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;
		}
	}
1111999
public static boolean hasAnnotation(final MethodNode methodNode, final Class<? extends Annotation> annotationClass) {
        return !methodNode.getAnnotations(new ClassNode(annotationClass)).isEmpty();
    }
254790
private static void applyTimeout(FrameworkMethod method) {
        // if default test timeout is defined
        if (LifecycleHooks.getConfig().containsKey(JUnitSettings.TEST_TIMEOUT.key())) {
            // get default test timeout
            long defaultTimeout = LifecycleHooks.getConfig().getLong(JUnitSettings.TEST_TIMEOUT.key());
            // get @Test annotation
            Test annotation = method.getAnnotation(Test.class);
            // if annotation declared and current timeout is less than default
            if ((annotation != null) && (annotation.timeout() < defaultTimeout)) {
                // set test timeout interval
                MutableTest.proxyFor(method.getMethod()).setTimeout(defaultTimeout);
            }
        }
    }
878987
private void processMethod(final Method method) {
    CommandArgument annotation = method.getAnnotation(CommandArgument.class);
    if (annotation != null) {
      final String name = method.getName();
      final Class<?>[] paramTypes = method.getParameterTypes();
      final Annotation[][] paramAnnotations = method.getParameterAnnotations();
      final ArgumentProcessor<Object[]> argProcessor = new ArgumentProcessor<Object[]>();
      final Object[] defaultParams = new Object[paramTypes.length];
      final List<Integer> positionalParams = new ArrayList<Integer>();

      String key = annotation.value();
      if (key.equals("")) {
        key = name;
      }

      for (int i = 0; i < paramAnnotations.length; i++) {
        Class<?> paramType = paramTypes[i];
        if (paramType == Integer.class || paramType == int.class) {
          defaultParams[i] = 0;
        } else if (paramType == Long.class || paramType == long.class) {
            defaultParams[i] = 0L;
        } else if (paramType == Double.class || paramType == double.class) {
          defaultParams[i] = 0.0;
        } else if (paramType == Float.class || paramType == float.class) {
          defaultParams[i] = (float) 0.0;
        } else if (paramType == String.class) {
          defaultParams[i] = "";
        } else if (paramType == File.class) {
          defaultParams[i] = null;
        } else if (paramType == Boolean.class || paramType == boolean.class) {
          defaultParams[i] = false;
        } else {
          throw new IllegalArgumentException("Invalid type (" + paramType.getCanonicalName() + ") for option parameter: method=" + method.getDeclaringClass().getCanonicalName() + "." + name);
        }

        int j;
        for (j = 0; j < paramAnnotations[i].length; j++) {
          if (paramAnnotations[i][j] instanceof OptionArgument) {
            OptionArgument optAnnotation = (OptionArgument) paramAnnotations[i][j];
            String optKey = optAnnotation.value();
            if (optKey.equals("")) {
              throw new IllegalArgumentException("OptionArgument on parameter requires key (method=`" + method.getDeclaringClass().getCanonicalName() + "." + name + "').");
            }

            char optShortKey = optAnnotation.shortKey();
            if (optShortKey == '\0') {
              optShortKey = optKey.charAt(0);
            }

            final int index = i;
            if (paramType == Integer.class || paramType == int.class) {
              argProcessor.addOption(optKey, optShortKey, new Command<Object[]>() {
                public void process(Queue<String> argq,
                    Object[] state) {
                  state[index] = Integer.parseInt(argq.remove());
                }
              });
            } else if (paramType == Long.class || paramType == long.class) {
              argProcessor.addOption(optKey, optShortKey, new Command<Object[]>() {
                public void process(Queue<String> argq,
                    Object[] state) {
                  state[index] = Long.parseLong(argq.remove());
                }
              });
            } else if (paramType == Boolean.class || paramType == boolean.class) {
              argProcessor.addOption(optKey, optShortKey, new Command<Object[]>() {
                public void process(Queue<String> argq,
                    Object[] state) {
                  state[index] = true;
                }
              });
            } else if (paramType == String.class) {
              argProcessor.addOption(optKey, optShortKey, new Command<Object[]>() {
                public void process(Queue<String> argq,
                    Object[] state) {
                  state[index] = argq.remove();
                }
              });
            } else if (paramType == Double.class || paramType == double.class) {
              argProcessor.addOption(optKey, optShortKey, new Command<Object[]>() {
                public void process(Queue<String> argq,
                    Object[] state) {
                  state[index] = Double.parseDouble(argq.remove());
                }
              });
            } else if (paramType == Float.class || paramType == float.class) {
              argProcessor.addOption(optKey, optShortKey, new Command<Object[]>() {
                public void process(Queue<String> argq,
                    Object[] state) {
                  state[index] = Float.parseFloat(argq.remove());
                }
              });
            } else if (paramType == File.class) {
              argProcessor.addOption(optKey, optShortKey, new Command<Object[]>() {
                public void process(Queue<String> argq,
                    Object[] state) {
                  state[index] = new File(argq.remove());
                }
              });
            }

            break;
          }
        }

        // If there is no OptionArgument annotation, treat it as a
        // positional parameter.
        if (j >= paramAnnotations[i].length) {
          positionalParams.add(i);
        }
      }

      // The default command will parse out all the positional parameters
      // from what's left over after all the options have been processed.
      argProcessor.setDefaultCommand(new Command<Object[]>() {
        public void process(Queue<String> argq, Object[] state) {
          for (int index : positionalParams) {
            if (argq.isEmpty()) {
              break;
            }
            Class<?> paramType = paramTypes[index];
            if (paramType == Integer.class || paramType == int.class) {
              state[index] = Integer.parseInt(argq.remove());
            } else if (paramType == Long.class || paramType == long.class) {
              state[index] = Long.parseLong(argq.remove());
            } else if (paramType == Double.class || paramType == double.class) {
              state[index] = Double.parseDouble(argq.remove());
            } else if (paramType == Float.class || paramType == float.class) {
              state[index] = Float.parseFloat(argq.remove());
            } else if (paramType == String.class) {
              state[index] = argq.remove();
            } else if (paramType == File.class) {
              state[index] = new File(argq.remove());
            } else if (paramType == Boolean.class || paramType == boolean.class) {
              state[index] = Boolean.parseBoolean(argq.remove());
            } else {
              throw new UnexpectedException();
            }
          }
        }
      });

      // Add the command that processes its arguments and invokes the
      // method.
      addCommand(key, new Command<T>(){
        public void process(Queue<String> argq, T state) {
          Object[] params = defaultParams.clone();
          argProcessor.process(argq, params);
          try {
            method.invoke(state, params);
          } catch (IllegalArgumentException e) {
            throw new UnexpectedException(e);
          } catch (IllegalAccessException e) {
            throw new UnexpectedException(e);
          } catch (InvocationTargetException e) {
            throw new UnexpectedException(e);
          }
        }
      });
    }
  }
999742
private static void inspectRecursively(Class<?> c, List<Method> s, Class<? extends Annotation> annotationType) {

      for (Method m : c.getDeclaredMethods()) {
         // don't bother if this method has already been overridden by a subclass
         if (notFound(m, s) && m.isAnnotationPresent(annotationType)) {
            s.add(m);
         }
      }

      if (!c.equals(Object.class)) {
         if (!c.isInterface()) {
            inspectRecursively(c.getSuperclass(), s, annotationType);
         }
         for (Class<?> ifc : c.getInterfaces()) inspectRecursively(ifc, s, annotationType);
      }
   }