java.lang.invoke.MethodHandles#identity ( )源码实例Demo

下面列出了java.lang.invoke.MethodHandles#identity ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-jdk9   文件: TryFinallyTest.java
@DataProvider
static Object[][] negativeTestData() {
    MethodHandle intid = MethodHandles.identity(int.class);
    MethodHandle intco = MethodHandles.constant(int.class, 0);
    MethodHandle errTarget = MethodHandles.dropArguments(intco, 0, int.class, double.class, String.class, int.class);
    MethodHandle errCleanup = MethodHandles.dropArguments(MethodHandles.constant(int.class, 0), 0, Throwable.class,
            int.class, double.class, Object.class);
    MethodHandle voidTarget = TryFinally.MH_voidTarget;
    MethodHandle voidICleanup = MethodHandles.dropArguments(TryFinally.MH_voidCleanup, 1, int.class);
    return new Object[][]{
            {intid, MethodHandles.identity(double.class),
                    "target and return types must match: double != int"},
            {intid, MethodHandles.dropArguments(intid, 0, String.class),
                    "cleanup first argument and Throwable must match: (String,int)int != class java.lang.Throwable"},
            {intid, MethodHandles.dropArguments(intid, 0, Throwable.class, double.class),
                    "cleanup second argument and target return type must match: (Throwable,double,int)int != int"},
            {errTarget, errCleanup,
                    "cleanup parameters after (Throwable,result) and target parameter list prefix must match: " +
                            errCleanup.type() + " != " + errTarget.type()},
            {voidTarget, voidICleanup,
                    "cleanup parameters after (Throwable,result) and target parameter list prefix must match: " +
                            voidICleanup.type() + " != " + voidTarget.type()}
    };
}
 
源代码2 项目: presto   文件: IdentityCast.java
@Override
public ScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, Metadata metadata)
{
    Type type = boundVariables.getTypeVariable("T");
    MethodHandle identity = MethodHandles.identity(type.getJavaType());
    return new ScalarFunctionImplementation(
            false,
            ImmutableList.of(valueTypeArgumentProperty(RETURN_NULL_ON_NULL)),
            identity);
}
 
源代码3 项目: presto   文件: LiteralFunction.java
@Override
public ScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, Metadata metadata)
{
    Type parameterType = boundVariables.getTypeVariable("F");
    Type type = boundVariables.getTypeVariable("T");

    MethodHandle methodHandle = null;
    if (parameterType.getJavaType() == type.getJavaType()) {
        methodHandle = MethodHandles.identity(parameterType.getJavaType());
    }

    if (parameterType.getJavaType() == Slice.class) {
        if (type.getJavaType() == Block.class) {
            methodHandle = READ_BLOCK.bindTo(metadata.getBlockEncodingSerde());
        }
        else if (type.getJavaType() != Slice.class) {
            methodHandle = READ_BLOCK_VALUE.bindTo(metadata.getBlockEncodingSerde()).bindTo(type);
        }
    }

    checkArgument(methodHandle != null,
            "Expected type %s to use (or can be converted into) Java type %s, but Java type is %s",
            type,
            parameterType.getJavaType(),
            type.getJavaType());

    return new ScalarFunctionImplementation(
            false,
            ImmutableList.of(valueTypeArgumentProperty(RETURN_NULL_ON_NULL)),
            methodHandle);
}
 
源代码4 项目: groovy   文件: Selector.java
private void handleNullWithoutBoolean() {
    if (handle != null || args[0] != null) return;

    if (staticTargetType.isPrimitive()) {
        handle = MethodHandles.insertArguments(GROOVY_CAST_EXCEPTION, 1, staticTargetType);
        // need to call here here because we used the static target type
        // it won't be done otherwise because handle.type() == callSite.type()
        castAndSetGuards();
    } else {
        handle = MethodHandles.identity(staticSourceType);
    }
}
 
源代码5 项目: groovy   文件: Selector.java
private void handleInstanceCase() {
    if (handle != null) return;

    if (staticTargetType.isAssignableFrom(args[0].getClass())) {
        handle = MethodHandles.identity(staticSourceType);
    }
}
 
源代码6 项目: TencentKona-8   文件: MethodHandleFactory.java
@Override
public MethodHandle identity(final Class<?> type) {
    final MethodHandle mh = MethodHandles.identity(type);
    return debug(mh, "identity", type);
}
 
源代码7 项目: jdk8u60   文件: MethodHandleFactory.java
@Override
public MethodHandle identity(final Class<?> type) {
    final MethodHandle mh = MethodHandles.identity(type);
    return debug(mh, "identity", type);
}
 
源代码8 项目: openjdk-jdk8u   文件: MethodHandleFactory.java
@Override
public MethodHandle identity(final Class<?> type) {
    final MethodHandle mh = MethodHandles.identity(type);
    return debug(mh, "identity", type);
}
 
@Override
public MethodHandle identity(final Class<?> type) {
    final MethodHandle mh = MethodHandles.identity(type);
    return debug(mh, "identity", type);
}
 
源代码10 项目: openjdk-jdk9   文件: MethodHandleFactory.java
@Override
public MethodHandle identity(final Class<?> type) {
    final MethodHandle mh = MethodHandles.identity(type);
    return debug(mh, "identity", type);
}
 
源代码11 项目: hottub   文件: MethodHandleFactory.java
@Override
public MethodHandle identity(final Class<?> type) {
    final MethodHandle mh = MethodHandles.identity(type);
    return debug(mh, "identity", type);
}
 
源代码12 项目: openjdk-8-source   文件: ValueConversions.java
public static MethodHandle identity(Class<?> type) {
    if (!type.isPrimitive())
        // Reference identity has been moved into MethodHandles:
        return MethodHandles.identity(type);
    return identity(Wrapper.findPrimitiveType(type));
}
 
源代码13 项目: openjdk-8   文件: ValueConversions.java
public static MethodHandle identity(Class<?> type) {
    if (!type.isPrimitive())
        // Reference identity has been moved into MethodHandles:
        return MethodHandles.identity(type);
    return identity(Wrapper.findPrimitiveType(type));
}
 
源代码14 项目: jdk8u_nashorn   文件: MethodHandleFactory.java
@Override
public MethodHandle identity(final Class<?> type) {
    final MethodHandle mh = MethodHandles.identity(type);
    return debug(mh, "identity", type);
}
 
源代码15 项目: dynamic-object   文件: Validation.java
private static MethodHandle castChecker(Class<?> castTo) {
    MethodHandle handle = MethodHandles.identity(castTo);
    return handle.asType(methodType(Void.TYPE, Object.class));
}
 
源代码16 项目: es6draft   文件: NativeCalls.java
private static MethodHandle toObjectArray(List<Class<?>> types) {
    MethodHandle mh = MethodHandles.identity(Object[].class);
    mh = mh.asCollector(Object[].class, types.size());
    return mh.asType(MethodType.methodType(Object[].class, types));
}