use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class RicochetTest method assertEqualFunction.
private static void assertEqualFunction(MethodHandle x, MethodHandle y) throws Throwable {
//??
assertEquals(x.type(), y.type());
MethodType t = x.type();
if (t.parameterCount() == 0) {
assertEqualFunctionAt(null, x, y);
return;
}
Class<?> ptype = t.parameterType(0);
if (ptype == long.class || ptype == Long.class) {
for (long i = -10; i <= 10; i++) {
assertEqualFunctionAt(i, x, y);
}
} else {
for (int i = -10; i <= 10; i++) {
assertEqualFunctionAt(i, x, y);
}
}
}
use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class PermuteArgsTest method adjustArity.
static MethodHandle adjustArity(MethodHandle mh, int arity) {
MethodType mt = mh.type();
int posArgs = mt.parameterCount() - 1;
Class<?> reptype = mt.parameterType(posArgs).getComponentType();
MethodType mt1 = mt.dropParameterTypes(posArgs, posArgs + 1);
while (mt1.parameterCount() < arity) {
Class<?> pt = reptype;
if (pt == Object.class && posArgs > 0)
// repeat types cyclically if possible:
pt = mt1.parameterType(mt1.parameterCount() - posArgs);
mt1 = mt1.appendParameterTypes(pt);
}
try {
return mh.asType(mt1);
} catch (WrongMethodTypeException | IllegalArgumentException ex) {
throw new IllegalArgumentException("cannot convert to type " + mt1 + " from " + mh, ex);
}
}
use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class ValueConversionsTest method testConvert.
static void testConvert(Wrapper src, Wrapper dst, long tval) throws Throwable {
// must have prims
if (dst == Wrapper.OBJECT || src == Wrapper.OBJECT)
return;
// must have values
if (dst == Wrapper.VOID || src == Wrapper.VOID)
return;
boolean testSingleCase = (tval != 0);
final long tvalInit = tval;
MethodHandle conv = ValueConversions.convertPrimitive(src, dst);
MethodType convType = MethodType.methodType(dst.primitiveType(), src.primitiveType());
assertEquals(convType, conv.type());
MethodHandle converter = conv.asType(conv.type().changeReturnType(Object.class));
for (; ; ) {
long n = tval;
Object testValue = src.wrap(n);
Object expResult = dst.cast(testValue, dst.primitiveType());
Object result;
switch(src) {
case INT:
result = converter.invokeExact((int) n);
break;
case LONG:
result = converter.invokeExact(/*long*/
n);
break;
case FLOAT:
result = converter.invokeExact((float) n);
break;
case DOUBLE:
result = converter.invokeExact((double) n);
break;
case CHAR:
result = converter.invokeExact((char) n);
break;
case BYTE:
result = converter.invokeExact((byte) n);
break;
case SHORT:
result = converter.invokeExact((short) n);
break;
case BOOLEAN:
result = converter.invokeExact((n & 1) != 0);
break;
default:
throw new AssertionError();
}
assertEquals("(src,dst,n,testValue)=" + Arrays.asList(src, dst, "0x" + Long.toHexString(n), testValue), expResult, result);
if (testSingleCase)
break;
// next test value:
tval = nextTestValue(tval);
// repeat
if (tval == tvalInit)
break;
}
}
use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class MethodTypeTest method testParameterType.
/**
* Test of parameterType method, of class MethodType.
*/
@Test
public void testParameterType() {
System.out.println("parameterType");
for (int num = 0; num < ptypes.length; num++) {
MethodType instance = mt_viS;
Class<?> expResult = ptypes[num];
Class<?> result = instance.parameterType(num);
assertSame(expResult, result);
}
}
use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class MethodTypeTest method testMake_Class_List.
/**
* Test of make method, of class MethodType.
*/
@Test
public void testMake_Class_List() {
System.out.println("make (from type list)");
MethodType result = MethodType.methodType(rtype, Arrays.asList(ptypes));
assertSame(mt_viS, result);
}
Aggregations