private static <T extends ParameterTypes> T checkCallableForArity(final int arity, final T[] callables, final int index) { final T callable = callables[index]; final int callableArity = callable.getArity(); if ( callableArity == arity ) return callable; // for arity 2 : // - callable arity 1 ([]...) is OK // - callable arity 2 (arg1, []...) is OK // - callable arity 3 (arg1, arg2, []...) is OK if ( callable.isVarArgs() && callableArity - 1 <= arity ) { return callable; } return null; }
private static <T extends ParameterTypes> T checkCallableForArity(final int arity, final T[] callables, final int index) { final T callable = callables[index]; final int callableArity = callable.getArity(); if ( callableArity == arity ) return callable; // for arity 2 : // - callable arity 1 ([]...) is OK // - callable arity 2 (arg1, []...) is OK // - callable arity 3 (arg1, arg2, []...) is OK if ( callable.isVarArgs() && callableArity - 1 <= arity ) { return callable; } return null; }
public static Object[] convertArguments(final ParameterTypes method, final IRubyObject arg0, final int addSpace) { final Class<?>[] paramTypes = method.getParameterTypes(); final Object[] javaArgs; if ( method.isVarArgs() ) { javaArgs = new Object[ 1 + addSpace ]; javaArgs[0] = convertVarArgumentsOnly(paramTypes[0], arg0); } else { javaArgs = new Object[ 1 + addSpace ]; javaArgs[0] = arg0.toJava(paramTypes[0]); } return javaArgs; }
private static int getExactnessScore(ParameterTypes paramTypes, IRubyObject[] args) { Class[] types = paramTypes.getParameterTypes(); int count = 0; if (paramTypes.isVarArgs()) { // varargs exactness gives the last N args as +1 since they'll already // have been determined to fit // dig out as many trailing args as possible that match varargs type int nonVarargs = types.length - 1; // add one for vararg count += 1; // check remaining args for (int i = 0; i < nonVarargs && i < args.length; i++) { if (types[i].equals(argClass(args[i]))) { count++; } } } else { for (int i = 0; i < args.length; i++) { if (types[i].equals(argClass(args[i]))) { count++; } } } return count; }
public static Object[] convertArguments(final ParameterTypes method, final IRubyObject arg0, final int addSpace) { final Class<?>[] paramTypes = method.getParameterTypes(); final Object[] javaArgs; if ( method.isVarArgs() ) { javaArgs = new Object[ 1 + addSpace ]; javaArgs[0] = convertVarArgumentsOnly(paramTypes[0], arg0); } else { javaArgs = new Object[ 1 + addSpace ]; javaArgs[0] = arg0.toJava(paramTypes[0]); } return javaArgs; }
private static int getExactnessScore(ParameterTypes paramTypes, IRubyObject[] args) { Class[] types = paramTypes.getParameterTypes(); int count = 0; if (paramTypes.isVarArgs()) { // varargs exactness gives the last N args as +1 since they'll already // have been determined to fit // dig out as many trailing args as possible that match varargs type int nonVarargs = types.length - 1; // add one for vararg count += 1; // check remaining args for (int i = 0; i < nonVarargs && i < args.length; i++) { if (types[i].equals(argClass(args[i]))) { count++; } } } else { for (int i = 0; i < args.length; i++) { if (types[i].equals(argClass(args[i]))) { count++; } } } return count; }
private static int calcExactnessScore(final ParameterTypes callable, final IRubyObject[] args) { final Class[] types = callable.getParameterTypes(); int count = 0; if ( callable.isVarArgs() ) { // varargs exactness gives the last N args as +1 since they'll already // have been determined to fit // dig out as many trailing args as possible that match varargs type final int nonVarargs = types.length - 1; count += 1; // add one for vararg // check remaining args for (int i = 0; i < nonVarargs && i < args.length; i++) { if ( types[i] == getJavaClass(args[i]) ) count++; } } else { for (int i = 0; i < args.length; i++) { if ( types[i] == getJavaClass(args[i]) ) count++; } } return count; }
private static int calcExactnessScore(final ParameterTypes callable, final IRubyObject[] args) { final Class[] types = callable.getParameterTypes(); int count = 0; if ( callable.isVarArgs() ) { // varargs exactness gives the last N args as +1 since they'll already // have been determined to fit // dig out as many trailing args as possible that match varargs type final int nonVarargs = types.length - 1; count += 1; // add one for vararg // check remaining args for (int i = 0; i < nonVarargs && i < args.length; i++) { if ( types[i] == getJavaClass(args[i]) ) count++; } } else { for (int i = 0; i < args.length; i++) { if ( types[i] == getJavaClass(args[i]) ) count++; } } return count; }
if ( callable.isVarArgs() ) { if ( callable.getArity() > args.length - 1 ) continue;
if ( callable.isVarArgs() ) { if ( callable.getArity() > args.length - 1 ) continue;
private static boolean assignableAndPrimitivableWithVarargs(ParameterTypes paramTypes, IRubyObject... args) { if ( ! paramTypes.isVarArgs() ) return false; // bail out if this is not a varargs method final Class[] types = paramTypes.getParameterTypes(); // if there's no args, we only match when there's just varargs if ( args.length == 0 ) return types.length <= 1; final int last = types.length - 1; if ( args.length < last ) return false; // can't match - paramTypes method is not usable! for ( int i = 0; i < last; i++ ) { // first check non-vararg argument types match if (!(ASSIGNABLE.match(types[i], args[i]) || PRIMITIVABLE.match(types[i], args[i]))) { return false; } } final Class varArgType = types[last].getComponentType(); // dig out as many trailing args as will fit, ensuring they match varargs type for ( int i = last; i < args.length; i++ ) { if (!(ASSIGNABLE.match(varArgType, args[i]) || PRIMITIVABLE.match(varArgType, args[i]))) { return false; } } return true; }
public static Object[] convertArguments(final ParameterTypes method, final IRubyObject[] args, final int addSpace) { final Class<?>[] paramTypes = method.getParameterTypes(); final Object[] javaArgs; final int len = args.length; if ( method.isVarArgs() ) { final int last = paramTypes.length - 1; javaArgs = new Object[ last + 1 + addSpace ]; for ( int i = 0; i < last; i++ ) { javaArgs[i] = args[i].toJava(paramTypes[i]); } javaArgs[ last ] = convertVarArgumentsOnly(paramTypes[ last ], last, args); } else { javaArgs = new Object[ len + addSpace ]; for ( int i = 0; i < len; i++ ) { javaArgs[i] = args[i].toJava(paramTypes[i]); } } return javaArgs; }
private static boolean assignableAndPrimitivableWithVarargs(ParameterTypes paramTypes, IRubyObject... args) { if ( ! paramTypes.isVarArgs() ) return false; // bail out if this is not a varargs method final Class[] types = paramTypes.getParameterTypes(); // if there's no args, we only match when there's just varargs if ( args.length == 0 ) return types.length <= 1; final int last = types.length - 1; if ( args.length < last ) return false; // can't match - paramTypes method is not usable! for ( int i = 0; i < last; i++ ) { // first check non-vararg argument types match if (!(ASSIGNABLE.match(types[i], args[i]) || PRIMITIVABLE.match(types[i], args[i]))) { return false; } } final Class varArgType = types[last].getComponentType(); // dig out as many trailing args as will fit, ensuring they match varargs type for ( int i = last; i < args.length; i++ ) { if (!(ASSIGNABLE.match(varArgType, args[i]) || PRIMITIVABLE.match(varArgType, args[i]))) { return false; } } return true; }
public static Object[] convertArguments(final ParameterTypes method, final IRubyObject[] args, final int addSpace) { final Class<?>[] paramTypes = method.getParameterTypes(); final Object[] javaArgs; final int len = args.length; if ( method.isVarArgs() ) { final int last = paramTypes.length - 1; javaArgs = new Object[ last + 1 + addSpace ]; for ( int i = 0; i < last; i++ ) { javaArgs[i] = args[i].toJava(paramTypes[i]); } javaArgs[ last ] = convertVarArgumentsOnly(paramTypes[ last ], last, args); } else { javaArgs = new Object[ len + addSpace ]; for ( int i = 0; i < len; i++ ) { javaArgs[i] = args[i].toJava(paramTypes[i]); } } return javaArgs; }
private static boolean assignableAndPrimitivableWithVarargs(ParameterTypes paramTypes, IRubyObject... args) { // bail out if this is not a varargs method if (!paramTypes.isVarArgs()) return false; Class[] types = paramTypes.getParameterTypes(); Class varArgArrayType = types[types.length - 1]; Class varArgType = varArgArrayType.getComponentType(); // if there's no args, we only match when there's just varargs if (args.length == 0) { return types.length <= 1; } // dig out as many trailing args as will fit, ensuring they match varargs type int nonVarargs = types.length - 1; for (int i = args.length - 1; i >= nonVarargs; i--) { if (!(ASSIGNABLE.match(varArgType, args[i]) || PRIMITIVABLE.match(varArgType, args[i]))) { return false; } } // check remaining args for (int i = 0; i < nonVarargs; i++) { if (!(ASSIGNABLE.match(types[i], args[i]) || PRIMITIVABLE.match(types[i], args[i]))) { return false; } } return true; }
private static boolean assignableAndPrimitivableWithVarargs(ParameterTypes paramTypes, IRubyObject... args) { // bail out if this is not a varargs method if (!paramTypes.isVarArgs()) return false; Class[] types = paramTypes.getParameterTypes(); Class varArgArrayType = types[types.length - 1]; Class varArgType = varArgArrayType.getComponentType(); // if there's no args, we only match when there's just varargs if (args.length == 0) { return types.length <= 1; } // dig out as many trailing args as will fit, ensuring they match varargs type int nonVarargs = types.length - 1; for (int i = args.length - 1; i >= nonVarargs; i--) { if (!(ASSIGNABLE.match(varArgType, args[i]) || PRIMITIVABLE.match(varArgType, args[i]))) { return false; } } // check remaining args for (int i = 0; i < nonVarargs; i++) { if (!(ASSIGNABLE.match(types[i], args[i]) || PRIMITIVABLE.match(types[i], args[i]))) { return false; } } return true; }