From 6a196c2f324ac499bd6c0542ea00e6c5a19499d3 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 18 Nov 2019 13:19:22 +0300 Subject: [PATCH] Remove toString implementation from Kotlin lambda base class since it uses unsupported reflection API --- .../org/teavm/classlib/impl/JCLPlugin.java | 1 + .../org/teavm/classlib/impl/KotlinHacks.java | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 classlib/src/main/java/org/teavm/classlib/impl/KotlinHacks.java diff --git a/classlib/src/main/java/org/teavm/classlib/impl/JCLPlugin.java b/classlib/src/main/java/org/teavm/classlib/impl/JCLPlugin.java index 3a751b6f6..6960b9cd0 100644 --- a/classlib/src/main/java/org/teavm/classlib/impl/JCLPlugin.java +++ b/classlib/src/main/java/org/teavm/classlib/impl/JCLPlugin.java @@ -109,6 +109,7 @@ public class JCLPlugin implements TeaVMPlugin { if (!isBootstrap()) { host.add(new ScalaHacks()); + host.add(new KotlinHacks()); } host.add(new NumericClassTransformer()); diff --git a/classlib/src/main/java/org/teavm/classlib/impl/KotlinHacks.java b/classlib/src/main/java/org/teavm/classlib/impl/KotlinHacks.java new file mode 100644 index 000000000..06e887d98 --- /dev/null +++ b/classlib/src/main/java/org/teavm/classlib/impl/KotlinHacks.java @@ -0,0 +1,40 @@ +/* + * Copyright 2019 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.impl; + +import java.util.ArrayList; +import java.util.List; +import org.teavm.model.ClassHolder; +import org.teavm.model.ClassHolderTransformer; +import org.teavm.model.ClassHolderTransformerContext; +import org.teavm.model.MethodHolder; + +public class KotlinHacks implements ClassHolderTransformer { + @Override + public void transformClass(ClassHolder cls, ClassHolderTransformerContext context) { + if (cls.getName().equals("kotlin.jvm.internal.Lambda")) { + List methodsToRemove = new ArrayList<>(); + for (MethodHolder method : cls.getMethods()) { + if (method.getName().equals("toString")) { + methodsToRemove.add(method); + } + } + for (MethodHolder method : methodsToRemove) { + cls.removeMethod(method); + } + } + } +}