private static MethodType extractChecked(Serializable serializable) throws IllegalArgumentException, TypeNotPresentException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException{ Method method = serializable.getClass().getDeclaredMethod("writeReplace"); method.setAccessible(true); MethodType type = MethodType.fromMethodDescriptorString( ((SerializedLambda) method.invoke(serializable)).getImplMethodSignature(), serializable.getClass().getClassLoader()); return type; } }
public static MethodType toMethodType(Type type, ClassLoader classLoader) { return MethodType.fromMethodDescriptorString(type.getInternalName(), classLoader); }
public static MethodType toMethodType(Type type, ClassLoader classLoader) { return MethodType.fromMethodDescriptorString(type.getInternalName(), classLoader); }
public static void main(String[] args) { String mt = extractConsumer((Lambda t) -> t.toString()).get().getInstantiatedMethodType(); System.out.println(mt); System.out.println(MethodType.fromMethodDescriptorString(mt, Thread.currentThread().getContextClassLoader()).parameterType(0)); }
default String getArgumentDescription() { MethodType methodType = MethodType.fromMethodDescriptorString(asSerializedLambda().getInstantiatedMethodType(), getClass().getClassLoader()); return methodType.parameterType(0).getSimpleName(); }
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; }
public static CallSite bootstrap(MethodHandles.Lookup lookup, String invokedName, MethodType invokedType, String value) throws Throwable { ClassLoader classLoader = lookup.lookupClass().getClassLoader(); MethodType type = MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", classLoader); Class<?> symbolClass = Class.forName("scala.Symbol", false, classLoader); MethodHandle factoryMethod = lookup.findStatic(symbolClass, "apply", type); Object symbolValue = factoryMethod.invokeWithArguments(value); return new ConstantCallSite(MethodHandles.constant(symbolClass, symbolValue)); } }
public static CallSite bootstrap(MethodHandles.Lookup lookup, String invokedName, MethodType invokedType, String value) throws Throwable { ClassLoader classLoader = lookup.lookupClass().getClassLoader(); MethodType type = MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", classLoader); Class<?> symbolClass = Class.forName("scala.Symbol", false, classLoader); MethodHandle factoryMethod = lookup.findStatic(symbolClass, "apply", type); Object symbolValue = factoryMethod.invokeWithArguments(value); return new ConstantCallSite(MethodHandles.constant(symbolClass, symbolValue)); } }
impl, serialized.getImplMethodName(), MethodType.fromMethodDescriptorString( serialized.getImplMethodSignature(), impl.getClassLoader() ) ); case MethodHandleInfo.REF_invokeVirtual: return lookup.findVirtual( impl, serialized.getImplMethodName(), MethodType.fromMethodDescriptorString( serialized.getImplMethodSignature(), impl.getClassLoader() ) ); default:
public static MethodHandle toMethodHandle(Handle handle, ClassLoader classLoader, MethodHandles.Lookup lookup) throws Exception { MethodType type = MethodType.fromMethodDescriptorString(handle.getDesc(), classLoader); Class<?> owner = classLoader.loadClass(handle.getOwner().replace('/', '.')); switch (handle.getTag()) { case H_INVOKESTATIC: return lookup.findStatic(owner, handle.getName(), type); case H_INVOKEVIRTUAL: case H_INVOKEINTERFACE: return lookup.findVirtual(owner, handle.getName(), type); case H_INVOKESPECIAL: return lookup.findSpecial(owner, handle.getName(), type, owner); case H_NEWINVOKESPECIAL: return lookup.findConstructor(owner, type); default: throw new AssertionError("Unexpected handle type: " + handle); } }
public static MethodHandle toMethodHandle(Handle handle, ClassLoader classLoader, MethodHandles.Lookup lookup) throws Exception { MethodType type = MethodType.fromMethodDescriptorString(handle.getDesc(), classLoader); Class<?> owner = classLoader.loadClass(handle.getOwner().replace('/', '.')); switch (handle.getTag()) { case H_INVOKESTATIC: return lookup.findStatic(owner, handle.getName(), type); case H_INVOKEVIRTUAL: case H_INVOKEINTERFACE: return lookup.findVirtual(owner, handle.getName(), type); case H_INVOKESPECIAL: return lookup.findSpecial(owner, handle.getName(), type, owner); case H_NEWINVOKESPECIAL: return lookup.findConstructor(owner, type); default: throw new AssertionError("Unexpected handle type: " + handle); } }
String eltName = cp.getCPHandleName(index); String eltDesc = cp.getCPHandleType(index); MethodType type = MethodType.fromMethodDescriptorString(eltDesc, cl); Class<?> cls = Class.forName(className.replace('/', '.'), false, cl); Method m = cls.getDeclaredMethod(eltName, type.parameterList().toArray(new Class[type.parameterCount()])); return lk.unreflect(m); case ClassConstants.CONSTANT_MethodType: return MethodType.fromMethodDescriptorString(cp.getCPMethodType(index), cl); default: assert false : "invalid type " + t;
String eltName = cp.getCPHandleName(index); String eltDesc = cp.getCPHandleType(index); MethodType type = MethodType.fromMethodDescriptorString(eltDesc, cl); Class<?> cls = Class.forName(className.replace('/', '.'), false, cl); Method m = cls.getDeclaredMethod(eltName, type.parameterList().toArray(new Class[type.parameterCount()])); return lk.unreflect(m); case ClassConstants.CONSTANT_MethodType: return MethodType.fromMethodDescriptorString(cp.getCPMethodType(index), cl); default: assert false : "invalid type " + t;