Java Code Examples for java.lang.invoke.MethodType#fromMethodDescriptorString()
The following examples show how to use
java.lang.invoke.MethodType#fromMethodDescriptorString() .
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: MethodTypeTest.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Test of make method, of class MethodType. */ @Test public void testMake_String_ClassLoader() { System.out.println("make (from bytecode signature)"); ClassLoader loader = null; MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi}; String obj = "Ljava/lang/Object;"; assertEquals(obj, concat(Object.class)); String[] expResults = { "(ILjava/lang/String;)V", concat("(", obj, 2, ")", Object.class), "()V", "()"+obj, concat("(", String.class, Integer.class, ")I"), concat("(", String.class, "I)", Integer.class), concat("(", String.class, Integer.class, ")", Integer.class), concat("(", String.class, "I)I") }; for (int i = 0; i < instances.length; i++) { MethodType instance = instances[i]; String result = instance.toMethodDescriptorString(); assertEquals("#"+i, expResults[i], result); MethodType parsed = MethodType.fromMethodDescriptorString(result, loader); assertSame("--#"+i, instance, parsed); } }
Example 2
Source File: LambdaDesugaring.java From bazel with Apache License 2.0 | 6 votes |
/** * Produces a {@link MethodHandle} using either the context or {@link #targetLoader} class * loader, depending on {@code target}. */ private MethodHandle toMethodHandle(Lookup lookup, Handle asmHandle, boolean target) throws ReflectiveOperationException { Class<?> owner = loadFromInternal(asmHandle.getOwner()); MethodType signature = MethodType.fromMethodDescriptorString( asmHandle.getDesc(), target ? targetLoader : Thread.currentThread().getContextClassLoader()); switch (asmHandle.getTag()) { case Opcodes.H_INVOKESTATIC: return lookup.findStatic(owner, asmHandle.getName(), signature); case Opcodes.H_INVOKEVIRTUAL: case Opcodes.H_INVOKEINTERFACE: return lookup.findVirtual(owner, asmHandle.getName(), signature); case Opcodes.H_INVOKESPECIAL: // we end up calling these using invokevirtual return lookup.findSpecial(owner, asmHandle.getName(), signature, owner); case Opcodes.H_NEWINVOKESPECIAL: return lookup.findConstructor(owner, signature); default: throw new UnsupportedOperationException("Cannot resolve " + asmHandle); } }
Example 3
Source File: LambdaDesugaring.java From bazel with Apache License 2.0 | 6 votes |
/** * Produces a {@link MethodHandle} or {@link MethodType} using {@link #targetLoader} for the * given ASM {@link Handle} or {@link Type}. {@code lookup} is only used for resolving {@link * Handle}s. */ private Object toJvmMetatype(Lookup lookup, Object asm) throws ReflectiveOperationException { if (asm instanceof Number) { return asm; } if (asm instanceof Type) { Type type = (Type) asm; switch (type.getSort()) { case Type.OBJECT: return loadFromInternal(type.getInternalName()); case Type.METHOD: return MethodType.fromMethodDescriptorString(type.getDescriptor(), targetLoader); default: throw new IllegalArgumentException("Cannot convert: " + asm); } } if (asm instanceof Handle) { return toMethodHandle(lookup, (Handle) asm, /*target*/ true); } throw new IllegalArgumentException("Cannot convert: " + asm); }
Example 4
Source File: MethodTypeTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
/** * Test of make method, of class MethodType. */ @Test public void testMake_String_ClassLoader() { System.out.println("make (from bytecode signature)"); ClassLoader loader = null; MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi}; String obj = "Ljava/lang/Object;"; assertEquals(obj, concat(Object.class)); String[] expResults = { "(ILjava/lang/String;)V", concat("(", obj, 2, ")", Object.class), "()V", "()"+obj, concat("(", String.class, Integer.class, ")I"), concat("(", String.class, "I)", Integer.class), concat("(", String.class, Integer.class, ")", Integer.class), concat("(", String.class, "I)I") }; for (int i = 0; i < instances.length; i++) { MethodType instance = instances[i]; String result = instance.toMethodDescriptorString(); assertEquals("#"+i, expResults[i], result); MethodType parsed = MethodType.fromMethodDescriptorString(result, loader); assertSame("--#"+i, instance, parsed); } }
Example 5
Source File: MethodTypeTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Test of make method, of class MethodType. */ @Test public void testMake_String_ClassLoader() { System.out.println("make (from bytecode signature)"); ClassLoader loader = null; MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi}; String obj = "Ljava/lang/Object;"; assertEquals(obj, concat(Object.class)); String[] expResults = { "(ILjava/lang/String;)V", concat("(", obj, 2, ")", Object.class), "()V", "()"+obj, concat("(", String.class, Integer.class, ")I"), concat("(", String.class, "I)", Integer.class), concat("(", String.class, Integer.class, ")", Integer.class), concat("(", String.class, "I)I") }; for (int i = 0; i < instances.length; i++) { MethodType instance = instances[i]; String result = instance.toMethodDescriptorString(); assertEquals("#"+i, expResults[i], result); MethodType parsed = MethodType.fromMethodDescriptorString(result, loader); assertSame("--#"+i, instance, parsed); } }
Example 6
Source File: MethodTypeTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * Test of make method, of class MethodType. */ @Test public void testMake_String_ClassLoader() { System.out.println("make (from bytecode signature)"); ClassLoader loader = null; MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi}; String obj = "Ljava/lang/Object;"; assertEquals(obj, concat(Object.class)); String[] expResults = { "(ILjava/lang/String;)V", concat("(", obj, 2, ")", Object.class), "()V", "()"+obj, concat("(", String.class, Integer.class, ")I"), concat("(", String.class, "I)", Integer.class), concat("(", String.class, Integer.class, ")", Integer.class), concat("(", String.class, "I)I") }; for (int i = 0; i < instances.length; i++) { MethodType instance = instances[i]; String result = instance.toMethodDescriptorString(); assertEquals("#"+i, expResults[i], result); MethodType parsed = MethodType.fromMethodDescriptorString(result, loader); assertSame("--#"+i, instance, parsed); } }
Example 7
Source File: MethodTypeTest.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * Test of make method, of class MethodType. */ @Test public void testMake_String_ClassLoader() { System.out.println("make (from bytecode signature)"); ClassLoader loader = null; MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi}; String obj = "Ljava/lang/Object;"; assertEquals(obj, concat(Object.class)); String[] expResults = { "(ILjava/lang/String;)V", concat("(", obj, 2, ")", Object.class), "()V", "()"+obj, concat("(", String.class, Integer.class, ")I"), concat("(", String.class, "I)", Integer.class), concat("(", String.class, Integer.class, ")", Integer.class), concat("(", String.class, "I)I") }; for (int i = 0; i < instances.length; i++) { MethodType instance = instances[i]; String result = instance.toMethodDescriptorString(); assertEquals("#"+i, expResults[i], result); MethodType parsed = MethodType.fromMethodDescriptorString(result, loader); assertSame("--#"+i, instance, parsed); } }
Example 8
Source File: MethodTypeTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Test of make method, of class MethodType. */ @Test public void testMake_String_ClassLoader() { System.out.println("make (from bytecode signature)"); ClassLoader loader = null; MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi}; String obj = "Ljava/lang/Object;"; assertEquals(obj, concat(Object.class)); String[] expResults = { "(ILjava/lang/String;)V", concat("(", obj, 2, ")", Object.class), "()V", "()"+obj, concat("(", String.class, Integer.class, ")I"), concat("(", String.class, "I)", Integer.class), concat("(", String.class, Integer.class, ")", Integer.class), concat("(", String.class, "I)I") }; for (int i = 0; i < instances.length; i++) { MethodType instance = instances[i]; String result = instance.toMethodDescriptorString(); assertEquals("#"+i, expResults[i], result); MethodType parsed = MethodType.fromMethodDescriptorString(result, loader); assertSame("--#"+i, instance, parsed); } }
Example 9
Source File: MethodTypeTest.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Test of make method, of class MethodType. */ @Test public void testMake_String_ClassLoader() { System.out.println("make (from bytecode signature)"); ClassLoader loader = null; MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi}; String obj = "Ljava/lang/Object;"; assertEquals(obj, concat(Object.class)); String[] expResults = { "(ILjava/lang/String;)V", concat("(", obj, 2, ")", Object.class), "()V", "()"+obj, concat("(", String.class, Integer.class, ")I"), concat("(", String.class, "I)", Integer.class), concat("(", String.class, Integer.class, ")", Integer.class), concat("(", String.class, "I)I") }; for (int i = 0; i < instances.length; i++) { MethodType instance = instances[i]; String result = instance.toMethodDescriptorString(); assertEquals("#"+i, expResults[i], result); MethodType parsed = MethodType.fromMethodDescriptorString(result, loader); assertSame("--#"+i, instance, parsed); } }
Example 10
Source File: MethodTypeTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Test of make method, of class MethodType. */ @Test public void testMake_String_ClassLoader() { System.out.println("make (from bytecode signature)"); ClassLoader loader = null; MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi}; String obj = "Ljava/lang/Object;"; assertEquals(obj, concat(Object.class)); String[] expResults = { "(ILjava/lang/String;)V", concat("(", obj, 2, ")", Object.class), "()V", "()"+obj, concat("(", String.class, Integer.class, ")I"), concat("(", String.class, "I)", Integer.class), concat("(", String.class, Integer.class, ")", Integer.class), concat("(", String.class, "I)I") }; for (int i = 0; i < instances.length; i++) { MethodType instance = instances[i]; String result = instance.toMethodDescriptorString(); assertEquals("#"+i, expResults[i], result); MethodType parsed = MethodType.fromMethodDescriptorString(result, loader); assertSame("--#"+i, instance, parsed); } }
Example 11
Source File: MethodTypeTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Test of make method, of class MethodType. */ @Test public void testMake_String_ClassLoader() { System.out.println("make (from bytecode signature)"); ClassLoader loader = null; MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi}; String obj = "Ljava/lang/Object;"; assertEquals(obj, concat(Object.class)); String[] expResults = { "(ILjava/lang/String;)V", concat("(", obj, 2, ")", Object.class), "()V", "()"+obj, concat("(", String.class, Integer.class, ")I"), concat("(", String.class, "I)", Integer.class), concat("(", String.class, Integer.class, ")", Integer.class), concat("(", String.class, "I)I") }; for (int i = 0; i < instances.length; i++) { MethodType instance = instances[i]; String result = instance.toMethodDescriptorString(); assertEquals("#"+i, expResults[i], result); MethodType parsed = MethodType.fromMethodDescriptorString(result, loader); assertSame("--#"+i, instance, parsed); } }
Example 12
Source File: MethodTypeTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Test of make method, of class MethodType. */ @Test public void testMake_String_ClassLoader() { System.out.println("make (from bytecode signature)"); ClassLoader loader = null; MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi}; String obj = "Ljava/lang/Object;"; assertEquals(obj, concat(Object.class)); String[] expResults = { "(ILjava/lang/String;)V", concat("(", obj, 2, ")", Object.class), "()V", "()"+obj, concat("(", String.class, Integer.class, ")I"), concat("(", String.class, "I)", Integer.class), concat("(", String.class, Integer.class, ")", Integer.class), concat("(", String.class, "I)I") }; for (int i = 0; i < instances.length; i++) { MethodType instance = instances[i]; String result = instance.toMethodDescriptorString(); assertEquals("#"+i, expResults[i], result); MethodType parsed = MethodType.fromMethodDescriptorString(result, loader); assertSame("--#"+i, instance, parsed); } }
Example 13
Source File: MethodTypeTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Test of make method, of class MethodType. */ @Test public void testMake_String_ClassLoader() { System.out.println("make (from bytecode signature)"); ClassLoader loader = null; MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi}; String obj = "Ljava/lang/Object;"; assertEquals(obj, concat(Object.class)); String[] expResults = { "(ILjava/lang/String;)V", concat("(", obj, 2, ")", Object.class), "()V", "()"+obj, concat("(", String.class, Integer.class, ")I"), concat("(", String.class, "I)", Integer.class), concat("(", String.class, Integer.class, ")", Integer.class), concat("(", String.class, "I)I") }; for (int i = 0; i < instances.length; i++) { MethodType instance = instances[i]; String result = instance.toMethodDescriptorString(); assertEquals("#"+i, expResults[i], result); MethodType parsed = MethodType.fromMethodDescriptorString(result, loader); assertSame("--#"+i, instance, parsed); } }
Example 14
Source File: MethodTypeTest.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Test of make method, of class MethodType. */ @Test public void testMake_String_ClassLoader() { System.out.println("make (from bytecode signature)"); ClassLoader loader = null; MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi}; String obj = "Ljava/lang/Object;"; assertEquals(obj, concat(Object.class)); String[] expResults = { "(ILjava/lang/String;)V", concat("(", obj, 2, ")", Object.class), "()V", "()"+obj, concat("(", String.class, Integer.class, ")I"), concat("(", String.class, "I)", Integer.class), concat("(", String.class, Integer.class, ")", Integer.class), concat("(", String.class, "I)I") }; for (int i = 0; i < instances.length; i++) { MethodType instance = instances[i]; String result = instance.toMethodDescriptorString(); assertEquals("#"+i, expResults[i], result); MethodType parsed = MethodType.fromMethodDescriptorString(result, loader); assertSame("--#"+i, instance, parsed); } }
Example 15
Source File: MethodTypeTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Test of make method, of class MethodType. */ @Test public void testMake_String_ClassLoader() { System.out.println("make (from bytecode signature)"); ClassLoader loader = null; MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi}; String obj = "Ljava/lang/Object;"; assertEquals(obj, concat(Object.class)); String[] expResults = { "(ILjava/lang/String;)V", concat("(", obj, 2, ")", Object.class), "()V", "()"+obj, concat("(", String.class, Integer.class, ")I"), concat("(", String.class, "I)", Integer.class), concat("(", String.class, Integer.class, ")", Integer.class), concat("(", String.class, "I)I") }; for (int i = 0; i < instances.length; i++) { MethodType instance = instances[i]; String result = instance.toMethodDescriptorString(); assertEquals("#"+i, expResults[i], result); MethodType parsed = MethodType.fromMethodDescriptorString(result, loader); assertSame("--#"+i, instance, parsed); } }
Example 16
Source File: DescribableFunction.java From java-8-matchers with MIT License | 5 votes |
default String getResultDescription() { SerializedLambda lambda = asSerializedLambda(); MethodType lambdaMethodType = MethodType.fromMethodDescriptorString(lambda.getImplMethodSignature(), getClass().getClassLoader()); String resultType = lambdaMethodType.returnType().getSimpleName(); if (! lambda.getImplMethodName().startsWith("lambda$")) { return lambda.getImplMethodName() + " (" + withPrefixedArticle(resultType) + ")"; } return resultType; }
Example 17
Source File: SingleArgumentDescribableFunctionalInterface.java From java-8-matchers with MIT License | 4 votes |
default String getArgumentDescription() { MethodType methodType = MethodType.fromMethodDescriptorString(asSerializedLambda().getInstantiatedMethodType(), getClass().getClassLoader()); return methodType.parameterType(0).getSimpleName(); }