[Commonizer] Metadata comparator: Fully support contracts comparison

^KT-62753
This commit is contained in:
Dmitriy Dolovov
2024-01-25 14:48:51 +01:00
committed by Space Team
parent 4c8b5c699e
commit 5f3eee7267
@@ -54,6 +54,7 @@ class MetadataDeclarationsComparator private constructor(private val config: Con
} }
@Suppress("MemberVisibilityCanBePrivate", "unused") @Suppress("MemberVisibilityCanBePrivate", "unused")
@OptIn(ExperimentalContracts::class)
sealed interface PathElement { sealed interface PathElement {
val name: String val name: String
@@ -109,9 +110,20 @@ class MetadataDeclarationsComparator private constructor(private val config: Con
override val name get() = entryA.name override val name get() = entryA.name
} }
class Contract(val contractA: KmContract, val contractB: KmContract) : PathElement {
override val name get() = "contract"
}
class Effect(val effectA: KmEffect, val effectB: KmEffect, val index: Int) : PathElement {
override val name get() = index.toString()
}
class EffectExpression(val effectExpressionA: KmEffectExpression, val effectExpressionB: KmEffectExpression, val index: Int) : PathElement {
override val name get() = index.toString()
}
companion object { companion object {
internal fun <E : Any> guess(entityA: E, entityB: E, entityKind: EntityKind, entityKey: String?): PathElement { internal fun <E : Any> guess(entityA: E, entityB: E, entityKind: EntityKind, entityKey: String?): PathElement = when {
return when {
entityA is KmClass && entityB is KmClass -> Class(entityA, entityB) entityA is KmClass && entityB is KmClass -> Class(entityA, entityB)
entityA is KmTypeAlias && entityB is KmTypeAlias -> TypeAlias(entityA, entityB) entityA is KmTypeAlias && entityB is KmTypeAlias -> TypeAlias(entityA, entityB)
entityA is KmProperty && entityB is KmProperty -> Property(entityA, entityB) entityA is KmProperty && entityB is KmProperty -> Property(entityA, entityB)
@@ -135,12 +147,20 @@ class MetadataDeclarationsComparator private constructor(private val config: Con
val index = entityKey!!.toInt() val index = entityKey!!.toInt()
TypeArgument(entityA, entityB, index) TypeArgument(entityA, entityB, index)
} }
entityA is KmContract && entityB is KmContract -> Contract(entityA, entityB)
entityA is KmEffect && entityB is KmEffect -> {
val index = entityKey!!.toInt()
Effect(entityA, entityB, index)
}
entityA is KmEffectExpression && entityB is KmEffectExpression -> {
val index = entityKey!!.toInt()
EffectExpression(entityA, entityB, index)
}
entityA is KlibEnumEntry && entityB is KlibEnumEntry -> EnumEntry(entityA, entityB) entityA is KlibEnumEntry && entityB is KlibEnumEntry -> EnumEntry(entityA, entityB)
else -> error("Unknown combination of entities: ${entityA::class.java}, ${entityB::class.java}") else -> error("Unknown combination of entities: ${entityA::class.java}, ${entityB::class.java}")
} }
} }
} }
}
sealed interface EntityKind { sealed interface EntityKind {
enum class AnnotationKind : EntityKind { enum class AnnotationKind : EntityKind {