Codota Logo
Binder.cast
Code IndexAdd Codota to your IDE (free)

How to use
cast
method
in
com.headius.invokebinder.Binder

Best Java code snippets using com.headius.invokebinder.Binder.cast (Showing top 20 results out of 315)

  • Common ways to obtain Binder
private void myMethod () {
Binder b =
  • Codota IconMethodType start;Binder.from(start)
  • Codota IconClass returnType;Class[] argTypes;Object[] values;Binder.from(returnType, Throwable.class, argTypes).drop(int2, count).insert(int1, values)
  • Smart code suggestions by Codota
}
origin: com.headius/invokebinder

/**
 * Cast the incoming arguments to the types in the given signature. The
 * argument count must match, but the names in the target signature are
 * ignored.
 *
 * @param target the Signature to which arguments should be cast
 * @return a new SmartBinder with the cast applied
 */
public SmartBinder cast(Signature target) {
  return new SmartBinder(target, binder.cast(target.type()));
}
origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public static CallSite fixnum(Lookup lookup, String name, MethodType type, long value) {
  MutableCallSite site = new MutableCallSite(type);
  MethodHandle handle = Binder
      .from(IRubyObject.class, ThreadContext.class)
      .insert(0, site, value)
      .cast(IRubyObject.class, MutableCallSite.class, long.class, ThreadContext.class)
      .invokeStaticQuiet(MethodHandles.lookup(), Bootstrap.class, "fixnum");
  site.setTarget(handle);
  return site;
}
origin: com.ning.billing/killbill-osgi-bundles-jruby

public static CallSite flote(Lookup lookup, String name, MethodType type, double value) {
  MutableCallSite site = new MutableCallSite(type);
  MethodHandle handle = Binder
      .from(IRubyObject.class, ThreadContext.class)
      .insert(0, site, value)
      .cast(IRubyObject.class, MutableCallSite.class, double.class, ThreadContext.class)
      .invokeStaticQuiet(MethodHandles.lookup(), Bootstrap.class, "flote");
  site.setTarget(handle);
  return site;
}
origin: com.ning.billing/killbill-osgi-bundles-jruby

public static CallSite fixnum(Lookup lookup, String name, MethodType type, long value) {
  MutableCallSite site = new MutableCallSite(type);
  MethodHandle handle = Binder
      .from(IRubyObject.class, ThreadContext.class)
      .insert(0, site, value)
      .cast(IRubyObject.class, MutableCallSite.class, long.class, ThreadContext.class)
      .invokeStaticQuiet(MethodHandles.lookup(), Bootstrap.class, "fixnum");
  site.setTarget(handle);
  return site;
}
origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public static CallSite flote(Lookup lookup, String name, MethodType type, double value) {
  MutableCallSite site = new MutableCallSite(type);
  MethodHandle handle = Binder
      .from(IRubyObject.class, ThreadContext.class)
      .insert(0, site, value)
      .cast(IRubyObject.class, MutableCallSite.class, double.class, ThreadContext.class)
      .invokeStaticQuiet(MethodHandles.lookup(), Bootstrap.class, "flote");
  site.setTarget(handle);
  return site;
}
origin: com.headius/invokebinder

/**
 * Cast the named argument to the given type.
 *
 * @param name the name of the argument to cast
 * @param type the type to which that argument will be cast
 * @return a new SmartBinder with the cast applied
 */
public SmartBinder castArg(String name, Class<?> type) {
  Signature newSig = signature().replaceArg(name, name, type);
  return new SmartBinder(this, newSig, binder.cast(newSig.type()));
}
origin: com.headius/invokebinder

/**
 * Cast the incoming arguments to the return and argument types given. The
 * argument count must match.
 *
 * @param returnType the return type for the casted signature
 * @param argTypes   the types of the arguments for the casted signature
 * @return a new SmartBinder with the cast applied
 */
public SmartBinder cast(Class<?> returnType, Class<?>... argTypes) {
  return new SmartBinder(this, new Signature(returnType, argTypes, signature().argNames()), binder.cast(returnType, argTypes));
}
origin: org.jruby/jruby-complete

private static MethodHandle createAttrReaderHandle(InvokeSite site, IRubyObject self, RubyClass cls, VariableAccessor accessor) {
  MethodHandle nativeTarget;
  MethodHandle filter = cls.getClassRuntime().getNullToNilHandle();
  MethodHandle getValue;
  if (accessor instanceof FieldVariableAccessor) {
    MethodHandle getter = ((FieldVariableAccessor)accessor).getGetter();
    getValue = Binder.from(site.type())
        .drop(0, 2)
        .filterReturn(filter)
        .cast(methodType(Object.class, self.getClass()))
        .invoke(getter);
  } else {
    getValue = Binder.from(site.type())
        .drop(0, 2)
        .filterReturn(filter)
        .cast(methodType(Object.class, Object.class))
        .prepend(accessor)
        .invokeVirtualQuiet(LOOKUP, "get");
  }
  // NOTE: Must not cache the fully-bound handle in the method, since it's specific to this class
  return getValue;
}
origin: com.headius/invokebinder

/**
 * Cast the return value to the given type.
 *
 * Example: Our current signature is (String)String but the method this
 * handle will eventually call returns CharSequence.
 *
 * <code>binder = binder.castReturn(CharSequence.class);</code>
 *
 * Our handle will now successfully find and call the target method and
 * propagate the returned CharSequence as a String.
 *
 * @param type the new type for the return value
 * @return a new SmartBinder
 */
public SmartBinder castReturn(Class<?> type) {
  return new SmartBinder(this, signature().changeReturn(type), binder.cast(type, binder.type().parameterArray()));
}
origin: org.jruby/jruby-core

private static MethodHandle createAttrReaderHandle(InvokeSite site, IRubyObject self, RubyClass cls, VariableAccessor accessor) {
  MethodHandle nativeTarget;
  MethodHandle filter = cls.getClassRuntime().getNullToNilHandle();
  MethodHandle getValue;
  if (accessor instanceof FieldVariableAccessor) {
    MethodHandle getter = ((FieldVariableAccessor)accessor).getGetter();
    getValue = Binder.from(site.type())
        .drop(0, 2)
        .filterReturn(filter)
        .cast(methodType(Object.class, self.getClass()))
        .invoke(getter);
  } else {
    getValue = Binder.from(site.type())
        .drop(0, 2)
        .filterReturn(filter)
        .cast(methodType(Object.class, Object.class))
        .prepend(accessor)
        .invokeVirtualQuiet(LOOKUP, "get");
  }
  // NOTE: Must not cache the fully-bound handle in the method, since it's specific to this class
  return getValue;
}
origin: com.ning.billing/killbill-osgi-bundles-jruby

    .from(IRubyObject.class, IRubyObject.class)
    .insert(1, cls.getRuntime().getNil())
    .cast(IRubyObject.class, IRubyObject.class, IRubyObject.class)
    .invokeStaticQuiet(lookup(), InvocationLinker.class, "valueOrNil");
  Class objCls = InvokeDynamicSupport.REIFIED_OBJECT_CLASSES[offset];
  nativeTarget = b
      .cast(Object.class, objCls)
      .getFieldQuiet(lookup(), "var" + offset);
} else {
      .filterReturn(filter)
      .insert(1, accessor.getIndex())
      .cast(Object.class, RubyBasicObject.class, int.class)
      .invokeStaticQuiet(lookup(), VariableAccessor.class, "getVariable");
origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

    .from(IRubyObject.class, IRubyObject.class)
    .insert(1, cls.getRuntime().getNil())
    .cast(IRubyObject.class, IRubyObject.class, IRubyObject.class)
    .invokeStaticQuiet(lookup(), InvocationLinker.class, "valueOrNil");
  Class objCls = InvokeDynamicSupport.REIFIED_OBJECT_CLASSES[offset];
  nativeTarget = b
      .cast(Object.class, objCls)
      .getFieldQuiet(lookup(), "var" + offset);
} else {
      .filterReturn(filter)
      .insert(1, accessor.getIndex())
      .cast(Object.class, RubyBasicObject.class, int.class)
      .invokeStaticQuiet(lookup(), VariableAccessor.class, "getVariable");
origin: org.jruby/jruby-complete

private static MethodHandle createAttrWriterHandle(InvokeSite site, IRubyObject self, RubyClass cls, VariableAccessor accessor) {
  MethodHandle nativeTarget;
  MethodHandle filter = Binder
      .from(IRubyObject.class, Object.class)
      .drop(0)
      .constant(cls.getRuntime().getNil());
  MethodHandle setValue;
  if (accessor instanceof FieldVariableAccessor) {
    MethodHandle setter = ((FieldVariableAccessor)accessor).getSetter();
    setValue = Binder.from(site.type())
        .drop(0, 2)
        .filterReturn(filter)
        .cast(methodType(void.class, self.getClass(), Object.class))
        .invoke(setter);
  } else {
    setValue = Binder.from(site.type())
        .drop(0, 2)
        .filterReturn(filter)
        .cast(methodType(void.class, Object.class, Object.class))
        .prepend(accessor)
        .invokeVirtualQuiet(LOOKUP, "set");
  }
  return setValue;
}
origin: org.jruby/jruby-core

private static MethodHandle createAttrWriterHandle(InvokeSite site, IRubyObject self, RubyClass cls, VariableAccessor accessor) {
  MethodHandle nativeTarget;
  MethodHandle filter = Binder
      .from(IRubyObject.class, Object.class)
      .drop(0)
      .constant(cls.getRuntime().getNil());
  MethodHandle setValue;
  if (accessor instanceof FieldVariableAccessor) {
    MethodHandle setter = ((FieldVariableAccessor)accessor).getSetter();
    setValue = Binder.from(site.type())
        .drop(0, 2)
        .filterReturn(filter)
        .cast(methodType(void.class, self.getClass(), Object.class))
        .invoke(setter);
  } else {
    setValue = Binder.from(site.type())
        .drop(0, 2)
        .filterReturn(filter)
        .cast(methodType(void.class, Object.class, Object.class))
        .prepend(accessor)
        .invokeVirtualQuiet(LOOKUP, "set");
  }
  return setValue;
}
origin: org.jruby/jruby-complete

.cast(Object.class, IRubyObject.class)
.invokeStaticQuiet(lookup(), JavaUtil.class, "objectFromJavaProxy");
.filter(0, receiverConverter)
.filterReturn(filter)
.cast(fieldHandle.type())
.invoke(fieldHandle);
.cast(Object.class, IRubyObject.class)
.invokeStaticQuiet(lookup(), JavaUtil.class, "objectFromJavaProxy");
.filter(0, receiverConverter)
.filterReturn(constant(IRubyObject.class, self.getRuntime().getNil()))
.cast(fieldHandle.type())
.invoke(fieldHandle);
origin: com.ning.billing/killbill-osgi-bundles-jruby

  Class objCls = InvokeDynamicSupport.REIFIED_OBJECT_CLASSES[offset];
  nativeTarget = b
      .cast(void.class, objCls, Object.class)
      .invokeStaticQuiet(lookup(), objCls, "setVariableChecked");
} else {
      .filterReturn(filter)
      .insert(1, cls.getRealClass(), accessor.getIndex())
      .cast(void.class, RubyBasicObject.class, RubyClass.class, int.class, Object.class)
      .invokeStaticQuiet(lookup(), accessor.getClass(), "setVariableChecked");
origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

  Class objCls = InvokeDynamicSupport.REIFIED_OBJECT_CLASSES[offset];
  nativeTarget = b
      .cast(void.class, objCls, Object.class)
      .invokeStaticQuiet(lookup(), objCls, "setVariableChecked");
} else {
      .filterReturn(filter)
      .insert(1, cls.getRealClass(), accessor.getIndex())
      .cast(void.class, RubyBasicObject.class, RubyClass.class, int.class, Object.class)
      .invokeStaticQuiet(lookup(), accessor.getClass(), "setVariableChecked");
origin: com.headius/invokebinder

/**
 * Apply all transforms to an endpoint that does absolutely nothing. Useful for
 * creating exception handlers in void methods that simply ignore the exception.
 *
 * @return a handle that has all transforms applied and does nothing at its endpoint
 */
public MethodHandle nop() {
  if (type().returnType() != void.class) {
    throw new InvalidTransformException("must have void return type to nop: " + type());
  }
  return invoke(Binder
      .from(type())
      .drop(0, type().parameterCount())
      .cast(Object.class)
      .constant(null));
}
origin: org.jruby/jruby-complete

MethodHandle buildNewInstanceHandle(DynamicMethod method, IRubyObject self) {
  MethodHandle mh = null;
  if (method == self.getRuntime().getBaseNewMethod()) {
    RubyClass recvClass = (RubyClass) self;
    // Bind a second site as a dynamic invoker to guard against changes in new object's type
    CallSite initSite = SelfInvokeSite.bootstrap(LOOKUP, "callFunctional:initialize", type(), literalClosure ? 1 : 0, file, line);
    MethodHandle initHandle = initSite.dynamicInvoker();
    MethodHandle allocFilter = Binder.from(IRubyObject.class, IRubyObject.class)
        .cast(IRubyObject.class, RubyClass.class)
        .insert(0, new Class[] {ObjectAllocator.class, Ruby.class}, recvClass.getAllocator(), self.getRuntime())
        .invokeVirtualQuiet(LOOKUP, "allocate");
    mh = SmartBinder.from(LOOKUP, signature)
        .filter("self", allocFilter)
        .fold("dummy", initHandle)
        .permute("self")
        .identity()
        .handle();
    if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) {
      LOG.info(name() + "\tbound as new instance creation " + Bootstrap.logMethod(method));
    }
  }
  return mh;
}
origin: org.jruby/jruby-core

MethodHandle buildNewInstanceHandle(DynamicMethod method, IRubyObject self) {
  MethodHandle mh = null;
  if (method == self.getRuntime().getBaseNewMethod()) {
    RubyClass recvClass = (RubyClass) self;
    // Bind a second site as a dynamic invoker to guard against changes in new object's type
    CallSite initSite = SelfInvokeSite.bootstrap(LOOKUP, "callFunctional:initialize", type(), literalClosure ? 1 : 0, file, line);
    MethodHandle initHandle = initSite.dynamicInvoker();
    MethodHandle allocFilter = Binder.from(IRubyObject.class, IRubyObject.class)
        .cast(IRubyObject.class, RubyClass.class)
        .insert(0, new Class[] {ObjectAllocator.class, Ruby.class}, recvClass.getAllocator(), self.getRuntime())
        .invokeVirtualQuiet(LOOKUP, "allocate");
    mh = SmartBinder.from(LOOKUP, signature)
        .filter("self", allocFilter)
        .fold("dummy", initHandle)
        .permute("self")
        .identity()
        .handle();
    if (Options.INVOKEDYNAMIC_LOG_BINDING.load()) {
      LOG.info(name() + "\tbound as new instance creation " + Bootstrap.logMethod(method));
    }
  }
  return mh;
}
com.headius.invokebinderBindercast

Javadoc

Cast the incoming arguments to the given MethodType. The casts applied are equivalent to those in MethodHandle.explicitCastArguments(MethodType).

Popular methods of Binder

  • from
    Construct a new Binder, starting from a given MethodType.
  • insert
    Insert at the given index the given argument value(s).
  • invoke
    Apply the chain of transforms and bind them to a static method specified using the end signature plu
  • collect
    Box all incoming arguments from the given position onward into the given array type.
  • constant
    Apply the tranforms, binding them to a constant value that will propagate back through the chain. Th
  • drop
    Drop from the given index a number of arguments.
  • filter
    Filter incoming arguments, from the given index, replacing each with the result of calling the assoc
  • fold
    Process the incoming arguments using the given handle, inserting the result as the first argument.
  • invokeVirtual
    Apply the chain of transforms and bind them to a virtual method specified using the end signature pl
  • permute
    Permute the incoming arguments to a new sequence specified by the given values. Arguments may be dup
  • filterReturn
    Filter return value, using a function that produces the current return type from another type. The n
  • invokeStaticQuiet
    Apply the chain of transforms and bind them to a static method specified using the end signature plu
  • filterReturn,
  • invokeStaticQuiet,
  • invokeVirtualQuiet,
  • tryFinally,
  • nop,
  • type,
  • append,
  • foldVoid,
  • identity

Popular in Java

  • Finding current android device location
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • compareTo (BigDecimal)
    Compares this BigDecimal with the specified BigDecimal. Two BigDecimal objects that are equal in val
  • setScale (BigDecimal)
    Returns a BigDecimal whose scale is the specified value, and whose value is numerically equal to thi
  • KeyStore (java.security)
    This class represents an in-memory collection of keys and certificates. It manages two types of entr
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • ConcurrentHashMap (java.util.concurrent)
    A hash table supporting full concurrency of retrievals and adjustable expected concurrency for updat
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • JOptionPane (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now