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

commonMain.co.touchlab.skie.phases.features.flow.FlowMappingStrategy.kt Maven / Gradle / Ivy

Go to download

Kotlin compiler plugin that improves Swift interface of a Kotlin Multiplatform framework.

The newest version!
package co.touchlab.skie.phases.features.flow

import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.typeUtil.supertypes

enum class FlowMappingStrategy {
    Full, TypeArgumentsOnly, None;

    private val incompatibleTypeFqNames = listOf(
        "kotlinx.coroutines.flow.Flow",
        "kotlin.collections.List",
        "kotlin.collections.Map",
    )

    fun limitedToTypeArguments(): FlowMappingStrategy =
        when (this) {
            Full, TypeArgumentsOnly -> TypeArgumentsOnly
            None -> None
        }

    fun forTypeArgumentsOf(kotlinType: KotlinType): FlowMappingStrategy =
        if (kotlinType.isIncompatibleWithSkieFlows) limitedToTypeArguments() else forTypeArgumentsOfCompatibleType()

    private val KotlinType.isIncompatibleWithSkieFlows: Boolean
        get() = (listOf(this) + supertypes()).any {
            (it.constructor.declarationDescriptor as? ClassDescriptor)?.fqNameSafe?.asString() in incompatibleTypeFqNames
        }

    private fun forTypeArgumentsOfCompatibleType(): FlowMappingStrategy =
        when (this) {
            Full, TypeArgumentsOnly -> Full
            None -> None
        }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy