Java Code Examples for java.lang.invoke.MethodHandles#identity()
The following examples show how to use
java.lang.invoke.MethodHandles#identity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TryFinallyTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@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()} }; }
Example 2
Source File: IdentityCast.java From presto with Apache License 2.0 | 5 votes |
@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); }
Example 3
Source File: LiteralFunction.java From presto with Apache License 2.0 | 5 votes |
@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); }
Example 4
Source File: Selector.java From groovy with Apache License 2.0 | 5 votes |
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); } }
Example 5
Source File: Selector.java From groovy with Apache License 2.0 | 5 votes |
private void handleInstanceCase() { if (handle != null) return; if (staticTargetType.isAssignableFrom(args[0].getClass())) { handle = MethodHandles.identity(staticSourceType); } }
Example 6
Source File: MethodHandleFactory.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Override public MethodHandle identity(final Class<?> type) { final MethodHandle mh = MethodHandles.identity(type); return debug(mh, "identity", type); }
Example 7
Source File: MethodHandleFactory.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Override public MethodHandle identity(final Class<?> type) { final MethodHandle mh = MethodHandles.identity(type); return debug(mh, "identity", type); }
Example 8
Source File: MethodHandleFactory.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@Override public MethodHandle identity(final Class<?> type) { final MethodHandle mh = MethodHandles.identity(type); return debug(mh, "identity", type); }
Example 9
Source File: MethodHandleFactory.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Override public MethodHandle identity(final Class<?> type) { final MethodHandle mh = MethodHandles.identity(type); return debug(mh, "identity", type); }
Example 10
Source File: MethodHandleFactory.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override public MethodHandle identity(final Class<?> type) { final MethodHandle mh = MethodHandles.identity(type); return debug(mh, "identity", type); }
Example 11
Source File: MethodHandleFactory.java From hottub with GNU General Public License v2.0 | 4 votes |
@Override public MethodHandle identity(final Class<?> type) { final MethodHandle mh = MethodHandles.identity(type); return debug(mh, "identity", type); }
Example 12
Source File: ValueConversions.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
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)); }
Example 13
Source File: ValueConversions.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
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)); }
Example 14
Source File: MethodHandleFactory.java From jdk8u_nashorn with GNU General Public License v2.0 | 4 votes |
@Override public MethodHandle identity(final Class<?> type) { final MethodHandle mh = MethodHandles.identity(type); return debug(mh, "identity", type); }
Example 15
Source File: Validation.java From dynamic-object with Creative Commons Zero v1.0 Universal | 4 votes |
private static MethodHandle castChecker(Class<?> castTo) { MethodHandle handle = MethodHandles.identity(castTo); return handle.asType(methodType(Void.TYPE, Object.class)); }
Example 16
Source File: NativeCalls.java From es6draft with MIT License | 4 votes |
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)); }