From 4f9346e4e332246ea101f3ec74a467856d099daf Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Fri, 12 Mar 2021 18:39:23 +0300 Subject: [PATCH] Update Kotlin hacks --- .../org/teavm/classlib/impl/KotlinHacks.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/classlib/src/main/java/org/teavm/classlib/impl/KotlinHacks.java b/classlib/src/main/java/org/teavm/classlib/impl/KotlinHacks.java index 06e887d98..2cc37fdfa 100644 --- a/classlib/src/main/java/org/teavm/classlib/impl/KotlinHacks.java +++ b/classlib/src/main/java/org/teavm/classlib/impl/KotlinHacks.java @@ -17,15 +17,22 @@ package org.teavm.classlib.impl; import java.util.ArrayList; import java.util.List; +import org.teavm.model.AccessLevel; +import org.teavm.model.BasicBlock; import org.teavm.model.ClassHolder; import org.teavm.model.ClassHolderTransformer; import org.teavm.model.ClassHolderTransformerContext; +import org.teavm.model.ElementModifier; import org.teavm.model.MethodHolder; +import org.teavm.model.Program; +import org.teavm.model.instructions.ExitInstruction; +import org.teavm.model.instructions.StringConstantInstruction; public class KotlinHacks implements ClassHolderTransformer { @Override public void transformClass(ClassHolder cls, ClassHolderTransformerContext context) { - if (cls.getName().equals("kotlin.jvm.internal.Lambda")) { + if (cls.getName().equals("kotlin.jvm.internal.Lambda") + || cls.getName().equals("kotlin.coroutines.jvm.internal.BaseContinuationImpl")) { List methodsToRemove = new ArrayList<>(); for (MethodHolder method : cls.getMethods()) { if (method.getName().equals("toString")) { @@ -35,6 +42,26 @@ public class KotlinHacks implements ClassHolderTransformer { for (MethodHolder method : methodsToRemove) { cls.removeMethod(method); } + } else if (cls.getName().equals("kotlin.jvm.internal.Reflection")) { + for (MethodHolder method : cls.getMethods()) { + if (method.getLevel() == AccessLevel.PUBLIC && method.hasModifier(ElementModifier.STATIC) + && method.getName().equals("renderLambdaToString") + && method.getResultType().isObject(String.class)) { + Program program = new Program(); + BasicBlock block = program.createBasicBlock(); + + StringConstantInstruction stringConstant = new StringConstantInstruction(); + stringConstant.setReceiver(program.createVariable()); + stringConstant.setConstant("lambda"); + block.add(stringConstant); + + ExitInstruction exit = new ExitInstruction(); + exit.setValueToReturn(stringConstant.getReceiver()); + block.add(exit); + + method.setProgram(program); + } + } } } }