public Object chooseMethod(Class[] arguments, boolean coerce) { if (arguments.length == 0) { return MetaClassHelper.chooseEmptyMethodParams(methods); } else if (arguments.length == 1 && arguments[0] == null) { return MetaClassHelper.chooseMostGeneralMethodWith1NullParam(methods); } else { List matchingMethods = new ArrayList(); final int len = methods.size(); final Object[] data = methods.getArray(); for (int i = 0; i != len; ++i) { Object method = data[i]; // making this false helps find matches if (MetaClassHelper.isValidMethod(method, arguments)) { matchingMethods.add(method); } } if (matchingMethods.isEmpty()) { return null; } else if (matchingMethods.size() == 1) { return matchingMethods.get(0); } return chooseMostSpecificParams(CLOSURE_DO_CALL_METHOD, matchingMethods, arguments); } }
if (MetaClassHelper.isValidMethod(methodOrList, argClasses)) { return methodOrList; } else if (methodCount == 1) { Object method = methods.get(0); if (MetaClassHelper.isValidMethod(method, argClasses)) { return method; if (MetaClassHelper.isValidMethod(method, argClasses)) { if (matchingMethods == null) matchingMethods = method;
/** * Checks that the given parameters are valid to call this method * * @param arguments the arguments to check * @throws IllegalArgumentException if the parameters are not valid */ public void checkParameters(Class[] arguments) { // lets check that the argument types are valid if (!MetaClassHelper.isValidMethod(getParameterTypes(), arguments)) { throw new IllegalArgumentException( "Parameters to method: " + getName() + " do not match types: " + InvokerHelper.toString(getParameterTypes()) + " for arguments: " + InvokerHelper.toString(arguments)); } } public boolean isMethod(MetaMethod method) {