@Override public Binder prepareBinder() { // collect dregexp args into an array String[] argNames = new String[type().parameterCount()]; Class[] argTypes = new Class[argNames.length]; argNames[0] = "context"; argTypes[0] = ThreadContext.class; for (int i = 1; i < argNames.length; i++) { argNames[i] = "part" + i; argTypes[i] = RubyString.class; } // "once" deregexp must be handled on the call side return SmartBinder .from(RubyRegexp.class, argNames, argTypes) .collect("parts", "part.*") .binder(); }
@Override public Binder prepareBinder() { // collect dregexp args into an array String[] argNames = new String[type().parameterCount()]; Class[] argTypes = new Class[argNames.length]; argNames[0] = "context"; argTypes[0] = ThreadContext.class; for (int i = 1; i < argNames.length; i++) { argNames[i] = "part" + i; argTypes[i] = RubyString.class; } // "once" deregexp must be handled on the call side return SmartBinder .from(RubyRegexp.class, argNames, argTypes) .collect("parts", "part.*") .binder(); }
/** * Filter the arguments matching the given pattern using the given filter function. * * @param pattern the regular expression pattern to match arguments * @param filter the MethodHandle to use to filter the arguments * @return a new SmartBinder with the filter applied */ public SmartBinder filter(String pattern, MethodHandle filter) { String[] argNames = signature().argNames(); Pattern pat = Pattern.compile(pattern); Binder newBinder = binder(); Signature newSig = signature(); for (int i = 0; i < argNames.length; i++) { if (pat.matcher(argNames[i]).matches()) { newBinder = newBinder.filter(i, filter); newSig = newSig.argType(i, filter.type().returnType()); } } return new SmartBinder(newSig, newBinder); }
/** * Prepare a binder for this call site's target, forcing varargs if specified * * @param varargs whether to only call an arg-boxed variable arity path * @return the prepared binder */ public Binder prepareBinder(boolean varargs) { SmartBinder binder = SmartBinder.from(signature); if (varargs || arity > 3) { // we know we want to call varargs path always, so prepare args[] here if (arity == -1) { // do nothing, already have IRubyObject[] in args } else if (arity == 0) { binder = binder.insert(argOffset, "args", IRubyObject.NULL_ARRAY); } else { binder = binder .collect("args", "arg[0-9]+"); } } // add block if needed if (signature.lastArgType() != Block.class) { binder = binder.append("block", Block.NULL_BLOCK); } // bind to site binder = binder.insert(0, "site", this); return binder.binder(); }
/** * Prepare a binder for this call site's target, forcing varargs if specified * * @param varargs whether to only call an arg-boxed variable arity path * @return the prepared binder */ public Binder prepareBinder(boolean varargs) { SmartBinder binder = SmartBinder.from(signature); if (varargs || arity > 3) { // we know we want to call varargs path always, so prepare args[] here if (arity == -1) { // do nothing, already have IRubyObject[] in args } else if (arity == 0) { binder = binder.insert(argOffset, "args", IRubyObject.NULL_ARRAY); } else { binder = binder .collect("args", "arg[0-9]+"); } } // add block if needed if (signature.lastArgType() != Block.class) { binder = binder.append("block", Block.NULL_BLOCK); } // bind to site binder = binder.insert(0, "site", this); return binder.binder(); }