/** * Generate an array of argument offsets based on permuting this signature * to the given signature. Repeats are permitted, and the patterns will be * matched against actual argument names using regex matching. * * @param otherArgPatterns the argument name patterns to permute * @return an array of argument offsets that will permute to the matching * argument names */ public int[] to(String... otherArgPatterns) { return to(permute(otherArgPatterns)); }
/** * Produce a method handle permuting the arguments in this signature using * the given permute arguments and targeting the given java.lang.invoke.MethodHandle. * * Example: * * <pre> * Signature sig = Signature.returning(String.class).appendArg("a", int.class).appendArg("b", int.class); * MethodHandle handle = handleThatTakesOneInt(); * MethodHandle newHandle = sig.permuteTo(handle, "b"); * </pre> * * @param target the method handle to target * @param permuteArgs the arguments to permute * @return a new handle that permutes appropriate positions based on the * given permute args */ public MethodHandle permuteWith(MethodHandle target, String... permuteArgs) { return MethodHandles.permuteArguments(target, methodType, to(permute(permuteArgs))); }
/** * Using the argument names and order in the target Signature, permute the * arguments in this SmartBinder. Arguments may be duplicated or omitted * in the target Signature, but all arguments in the target must be defined * in this SmartBinder . * * @param target the Signature from which to derive a new argument list * @return a new SmartBinder with the permute applied */ public SmartBinder permute(Signature target) { return new SmartBinder(this, target, binder.permute(signature().to(target))); }
@Override public MethodHandle generate(JRubyCallSite site, RubyClass cls, DynamicMethod method, String realName) { MethodHandle handle = ((HandleMethod)method).getHandle(site.arity()); if (handle == null) { throw new IndirectBindingException("MH dynamic method does not have needed arity"); } if (RubyInstanceConfig.LOG_INDY_BINDINGS) LOG.info(site.name() + "\tbound from MHDynMethod " + logMethod(method) + ":" + handle); Signature fullSig = site.fullSignature(); MethodHandle nativeTarget = Binder .from(fullSig.type()) .permute(fullSig.to("context", "self", "arg*", "block")) .invoke(handle); nativeTarget = addOrRemoveBlock(site, nativeTarget); return nativeTarget; } }
@Override public MethodHandle generate(JRubyCallSite site, RubyClass cls, DynamicMethod method, String realName) { MethodHandle handle = ((HandleMethod)method).getHandle(site.arity()); if (handle == null) { throw new IndirectBindingException("MH dynamic method does not have needed arity"); } if (RubyInstanceConfig.LOG_INDY_BINDINGS) LOG.info(site.name() + "\tbound from MHDynMethod " + logMethod(method) + ":" + handle); Signature fullSig = site.fullSignature(); MethodHandle nativeTarget = Binder .from(fullSig.type()) .permute(fullSig.to("context", "self", "arg*", "block")) .invoke(handle); nativeTarget = addOrRemoveBlock(site, nativeTarget); return nativeTarget; } }
nativeTarget = Binder .from(fullSig.type()) .permute(fullSig.to("context", "self", "arg*", "block")) .insert(0, scriptObject) .invokeStaticQuiet(site.lookup(), nativeCall.getNativeTarget(), nativeCall.getNativeName());
nativeTarget = Binder .from(fullSig.type()) .permute(fullSig.to("context", "self", "arg*", "block")) .insert(0, scriptObject) .invokeStaticQuiet(site.lookup(), nativeCall.getNativeTarget(), nativeCall.getNativeName());
nativeTarget = permuteArguments(nativeTarget, fullSig.type(), fullSig.to(target));
nativeTarget = permuteArguments(nativeTarget, fullSig.type(), fullSig.to(target));