Examples of MethodHandle


Examples of java.lang.invoke.MethodHandle

    return handle.bindTo(receiver).invokeWithArguments(arguments);
  }

  public static Object perform(Object receiver, String selector)
      throws Throwable {
    MethodHandle handle = getHandle(receiver, selector);
    return handle.invoke(receiver);
  }
View Full Code Here

Examples of java.lang.invoke.MethodHandle

    return handle.invoke(receiver);
  }

  public static Object perform(Object receiver, String selector, Object arg1)
      throws Throwable {
    MethodHandle handle = getHandle(receiver, selector);
    return handle.invoke(receiver, arg1);
  }
View Full Code Here

Examples of java.lang.invoke.MethodHandle

      }
     
      AlmostFinalCallSite(AlmostFinalValue volatileFinalValue) {
        super(MethodType.methodType(Object.class));
        Object lock = new Object();
        MethodHandle fallback = FALLBACK.bindTo(this);
        synchronized(lock) {
          value = NONE;
          switchPoint = new SwitchPoint();
          setTarget(fallback);
        }
View Full Code Here

Examples of java.lang.invoke.MethodHandle

        synchronized(lock) {
          Object value = this.value;
          if (value == NONE) {
            value = volatileFinalValue.initialValue();
          }
          MethodHandle target = switchPoint.guardWithTest(MethodHandles.constant(Object.class, value), fallback);
          setTarget(target);
          return value;
        }
      }
View Full Code Here

Examples of java.lang.invoke.MethodHandle

    try {

      Method method = identityClass.getDeclaredMethod("initialize");
      Object instance = aSystemMapping
          .singletonAtReference_(_aClassMapping.reference().nonmeta());
      final MethodHandle unreflect = MethodHandles.lookup().unreflect(
          method);
      System.out.println("Initializing " + identityClass);
      unreflect.invoke(instance);
      return this;
    } catch (NoSuchMethodException e) {
      return this;
    } catch (SecurityException | IllegalAccessException
        | IllegalArgumentException | InvocationTargetException e) {
View Full Code Here

Examples of java.lang.invoke.MethodHandle

    Object[] astConstants = jvmClass.astConstants();
    if (astConstants.length == 0)
      return this;
    MethodType type = MethodType.genericMethodType(astConstants.length)
        .changeReturnType(void.class);
    MethodHandle findStatic;
    try {
      findStatic = MethodHandles.lookup().findStatic(current.javaClass,
          "_astinit", type);
      findStatic.invokeWithArguments(astConstants);
    } catch (Throwable e) {
      throw new RuntimeException(e);
    }
    return this;
  }
View Full Code Here

Examples of java.lang.invoke.MethodHandle

      if (value != null && String.class.isAssignableFrom(valueOfClass)) {
        return (VT) value.toString();
      }
      final Class<?> clazz = PRIMS.containsKey(valueOfClass) ? PRIMS
          .get(valueOfClass) : valueOfClass;
      MethodHandle mh1 = null;
      try {
        mh1 = MethodHandles.lookup().findStatic(clazz, "valueOf",
            MethodType.methodType(clazz, String.class));
      } catch (final Throwable t) {
        // class doesn't support it- do nothing
      }
      if (mh1 != null) {
        try {
          return (VT) mh1.invoke(value);
        } catch (final Throwable t) {
          throw new IllegalArgumentException(String.format(
              "Unable to invoke valueOf on %1$s using %2$s",
              value, valueOfClass), t);
        }
View Full Code Here

Examples of java.lang.invoke.MethodHandle

     * @throws NoSuchMethodException
     *             thrown when an accessor cannot be found for the field
     */
    protected static MethodHandle buildAccessorWithLikelyPrefixes(
        final Object target, final String fieldName) {
      final MethodHandle mh = buildAccessor(target, fieldName, "get",
          "is", "has", "use");
      if (mh == null) {
        // throw new NoSuchMethodException(fieldName + " on " + target);
        throw new IllegalArgumentException(fieldName + " on " + target);
      }
View Full Code Here

Examples of java.lang.invoke.MethodHandle

     * @return the setter {@link MethodHandle}
     */
    protected static MethodHandle buildSetter(final MethodHandle accessor,
        final Object target, final String fieldName) {
      try {
        final MethodHandle mh1 = MethodHandles
            .lookup()
            .findVirtual(
                target.getClass(),
                buildMethodName("set", fieldName),
                MethodType.methodType(void.class, accessor
View Full Code Here

Examples of java.lang.invoke.MethodHandle

      if (value != null && String.class.isAssignableFrom(valueOfClass)) {
        return (VT) value.toString();
      }
      final Class<?> clazz = PRIMS.containsKey(valueOfClass) ? PRIMS
          .get(valueOfClass) : valueOfClass;
      MethodHandle mh1 = null;
      try {
        mh1 = MethodHandles.lookup().findStatic(clazz, "valueOf",
            MethodType.methodType(clazz, String.class));
      } catch (final Throwable t) {
        // class doesn't support it- do nothing
      }
      if (mh1 != null) {
        try {
          return (VT) mh1.invoke(value);
        } catch (final Throwable t) {
          throw new IllegalArgumentException(String.format(
              "Unable to invoke valueOf on %1$s using %2$s",
              value, valueOfClass), t);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.