/*
 *  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<MethodHolder> methodsToRemove = new ArrayList<>();
            for (MethodHolder method : cls.getMethods()) {
                if (method.getName().equals("toString")) {
                    methodsToRemove.add(method);
                }
            }
            for (MethodHolder method : methodsToRemove) {
                cls.removeMethod(method);
            }
        }
    }
}

@@ -684,24 +684,95 @@
 .util.List;%0A
+import org.teavm.model.AccessLevel;%0Aimport org.teavm.model.BasicBlock;%0A
 import org.t
@@ -919,28 +919,216 @@
 m.model.
-MethodHolder
+ElementModifier;%0Aimport org.teavm.model.MethodHolder;%0Aimport org.teavm.model.Program;%0Aimport org.teavm.model.instructions.ExitInstruction;%0Aimport org.teavm.model.instructions.StringConstantInstruction
 ;%0A%0Apubli
@@ -1348,16 +1348,111 @@
 Lambda%22)
+%0A                %7C%7C cls.getName().equals(%22kotlin.coroutines.jvm.internal.BaseContinuationImpl%22)
 ) %7B%0A    
@@ -1820,32 +1820,1079 @@
 ;%0A            %7D%0A
+        %7D else if (cls.getName().equals(%22kotlin.jvm.internal.Reflection%22)) %7B%0A            for (MethodHolder method : cls.getMethods()) %7B%0A                if (method.getLevel() == AccessLevel.PUBLIC && method.hasModifier(ElementModifier.STATIC)%0A                        && method.getName().equals(%22renderLambdaToString%22)%0A                        && method.getResultType().isObject(String.class)) %7B%0A                    Program program = new Program();%0A                    BasicBlock block = program.createBasicBlock();%0A%0A                    StringConstantInstruction stringConstant = new StringConstantInstruction();%0A                    stringConstant.setReceiver(program.createVariable());%0A                    stringConstant.setConstant(%22lambda%22);%0A                    block.add(stringConstant);%0A%0A                    ExitInstruction exit = new ExitInstruction();%0A                    exit.setValueToReturn(stringConstant.getReceiver());%0A                    block.add(exit);%0A%0A                    method.setProgram(program);%0A                %7D%0A            %7D%0A
         %7D%0A    %7D%0A

Update Kotlin hacks