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 <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 StringBuilder inspectParameterTypes( final StringBuilder str, final ParameterTypes target, final boolean brackets) { if ( brackets ) str.append('('); final Class<?>[] types = target.getParameterTypes(); for ( int i = 0; i < types.length; i++ ) { str.append( types[i].getName() ); if ( i < types.length - 1 ) str.append(','); } if ( brackets ) str.append(')'); return str; }
if ( callable == null ) continue; // removed (matched) Class[] types = callable.getParameterTypes(); if ( callable == null ) continue; // removed (matched) Class[] types = callable.getParameterTypes(); if ( callable == null ) continue; // removed (matched) Class[] types = callable.getParameterTypes(); if ( callable.isVarArgs() ) { if ( callable.getArity() > args.length - 1 ) continue; if ( callable.getArity() != args.length ) continue;
private static StringBuilder inspectParameterTypes( final StringBuilder str, final ParameterTypes target, final boolean brackets) { if ( brackets ) str.append('('); final Class<?>[] types = target.getParameterTypes(); for ( int i = 0; i < types.length; i++ ) { str.append( types[i].getName() ); if ( i < types.length - 1 ) str.append(','); } if ( brackets ) str.append(')'); return str; }
if ( callable == null ) continue; // removed (matched) Class[] types = callable.getParameterTypes(); if ( callable == null ) continue; // removed (matched) Class[] types = callable.getParameterTypes(); if ( callable == null ) continue; // removed (matched) Class[] types = callable.getParameterTypes(); if ( callable.isVarArgs() ) { if ( callable.getArity() > args.length - 1 ) continue; if ( callable.getArity() != args.length ) continue;
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 boolean exactMatch(ParameterTypes paramTypes, IRubyObject... args) { final Class[] types = paramTypes.getParameterTypes(); if (args.length != types.length) return false; for (int i = 0; i < types.length; i++) { if (!EXACT.match(types[i], args[i])) { return false; } } return true; }
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 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 boolean exactMatch(ParameterTypes paramTypes, IRubyObject... args) { Class[] types = paramTypes.getParameterTypes(); if (args.length != types.length) return false; for (int i = 0; i < types.length; i++) { if (!EXACT.match(types[i], args[i])) { return false; } } return true; }
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 boolean exactMatch(ParameterTypes paramTypes, IRubyObject... args) { final Class[] types = paramTypes.getParameterTypes(); if (args.length != types.length) return false; for (int i = 0; i < types.length; i++) { if (!EXACT.match(types[i], args[i])) { return false; } } return true; }
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 boolean exactMatch(ParameterTypes paramTypes, IRubyObject... args) { Class[] types = paramTypes.getParameterTypes(); if (args.length != types.length) return false; for (int i = 0; i < types.length; i++) { if (!EXACT.match(types[i], args[i])) { return false; } } return true; }
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 List<ParameterTypes> findCallable(ParameterTypes[] callables, IRubyObject... args) { List<ParameterTypes> retainedCallables = new ArrayList<ParameterTypes>(callables.length); List<ParameterTypes> incomingCallables = new ArrayList<ParameterTypes>(Arrays.asList(callables)); for (int currentArg = 0; currentArg < args.length; currentArg++) { retainedCallables.clear(); for (Matcher matcher : MATCH_SEQUENCE) { for (Iterator<ParameterTypes> callableIter = incomingCallables.iterator(); callableIter.hasNext();) { ParameterTypes callable = callableIter.next(); Class[] types = callable.getParameterTypes(); if (matcher.match(types[currentArg], args[currentArg])) { callableIter.remove(); retainedCallables.add(callable); } } } incomingCallables.clear(); incomingCallables.addAll(retainedCallables); } return retainedCallables; }
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 List<ParameterTypes> findCallable(ParameterTypes[] callables, IRubyObject... args) { List<ParameterTypes> retainedCallables = new ArrayList<ParameterTypes>(callables.length); List<ParameterTypes> incomingCallables = new ArrayList<ParameterTypes>(Arrays.asList(callables)); for (int currentArg = 0; currentArg < args.length; currentArg++) { retainedCallables.clear(); for (Matcher matcher : MATCH_SEQUENCE) { for (Iterator<ParameterTypes> callableIter = incomingCallables.iterator(); callableIter.hasNext();) { ParameterTypes callable = callableIter.next(); Class[] types = callable.getParameterTypes(); if (matcher.match(types[currentArg], args[currentArg])) { callableIter.remove(); retainedCallables.add(callable); } } } incomingCallables.clear(); incomingCallables.addAll(retainedCallables); } return retainedCallables; }
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; }