All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kotlin.reflect.jvm.internal.calls.InternalUnderlyingValOfInlineClass.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0-Beta1
Show newest version
/*
 * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
 * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
 */

package kotlin.reflect.jvm.internal.calls

import java.lang.reflect.Type
import kotlin.reflect.jvm.internal.calls.CallerImpl.Companion.dropFirst
import java.lang.reflect.Method as ReflectMethod

internal sealed class InternalUnderlyingValOfInlineClass(
    private val unboxMethod: ReflectMethod,
    final override val parameterTypes: List
) : Caller {

    final override val member: ReflectMethod? get() = null

    final override val returnType: Type =
        unboxMethod.returnType

    protected fun callMethod(instance: Any?, args: Array<*>): Any? {
        return unboxMethod.invoke(instance, *args)
    }

    class Unbound(
        unboxMethod: ReflectMethod
    ) : InternalUnderlyingValOfInlineClass(unboxMethod, listOf(unboxMethod.declaringClass)) {
        override fun call(args: Array<*>): Any? {
            checkArguments(args)
            return callMethod(args[0], args.dropFirst())
        }
    }

    class Bound(
        unboxMethod: ReflectMethod,
        private val boundReceiver: Any?
    ) : InternalUnderlyingValOfInlineClass(unboxMethod, emptyList()), BoundCaller {
        override fun call(args: Array<*>): Any? {
            checkArguments(args)
            return callMethod(boundReceiver, args)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy