Get pertinent method and fill the argument list from message arguments

@param dsClass
@param message
@param arguments
@return
@throws java.lang.NoSuchMethodException
355322
public Method getMethodFromDataService(final Class dsClass, final MessageFromClient message, List<Object> arguments) throws NoSuchMethodException {
		logger.debug("Try to find method {} on class {}", message.getOperation(), dsClass);
		List<String> parameters = message.getParameters();
		int nbparam = parameters.size() - getNumberOfNullEnderParameter(parameters); // determine how many parameter is null at the end
		List<Method> candidates = getSortedCandidateMethods(message.getOperation(), dsClass.getMethods()); // take only method with the good name, and orderedby number of arguments
		if (!candidates.isEmpty()) {
			while (nbparam <= parameters.size()) {
				for (Method method : candidates) {
					if (method.getParameterTypes().length == nbparam) {
						logger.debug("Process method {}", method.getName());
						try {
							checkMethod(method, arguments, parameters, nbparam);
							logger.debug("Method {}.{} with good signature found.", dsClass, message.getOperation());
							return method;
						} catch (JsonMarshallerException | JsonUnmarshallingException | IllegalArgumentException iae) {
							logger.debug("Method {}.{} not found. Some arguments didn't match. {}.", new Object[]{dsClass, message.getOperation(), iae.getMessage()});
						}
						arguments.clear();
					}
				}
				nbparam++;
			}
		}
		throw new NoSuchMethodException(dsClass.getName() + "." + message.getOperation());
	}
838995
private void doListGet(final Message<JsonObject> message) {
    final String name = message.body().getString("name");
    if (name == null) {
      message.reply(new JsonObject().putString("status", "error").putString("message", "No name specified."));
      return;
    }

    final Integer index = message.body().getInteger("index");
    if (index == null) {
      message.reply(new JsonObject().putString("status", "error").putString("message", "No index specified."));
      return;
    }

    context.execute(new Action<Object>() {
      @Override
      public Object perform() {
        return data.getList(formatKey(name)).get(index);
      }
    }, new Handler<AsyncResult<Object>>() {
      @Override
      public void handle(AsyncResult<Object> result) {
        if (result.failed()) {
          message.reply(new JsonObject().putString("status", "error").putString("message", result.cause().getMessage()));
        } else {
          message.reply(new JsonObject().putString("status", "ok").putValue("result", result.result()));
        }
      }
    });
  }
591888
protected Member findMemberIn (List<Member> memberList, Class<?>[] parameterTypes)
        throws NoSuchMethodException
    {
        List<Member> matchingMembers = new ArrayList<Member>();

        for (Iterator<Member> it = memberList.iterator(); it.hasNext();) {
            Member member = it.next();
            Class<?>[] methodParamTypes = _paramMap.get(member);

            // check for exactly equal method signature
            if (Arrays.equals(methodParamTypes, parameterTypes)) {
                return member;
            }

            if (ClassUtil.compatibleClasses(methodParamTypes, parameterTypes)) {
                matchingMembers.add(member);
            }
        }

        if (matchingMembers.isEmpty()) {
            throw new NoSuchMethodException(
                "No member in " + _clazz.getName() + " matching given args");
        }
        if (matchingMembers.size() == 1) {
            return matchingMembers.get(0);
        }

        return findMostSpecificMemberIn(matchingMembers);
    }
1318444
public static Method[] candidateMethods(Method[] methods, Class<?>[] argTypes) {
        return candidates(methods, collectSignatures(methods), collectVarArgs(methods), argTypes);
    }
1211528
private String getMethodName(Map<String, Command> references) throws NoSuchMethodException, IntrospectionException, Exception
	{
		if (methodName == null)
		{
			String methodValue = null;
			if (isTag("class")) { //$NON-NLS-1$
				addArgument(new Argument(String.class, data), 0);
				methodValue = "forName"; //$NON-NLS-1$
			}
			else if (isPrimitive())
			{
				if (isTag("char")) { //$NON-NLS-1$
					if (data.length() != 1)
					{
						throw new IntrospectionException(Messages.getString("beans.43", //$NON-NLS-1$
								data));
					}
					addArgument(new Argument(char.class, Character.valueOf(data.charAt(0))), 0);
				}
				else
				{
					addArgument(new Argument(String.class, data), 0);
				}
				methodValue = "new"; //$NON-NLS-1$
			}
			else if (isConstructor() || hasAttr("method", "new")) { //$NON-NLS-1$ //$NON-NLS-2$
				methodValue = "new"; //$NON-NLS-1$
			}
			else if (isArray())
			{
				methodValue = "new"; //$NON-NLS-1$
				int length = hasAttr("length") ? Integer //$NON-NLS-1$
						.parseInt(getAttr("length")) : getArgumentsNumber(); //$NON-NLS-1$
				copyArgumentsToCommands();
				addArgument(new Argument(int.class, Integer.valueOf(length)), 0);
			}
			else if (hasAttr("property")) { //$NON-NLS-1$
				String propertyValue = getAttr("property"); //$NON-NLS-1$
				if (hasAttr("index")) { //$NON-NLS-1$
					addArgument(new Argument(int.class, new Integer(getAttr("index"))), 0); //$NON-NLS-1$
				}

				BeanInfo beanInfo = Introspector.getBeanInfo(getTarget(references).getClass());
				PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();

				boolean methodFound = false;
				Method method = null;
				for (PropertyDescriptor pd : pds)
				{
					if (propertyValue.equals(pd.getName()))
					{
						int argsNum = getArgumentsNumber();
						if (hasAttr("index")) { //$NON-NLS-1$
							IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
							if (argsNum == 1)
							{
								method = ipd.getIndexedReadMethod();
							}
							else if (argsNum == 0)
							{
								method = ipd.getReadMethod();
							}
						}
						else
						{
							method = pd.getReadMethod();
						}

						if (method != null)
						{
							methodFound = matchMethodParams(method, references);
						}

						if (methodFound == false)
						{
							if (hasAttr("index")) { //$NON-NLS-1$
								IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
								if (argsNum == 2)
								{
									method = ipd.getIndexedWriteMethod();
								}
								else if (argsNum == 1)
								{
									method = ipd.getWriteMethod();
								}
							}
							else
							{
								method = pd.getWriteMethod();
							}
						}

						if (method != null)
						{
							methodFound = matchMethodParams(method, references);
						}
					}
				}

				if (method == null)
				{
					throw new NoSuchMethodException(Messages.getString("beans.44", //$NON-NLS-1$
							propertyValue));
				}
				methodValue = method.getName();
			}
			else if (hasAttr("method")) { //$NON-NLS-1$
				if (hasAttr("index")) { //$NON-NLS-1$
					addArgument(new Argument(int.class, Integer.valueOf(getAttr("index"))), 0); //$NON-NLS-1$
				}
				methodValue = getAttr("method"); //$NON-NLS-1$
			}
			else if (hasAttr("index")) { //$NON-NLS-1$
				addArgument(new Argument(int.class, Integer.valueOf(getAttr("index"))), 0); //$NON-NLS-1$
				methodValue = getArgumentsNumber() > 1 ? "set" : "get"; //$NON-NLS-1$ //$NON-NLS-2$
				if (ctx.isArray())
				{
					addArgument(ctx.getResult(), 0);
				}
			}
			else if (hasAttr("field")) { //$NON-NLS-1$
				addArgument(new Argument(Class.forName(getAttr("class"), true, //$NON-NLS-1$
						Thread.currentThread().getContextClassLoader())), 0);

				methodValue = "get"; //$NON-NLS-1$
			}
			else
			{
				throw new Exception(Messages.getString("beans.45")); //$NON-NLS-1$
			}
			methodName = methodValue;
		}
		return methodName;
	}
1152128
public static <T extends MethodDescription> ElementMatcher.Junction<T> takesArguments(int length) {
        return new MethodParametersMatcher<T>(new CollectionSizeMatcher<ParameterList<?>>(length));
    }
1103967
void createMethodBody(String classname, ExecutableElement methodElement, List<String> arguments, Writer writer) throws IOException {
		String methodName = getMethodName(methodElement);
		boolean ws = isWebsocketDataService(methodElement);
		String args = stringJoinAndDecorate(arguments, COMMA, new NothingDecorator());
		String keys = computeKeys(methodElement, arguments);
		createReturnOcelotPromiseFactory(classname, methodName, ws, args, keys, writer);
	}
1357764
public static @CheckForNull
    JavaClassAndMethod findMethod(JavaClass javaClass, String methodName, String methodSig) {
        return findMethod(javaClass, methodName, methodSig, ANY_METHOD);
    }
505366
public Method getNonProxiedMethod(Class cls, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException {
		return cls.getMethod(methodName, parameterTypes);
	}
208248
public BeanInvocation sayHello(String message) {
        BeanInvocation invocation = new BeanInvocation();
        try {
            invocation.setMethod(HelloService.class.getMethod("sayHello", String.class));
            invocation.setArgs(new Object[] { message });
        } catch (NoSuchMethodException e) {
            throw new CitrusRuntimeException("Failed to access remote service method", e);
        }
        return invocation;
    }
934480
public static Method[] candidateMethods(Method[] methods, Object[] args) {
        return candidateMethods(methods, collectArgTypes(args));
    }
274113
public static Object[] findMethodWithExactParameters(Object service, String methodName, List<?> args) {
        Object[] arguments = new Object[args.size()];
        for (int i = 0; i < args.size(); i++) {
            arguments[i] = args.get(i);
        }
        return findMethodWithExactParameters(service, methodName, arguments);
    }
1126117
public static <M extends PMessage<M,F>, F extends PField>
    MessageNamedArgumentFinder<M,F> forMessage(@Nonnull M message,
                                               @Nonnull FieldType... fieldTypes) {
        return new MessageNamedArgumentFinder<>(null, message, makeFieldTypes(fieldTypes));
    }
168675
@Override
    public Message newMessage(final String message, final Object... params) {
        return getParameterized().set(message, params);
    }
139435
private List<Type> getArgumentTypesWithoutMessage(
      MethodInvocationTree methodInvocationTree, VisitorState state) {
    List<Type> argumentTypes = new ArrayList<>();
    for (ExpressionTree argument : methodInvocationTree.getArguments()) {
      JCTree tree = (JCTree) argument;
      argumentTypes.add(tree.type);
    }
    removeMessageArgumentIfPresent(state, argumentTypes);
    return argumentTypes;
  }
1056415
public static Object invokeMethodOnSuperN(Class senderClass, GroovyObject receiver, String messageName, Object[] messageArguments) throws Throwable {
        MetaClass metaClass = receiver.getMetaClass();
        // ignore interception and missing method fallback
        Object result = null;
        try {
            result = metaClass.invokeMethod(senderClass, receiver, messageName, messageArguments, true, true);
        } catch (GroovyRuntimeException gre) {
            throw unwrap(gre);
        }
        return result;
    }
957022
@SuppressWarnings("unchecked")
	public static <T extends Message> T copy(final T message) {
		return message == null ? null : (T) message.copy();
	}