commonMain.co.touchlab.skie.phases.other.ValidateSkieVisibilityAnnotationsPhase.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.
package co.touchlab.skie.phases.other
import co.touchlab.skie.configuration.annotations.SkieVisibility
import co.touchlab.skie.kir.descriptor.allExposedMembers
import co.touchlab.skie.phases.ClassExportPhase
import co.touchlab.skie.phases.descriptorProvider
import co.touchlab.skie.phases.descriptorReporter
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
object ValidateSkieVisibilityAnnotationsPhase : ClassExportPhase {
context(ClassExportPhase.Context)
override suspend fun execute() {
descriptorProvider.allExposedMembers.forEach {
validate(it)
}
descriptorProvider.exposedClasses.forEach {
validate(it)
}
}
context(ClassExportPhase.Context)
private fun validate(declarationDescriptor: DeclarationDescriptor) {
val visibilityAnnotations = declarationDescriptor.annotations.filter {
it.fqName?.asString()?.startsWith(SkieVisibility::class.qualifiedName!!) == true
}
if (visibilityAnnotations.size > 1) {
descriptorReporter.warning(
"Multiple ${SkieVisibility::class.simpleName} annotations used simultaneously. This is not allowed and may result in undefined behavior. " +
"This warning might become an error in the future.",
declarationDescriptor,
)
}
}
}