commonMain.co.touchlab.skie.phases.features.defaultarguments.delegate.ClassMethodsDefaultArgumentGeneratorDelegate.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-compiler-linker-plugin-kgp_1.9.20 Show documentation
Show all versions of kotlin-compiler-linker-plugin-kgp_1.9.20 Show documentation
Kotlin compiler plugin that improves Swift interface of a Kotlin Multiplatform framework.
The newest version!
package co.touchlab.skie.phases.features.defaultarguments.delegate
import co.touchlab.skie.kir.descriptor.DescriptorProvider
import co.touchlab.skie.phases.FrontendIrPhase
import co.touchlab.skie.util.SharedCounter
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
class ClassMethodsDefaultArgumentGeneratorDelegate(
context: FrontendIrPhase.Context,
sharedCounter: SharedCounter,
) : BaseFunctionDefaultArgumentGeneratorDelegate(context, sharedCounter) {
override fun DescriptorProvider.allSupportedFunctions(): List =
this.allSupportedClasses().flatMap { classDescriptor ->
classDescriptor.allSupportedMethods()
}
private fun DescriptorProvider.allSupportedClasses(): List =
this.exposedClasses.filter { it.isSupported }
private val ClassDescriptor.isSupported: Boolean
get() = when (this.kind) {
ClassKind.CLASS, ClassKind.ENUM_CLASS, ClassKind.OBJECT -> true
ClassKind.INTERFACE, ClassKind.ENUM_ENTRY, ClassKind.ANNOTATION_CLASS -> false
}
private fun ClassDescriptor.allSupportedMethods(): List =
descriptorProvider.getExposedClassMembers(this)
.filterIsInstance()
.filter { it.isSupported }
private val SimpleFunctionDescriptor.isSupported: Boolean
get() = this.contextReceiverParameters.isEmpty()
}