[Commonizer] Rework mocks for tests to drop descriptors

This commit is contained in:
Dmitriy Dolovov
2021-03-04 01:15:28 +03:00
parent e96dd3b301
commit 607568fb73
8 changed files with 458 additions and 523 deletions
@@ -5,10 +5,12 @@
package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.commonizer.cir.*
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirConstantValue
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirConstantValue.*
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirAnnotationFactory
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory
import org.jetbrains.kotlin.descriptors.commonizer.utils.mockClassType
import org.junit.Test
import kotlin.DeprecationLevel.*
@@ -28,13 +30,13 @@ class AnnotationsCommonizerTest : AbstractCommonizerTest<List<CirAnnotation>, Li
expected = emptyList(),
emptyList(),
emptyList(),
listOf(mockAnnotation("org.sample.Foo"))
listOf(mockAnnotation("org/sample/Foo"))
)
@Test
fun noRelevantAnnotations2() = doTestSuccess(
expected = emptyList(),
listOf(mockAnnotation("org.sample.Foo")),
listOf(mockAnnotation("org/sample/Foo")),
emptyList(),
emptyList()
)
@@ -42,25 +44,25 @@ class AnnotationsCommonizerTest : AbstractCommonizerTest<List<CirAnnotation>, Li
@Test
fun noRelevantAnnotations3() = doTestSuccess(
expected = emptyList(),
listOf(mockAnnotation("org.sample.Foo")),
listOf(mockAnnotation("org.sample.Foo")),
listOf(mockAnnotation("org.sample.Foo"))
listOf(mockAnnotation("org/sample/Foo")),
listOf(mockAnnotation("org/sample/Foo")),
listOf(mockAnnotation("org/sample/Foo"))
)
@Test
fun noRelevantAnnotations4() = doTestSuccess(
expected = emptyList(),
listOf(mockAnnotation("org.sample.Foo")),
listOf(mockAnnotation("org.sample.Bar")),
listOf(mockAnnotation("org.sample.Baz"))
listOf(mockAnnotation("org/sample/Foo")),
listOf(mockAnnotation("org/sample/Bar")),
listOf(mockAnnotation("org/sample/Baz"))
)
@Test
fun noRelevantAnnotations5() = doTestSuccess(
expected = emptyList(),
listOf(mockAnnotation("kotlin.PublishedApi")),
listOf(mockAnnotation("kotlin.PublishedApi")),
listOf(mockAnnotation("kotlin.PublishedApi"))
listOf(mockAnnotation("kotlin/PublishedApi")),
listOf(mockAnnotation("kotlin/PublishedApi")),
listOf(mockAnnotation("kotlin/PublishedApi"))
)
@Test
@@ -279,11 +281,11 @@ class AnnotationsCommonizerTest : AbstractCommonizerTest<List<CirAnnotation>, Li
}
private fun mockAnnotation(
fqName: String,
classId: String,
constantValueArguments: Map<CirName, CirConstantValue<*>> = emptyMap(),
annotationValueArguments: Map<CirName, CirAnnotation> = emptyMap()
): CirAnnotation = CirAnnotationFactory.create(
type = CirTypeFactory.create(mockClassType(fqName)) as CirClassType,
type = mockClassType(classId),
constantValueArguments = constantValueArguments,
annotationValueArguments = annotationValueArguments
)
@@ -296,7 +298,7 @@ private fun mockDeprecated(
): CirAnnotation {
val replaceWith: CirAnnotation? = if (replaceWithExpression.isNotEmpty() || replaceWithImports.isNotEmpty()) {
mockAnnotation(
fqName = "kotlin.ReplaceWith",
classId = "kotlin/ReplaceWith",
constantValueArguments = mapOf(
CirName.create("expression") to StringValue(replaceWithExpression),
CirName.create("imports") to ArrayValue(replaceWithImports.map(::StringValue))
@@ -306,7 +308,7 @@ private fun mockDeprecated(
} else null
return mockAnnotation(
fqName = "kotlin.Deprecated",
classId = "kotlin/Deprecated",
constantValueArguments = HashMap<CirName, CirConstantValue<*>>().apply {
this[CirName.create("message")] = StringValue(message)
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirExtensionReceiver
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirExtensionReceiverFactory
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory
import org.jetbrains.kotlin.descriptors.commonizer.utils.MOCK_CLASSIFIERS
import org.jetbrains.kotlin.descriptors.commonizer.utils.mockClassType
import org.junit.Test
@@ -22,23 +21,23 @@ class ExtensionReceiverCommonizerTest : AbstractCommonizerTest<CirExtensionRecei
@Test
fun sameReceiver() = doTestSuccess(
expected = mockExtensionReceiver("kotlin.String"),
mockExtensionReceiver("kotlin.String"),
mockExtensionReceiver("kotlin.String"),
mockExtensionReceiver("kotlin.String")
expected = mockExtensionReceiver("kotlin/String"),
mockExtensionReceiver("kotlin/String"),
mockExtensionReceiver("kotlin/String"),
mockExtensionReceiver("kotlin/String")
)
@Test(expected = IllegalCommonizerStateException::class)
fun differentReceivers() = doTestFailure(
mockExtensionReceiver("kotlin.String"),
mockExtensionReceiver("kotlin.String"),
mockExtensionReceiver("kotlin.Int")
mockExtensionReceiver("kotlin/String"),
mockExtensionReceiver("kotlin/String"),
mockExtensionReceiver("kotlin/Int")
)
@Test(expected = IllegalCommonizerStateException::class)
fun nullAndNonNullReceivers1() = doTestFailure(
mockExtensionReceiver("kotlin.String"),
mockExtensionReceiver("kotlin.String"),
mockExtensionReceiver("kotlin/String"),
mockExtensionReceiver("kotlin/String"),
null
)
@@ -46,13 +45,13 @@ class ExtensionReceiverCommonizerTest : AbstractCommonizerTest<CirExtensionRecei
fun nullAndNonNullReceivers2() = doTestFailure(
null,
null,
mockExtensionReceiver("kotlin.String")
mockExtensionReceiver("kotlin/String")
)
override fun createCommonizer() = ExtensionReceiverCommonizer(MOCK_CLASSIFIERS)
}
private fun mockExtensionReceiver(typeFqName: String) = CirExtensionReceiverFactory.create(
private fun mockExtensionReceiver(receiverClassId: String) = CirExtensionReceiverFactory.create(
annotations = emptyList(),
type = CirTypeFactory.create(mockClassType(typeFqName))
type = mockClassType(receiverClassId)
)
@@ -5,21 +5,15 @@
package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.commonizer.cir.*
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirClassFactory
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeAliasFactory
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.*
import org.jetbrains.kotlin.descriptors.commonizer.utils.classifierId
import org.jetbrains.kotlin.descriptors.commonizer.utils.isUnderStandardKotlinPackages
import org.jetbrains.kotlin.descriptors.commonizer.utils.mockClassType
import org.jetbrains.kotlin.descriptors.commonizer.utils.mockTAType
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.getAbbreviation
import org.junit.Before
import org.junit.Test
@@ -42,222 +36,222 @@ class TypeCommonizerTest : AbstractCommonizerTest<CirType, CirType>() {
@Test
fun classTypesInKotlinPackageWithSameName() = doTestSuccess(
expected = mockClassType("kotlin.collections.List"),
mockClassType("kotlin.collections.List"),
mockClassType("kotlin.collections.List"),
mockClassType("kotlin.collections.List")
expected = mockClassType("kotlin/collections/List"),
mockClassType("kotlin/collections/List"),
mockClassType("kotlin/collections/List"),
mockClassType("kotlin/collections/List")
)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInKotlinPackageWithDifferentNames1() = doTestFailure(
mockClassType("kotlin.collections.List"),
mockClassType("kotlin.collections.List"),
mockClassType("kotlin.fictitiousPackageName.List")
mockClassType("kotlin/collections/List"),
mockClassType("kotlin/collections/List"),
mockClassType("kotlin/fictitiousPackageName/List")
)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInKotlinPackageWithDifferentNames2() = doTestFailure(
mockClassType("kotlin.collections.List"),
mockClassType("kotlin.collections.List"),
mockClassType("kotlin.collections.Set")
mockClassType("kotlin/collections/List"),
mockClassType("kotlin/collections/List"),
mockClassType("kotlin/collections/Set")
)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInKotlinPackageWithDifferentNames3() = doTestFailure(
mockClassType("kotlin.collections.List"),
mockClassType("kotlin.collections.List"),
mockClassType("org.sample.Foo")
mockClassType("kotlin/collections/List"),
mockClassType("kotlin/collections/List"),
mockClassType("org/sample/Foo")
)
@Test
fun classTypesInKotlinxPackageWithSameName() = doTestSuccess(
expected = mockClassType("kotlinx.cinterop.CPointer"),
mockClassType("kotlinx.cinterop.CPointer"),
mockClassType("kotlinx.cinterop.CPointer"),
mockClassType("kotlinx.cinterop.CPointer")
expected = mockClassType("kotlinx/cinterop/CPointer"),
mockClassType("kotlinx/cinterop/CPointer"),
mockClassType("kotlinx/cinterop/CPointer"),
mockClassType("kotlinx/cinterop/CPointer")
)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInKotlinxPackageWithDifferentNames1() = doTestFailure(
mockClassType("kotlinx.cinterop.CPointer"),
mockClassType("kotlinx.cinterop.CPointer"),
mockClassType("kotlinx.fictitiousPackageName.CPointer")
mockClassType("kotlinx/cinterop/CPointer"),
mockClassType("kotlinx/cinterop/CPointer"),
mockClassType("kotlinx/fictitiousPackageName/CPointer")
)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInKotlinxPackageWithDifferentNames2() = doTestFailure(
mockClassType("kotlinx.cinterop.CPointer"),
mockClassType("kotlinx.cinterop.CPointer"),
mockClassType("kotlinx.cinterop.ObjCObject")
mockClassType("kotlinx/cinterop/CPointer"),
mockClassType("kotlinx/cinterop/CPointer"),
mockClassType("kotlinx/cinterop/ObjCObject")
)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInKotlinxPackageWithDifferentNames3() = doTestFailure(
mockClassType("kotlinx.cinterop.CPointer"),
mockClassType("kotlinx.cinterop.CPointer"),
mockClassType("org.sample.Foo")
mockClassType("kotlinx/cinterop/CPointer"),
mockClassType("kotlinx/cinterop/CPointer"),
mockClassType("org/sample/Foo")
)
@Test
fun classTypesInUserPackageWithSameName() = doTestSuccess(
expected = mockClassType("org.sample.Foo"),
mockClassType("org.sample.Foo"),
mockClassType("org.sample.Foo"),
mockClassType("org.sample.Foo")
expected = mockClassType("org/sample/Foo"),
mockClassType("org/sample/Foo"),
mockClassType("org/sample/Foo"),
mockClassType("org/sample/Foo")
)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInUserPackageWithDifferentNames1() = doTestFailure(
mockClassType("org.sample.Foo"),
mockClassType("org.fictitiousPackageName.Foo"),
mockClassType("org/sample/Foo"),
mockClassType("org/fictitiousPackageName/Foo"),
shouldFailOnFirstVariant = true
)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInUserPackageWithDifferentNames2() = doTestFailure(
mockClassType("org.sample.Foo"),
mockClassType("org.sample.Bar"),
mockClassType("org/sample/Foo"),
mockClassType("org/sample/Bar"),
shouldFailOnFirstVariant = true
)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInUserPackageWithDifferentNames3() = doTestFailure(
mockClassType("org.sample.Foo"),
mockClassType("kotlin.String"),
mockClassType("org/sample/Foo"),
mockClassType("kotlin/String"),
shouldFailOnFirstVariant = true
)
@Test
fun classTypesInKotlinPackageWithSameNullability1() = doTestSuccess(
expected = mockClassType("kotlin.collections.List", nullable = false),
mockClassType("kotlin.collections.List", nullable = false),
mockClassType("kotlin.collections.List", nullable = false),
mockClassType("kotlin.collections.List", nullable = false)
expected = mockClassType("kotlin/collections/List", nullable = false),
mockClassType("kotlin/collections/List", nullable = false),
mockClassType("kotlin/collections/List", nullable = false),
mockClassType("kotlin/collections/List", nullable = false)
)
@Test
fun classTypesInKotlinPackageWithSameNullability2() = doTestSuccess(
expected = mockClassType("kotlin.collections.List", nullable = true),
mockClassType("kotlin.collections.List", nullable = true),
mockClassType("kotlin.collections.List", nullable = true),
mockClassType("kotlin.collections.List", nullable = true)
expected = mockClassType("kotlin/collections/List", nullable = true),
mockClassType("kotlin/collections/List", nullable = true),
mockClassType("kotlin/collections/List", nullable = true),
mockClassType("kotlin/collections/List", nullable = true)
)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInKotlinPackageWithDifferentNullability1() = doTestFailure(
mockClassType("kotlin.collections.List", nullable = false),
mockClassType("kotlin.collections.List", nullable = false),
mockClassType("kotlin.collections.List", nullable = true)
mockClassType("kotlin/collections/List", nullable = false),
mockClassType("kotlin/collections/List", nullable = false),
mockClassType("kotlin/collections/List", nullable = true)
)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInKotlinPackageWithDifferentNullability2() = doTestFailure(
mockClassType("kotlin.collections.List", nullable = true),
mockClassType("kotlin.collections.List", nullable = true),
mockClassType("kotlin.collections.List", nullable = false)
mockClassType("kotlin/collections/List", nullable = true),
mockClassType("kotlin/collections/List", nullable = true),
mockClassType("kotlin/collections/List", nullable = false)
)
@Test
fun classTypesInUserPackageWithSameNullability1() = doTestSuccess(
expected = mockClassType("org.sample.Foo", nullable = false),
mockClassType("org.sample.Foo", nullable = false),
mockClassType("org.sample.Foo", nullable = false),
mockClassType("org.sample.Foo", nullable = false)
expected = mockClassType("org/sample/Foo", nullable = false),
mockClassType("org/sample/Foo", nullable = false),
mockClassType("org/sample/Foo", nullable = false),
mockClassType("org/sample/Foo", nullable = false)
)
@Test
fun classTypesInUserPackageWithSameNullability2() = doTestSuccess(
expected = mockClassType("org.sample.Foo", nullable = true),
mockClassType("org.sample.Foo", nullable = true),
mockClassType("org.sample.Foo", nullable = true),
mockClassType("org.sample.Foo", nullable = true)
expected = mockClassType("org/sample/Foo", nullable = true),
mockClassType("org/sample/Foo", nullable = true),
mockClassType("org/sample/Foo", nullable = true),
mockClassType("org/sample/Foo", nullable = true)
)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInUserPackageWithDifferentNullability1() = doTestFailure(
mockClassType("org.sample.Foo", nullable = false),
mockClassType("org.sample.Foo", nullable = false),
mockClassType("org.sample.Foo", nullable = true)
mockClassType("org/sample/Foo", nullable = false),
mockClassType("org/sample/Foo", nullable = false),
mockClassType("org/sample/Foo", nullable = true)
)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInUserPackageWithDifferentNullability2() = doTestFailure(
mockClassType("org.sample.Foo", nullable = true),
mockClassType("org.sample.Foo", nullable = true),
mockClassType("org.sample.Foo", nullable = false)
mockClassType("org/sample/Foo", nullable = true),
mockClassType("org/sample/Foo", nullable = true),
mockClassType("org/sample/Foo", nullable = false)
)
@Test
// why success: matching FQNs from the standard Kotlin packages
fun taTypesInKotlinPackageWithSameNameAndClass() = doTestSuccess(
expected = mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.SequenceScope") },
mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.SequenceScope") },
mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.SequenceScope") },
mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.SequenceScope") }
expected = mockTAType("kotlin/sequences/SequenceBuilder") { mockClassType("kotlin/sequences/SequenceScope") },
mockTAType("kotlin/sequences/SequenceBuilder") { mockClassType("kotlin/sequences/SequenceScope") },
mockTAType("kotlin/sequences/SequenceBuilder") { mockClassType("kotlin/sequences/SequenceScope") },
mockTAType("kotlin/sequences/SequenceBuilder") { mockClassType("kotlin/sequences/SequenceScope") }
)
@Test(expected = IllegalCommonizerStateException::class)
fun taTypesInKotlinPackageWithDifferentNames() = doTestFailure(
mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.SequenceScope") },
mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.SequenceScope") },
mockTAType("kotlin.sequences.FictitiousTypeAlias") { mockClassType("kotlin.sequences.SequenceScope") }
mockTAType("kotlin/sequences/SequenceBuilder") { mockClassType("kotlin/sequences/SequenceScope") },
mockTAType("kotlin/sequences/SequenceBuilder") { mockClassType("kotlin/sequences/SequenceScope") },
mockTAType("kotlin/sequences/FictitiousTypeAlias") { mockClassType("kotlin/sequences/SequenceScope") }
)
@Test
// why success: matching FQNs from the standard Kotlin packages
fun taTypesInKotlinPackageWithDifferentClasses() = doTestSuccess(
expected = mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.SequenceScope") },
mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.SequenceScope") },
mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.SequenceScope") },
mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.FictitiousClass") }
expected = mockTAType("kotlin/sequences/SequenceBuilder") { mockClassType("kotlin/sequences/SequenceScope") },
mockTAType("kotlin/sequences/SequenceBuilder") { mockClassType("kotlin/sequences/SequenceScope") },
mockTAType("kotlin/sequences/SequenceBuilder") { mockClassType("kotlin/sequences/SequenceScope") },
mockTAType("kotlin/sequences/SequenceBuilder") { mockClassType("kotlin/sequences/FictitiousClass") }
)
@Test
// why success: matching FQNs from the standard Kotlin packages
fun taTypesInKotlinxPackageWithSameNameAndClass() = doTestSuccess(
expected = mockTAType("kotlinx.cinterop.CArrayPointer") { mockClassType("kotlinx.cinterop.CPointer") },
mockTAType("kotlinx.cinterop.CArrayPointer") { mockClassType("kotlinx.cinterop.CPointer") },
mockTAType("kotlinx.cinterop.CArrayPointer") { mockClassType("kotlinx.cinterop.CPointer") },
mockTAType("kotlinx.cinterop.CArrayPointer") { mockClassType("kotlinx.cinterop.CPointer") }
expected = mockTAType("kotlinx/cinterop/CArrayPointer") { mockClassType("kotlinx/cinterop/CPointer") },
mockTAType("kotlinx/cinterop/CArrayPointer") { mockClassType("kotlinx/cinterop/CPointer") },
mockTAType("kotlinx/cinterop/CArrayPointer") { mockClassType("kotlinx/cinterop/CPointer") },
mockTAType("kotlinx/cinterop/CArrayPointer") { mockClassType("kotlinx/cinterop/CPointer") }
)
@Test(expected = IllegalCommonizerStateException::class)
fun taTypesInKotlinxPackageWithDifferentNames() = doTestFailure(
mockTAType("kotlinx.cinterop.CArrayPointer") { mockClassType("kotlinx.cinterop.CPointer") },
mockTAType("kotlinx.cinterop.CArrayPointer") { mockClassType("kotlinx.cinterop.CPointer") },
mockTAType("kotlinx.cinterop.FictitiousTypeAlias") { mockClassType("kotlinx.cinterop.CPointer") }
mockTAType("kotlinx/cinterop/CArrayPointer") { mockClassType("kotlinx/cinterop/CPointer") },
mockTAType("kotlinx/cinterop/CArrayPointer") { mockClassType("kotlinx/cinterop/CPointer") },
mockTAType("kotlinx/cinterop/FictitiousTypeAlias") { mockClassType("kotlinx/cinterop/CPointer") }
)
@Test
// why success: matching FQNs from the standard Kotlin packages
fun taTypesInKotlinxPackageWithDifferentClasses() = doTestSuccess(
expected = mockTAType("kotlinx.cinterop.CArrayPointer") { mockClassType("kotlinx.cinterop.CPointer") },
mockTAType("kotlinx.cinterop.CArrayPointer") { mockClassType("kotlinx.cinterop.CPointer") },
mockTAType("kotlinx.cinterop.CArrayPointer") { mockClassType("kotlinx.cinterop.CPointer") },
mockTAType("kotlinx.cinterop.CArrayPointer") { mockClassType("kotlinx.cinterop.FictitiousClass") }
expected = mockTAType("kotlinx/cinterop/CArrayPointer") { mockClassType("kotlinx/cinterop/CPointer") },
mockTAType("kotlinx/cinterop/CArrayPointer") { mockClassType("kotlinx/cinterop/CPointer") },
mockTAType("kotlinx/cinterop/CArrayPointer") { mockClassType("kotlinx/cinterop/CPointer") },
mockTAType("kotlinx/cinterop/CArrayPointer") { mockClassType("kotlinx/cinterop/FictitiousClass") }
)
@Test
// why success: matching FQNs from the standard Kotlin packages
fun multilevelTATypesInKotlinPackageWithSameNameAndRightHandSideClass() = doTestSuccess(
expected = mockTAType("kotlin.FictitiousTypeAlias") {
mockClassType("kotlin.FictitiousClass")
expected = mockTAType("kotlin/FictitiousTypeAlias") {
mockClassType("kotlin/FictitiousClass")
},
mockTAType("kotlin.FictitiousTypeAlias") {
mockClassType("kotlin.FictitiousClass")
mockTAType("kotlin/FictitiousTypeAlias") {
mockClassType("kotlin/FictitiousClass")
},
mockTAType("kotlin.FictitiousTypeAlias") {
mockTAType("kotlin.FictitiousTypeAliasL2") {
mockClassType("kotlin.FictitiousClass")
mockTAType("kotlin/FictitiousTypeAlias") {
mockTAType("kotlin/FictitiousTypeAliasL2") {
mockClassType("kotlin/FictitiousClass")
}
},
mockTAType("kotlin.FictitiousTypeAlias") {
mockTAType("kotlin.FictitiousTypeAliasL2") {
mockTAType("kotlin.FictitiousTypeAliasL3") {
mockClassType("kotlin.FictitiousClass")
mockTAType("kotlin/FictitiousTypeAlias") {
mockTAType("kotlin/FictitiousTypeAliasL2") {
mockTAType("kotlin/FictitiousTypeAliasL3") {
mockClassType("kotlin/FictitiousClass")
}
}
}
@@ -266,41 +260,41 @@ class TypeCommonizerTest : AbstractCommonizerTest<CirType, CirType>() {
@Test
// why success: lifting up
fun taTypesInUserPackageWithSameNameAndClass() = doTestSuccess(
expected = mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Foo") },
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Foo") },
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Foo") },
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Foo") }
expected = mockTAType("org/sample/FooAlias") { mockClassType("org/sample/Foo") },
mockTAType("org/sample/FooAlias") { mockClassType("org/sample/Foo") },
mockTAType("org/sample/FooAlias") { mockClassType("org/sample/Foo") },
mockTAType("org/sample/FooAlias") { mockClassType("org/sample/Foo") }
)
@Test(expected = IllegalCommonizerStateException::class)
fun taTypesInUserPackageWithDifferentNames() = doTestFailure(
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Foo") },
mockTAType("org.sample.BarAlias") { mockClassType("org.sample.Foo") },
mockTAType("org/sample/FooAlias") { mockClassType("org/sample/Foo") },
mockTAType("org/sample/BarAlias") { mockClassType("org/sample/Foo") },
shouldFailOnFirstVariant = true
)
@Test
// why success: expect class/actual TAs
fun taTypesInUserPackageWithDifferentClasses() = doTestSuccess(
expected = mockClassType("org.sample.FooAlias"),
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Foo") },
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Bar") }
expected = mockClassType("org/sample/FooAlias"),
mockTAType("org/sample/FooAlias") { mockClassType("org/sample/Foo") },
mockTAType("org/sample/FooAlias") { mockClassType("org/sample/Bar") }
)
@Test
// why success: short-circuiting & lifting up
fun multilevelTATypesInUserPackageWithSameNameAndRightHandSideClass1() = doTestSuccess(
expected = mockTAType("org.sample.FooAlias") {
mockClassType("org.sample.Foo")
expected = mockTAType("org/sample/FooAlias") {
mockClassType("org/sample/Foo")
},
mockTAType("org.sample.FooAlias") {
mockClassType("org.sample.Foo")
mockTAType("org/sample/FooAlias") {
mockClassType("org/sample/Foo")
},
mockTAType("org.sample.FooAlias") {
mockTAType("org.sample.FooAliasL2") {
mockClassType("org.sample.Foo")
mockTAType("org/sample/FooAlias") {
mockTAType("org/sample/FooAliasL2") {
mockClassType("org/sample/Foo")
}
}
)
@@ -308,39 +302,39 @@ class TypeCommonizerTest : AbstractCommonizerTest<CirType, CirType>() {
@Test
// why success: short-circuiting & lifting up
fun multilevelTATypesInUserPackageWithSameNameAndRightHandSideClass2() = doTestSuccess(
expected = mockTAType("org.sample.FooAlias") {
mockClassType("org.sample.Foo")
expected = mockTAType("org/sample/FooAlias") {
mockClassType("org/sample/Foo")
},
mockTAType("org.sample.FooAlias") {
mockTAType("org.sample.FooAliasL2") {
mockClassType("org.sample.Foo")
mockTAType("org/sample/FooAlias") {
mockTAType("org/sample/FooAliasL2") {
mockClassType("org/sample/Foo")
}
},
mockTAType("org.sample.FooAlias") {
mockClassType("org.sample.Foo")
mockTAType("org/sample/FooAlias") {
mockClassType("org/sample/Foo")
}
)
@Test
// why success: lifting up (inner and outer TAs)
fun multilevelTATypesInUserPackageWithSameNameAndRightHandSideClass3() = doTestSuccess(
expected = mockTAType("org.sample.FooAlias") {
mockTAType("org.sample.FooAliasL2") {
mockClassType("org.sample.Foo")
expected = mockTAType("org/sample/FooAlias") {
mockTAType("org/sample/FooAliasL2") {
mockClassType("org/sample/Foo")
}
},
mockTAType("org.sample.FooAlias") {
mockTAType("org.sample.FooAliasL2") {
mockClassType("org.sample.Foo")
mockTAType("org/sample/FooAlias") {
mockTAType("org/sample/FooAliasL2") {
mockClassType("org/sample/Foo")
}
},
mockTAType("org.sample.FooAlias") {
mockTAType("org.sample.FooAliasL2") {
mockClassType("org.sample.Foo")
mockTAType("org/sample/FooAlias") {
mockTAType("org/sample/FooAliasL2") {
mockClassType("org/sample/Foo")
}
}
)
@@ -348,21 +342,21 @@ class TypeCommonizerTest : AbstractCommonizerTest<CirType, CirType>() {
@Test
// why success: lifting up outer TA and expect class for inner TA
fun multilevelTATypesInUserPackageWithSameNameAndRightHandSideClass4() = doTestSuccess(
expected = mockTAType("org.sample.FooAlias") {
mockTAType("org.sample.FooAliasL2") {
mockClassType("org.sample.Foo")
expected = mockTAType("org/sample/FooAlias") {
mockTAType("org/sample/FooAliasL2") {
mockClassType("org/sample/Foo")
}
},
mockTAType("org.sample.FooAlias") {
mockTAType("org.sample.FooAliasL2") {
mockClassType("org.sample.Bar")
mockTAType("org/sample/FooAlias") {
mockTAType("org/sample/FooAliasL2") {
mockClassType("org/sample/Bar")
}
},
mockTAType("org.sample.FooAlias") {
mockTAType("org.sample.FooAliasL2") {
mockClassType("org.sample.Baz")
mockTAType("org/sample/FooAlias") {
mockTAType("org/sample/FooAliasL2") {
mockClassType("org/sample/Baz")
}
}
)
@@ -370,136 +364,151 @@ class TypeCommonizerTest : AbstractCommonizerTest<CirType, CirType>() {
@Test
// why success: types with the same nullability are treated as equal
fun taTypesInKotlinPackageWithSameNullability1() = doTestSuccess(
expected = mockTAType("kotlin.sequences.SequenceBuilder", nullable = false) { mockClassType("kotlin.sequences.SequenceScope") },
mockTAType("kotlin.sequences.SequenceBuilder", nullable = false) { mockClassType("kotlin.sequences.SequenceScope") },
mockTAType("kotlin.sequences.SequenceBuilder", nullable = false) { mockClassType("kotlin.sequences.SequenceScope") },
mockTAType("kotlin.sequences.SequenceBuilder", nullable = false) { mockClassType("kotlin.sequences.SequenceScope") }
expected = mockTAType("kotlin/sequences/SequenceBuilder", nullable = false) { mockClassType("kotlin/sequences/SequenceScope") },
mockTAType("kotlin/sequences/SequenceBuilder", nullable = false) { mockClassType("kotlin/sequences/SequenceScope") },
mockTAType("kotlin/sequences/SequenceBuilder", nullable = false) { mockClassType("kotlin/sequences/SequenceScope") },
mockTAType("kotlin/sequences/SequenceBuilder", nullable = false) { mockClassType("kotlin/sequences/SequenceScope") }
)
@Test
// why success: types with the same nullability are treated as equal
fun taTypesInKotlinPackageWithSameNullability2() = doTestSuccess(
expected = mockTAType("kotlin.sequences.SequenceBuilder", nullable = true) { mockClassType("kotlin.sequences.SequenceScope") },
mockTAType("kotlin.sequences.SequenceBuilder", nullable = true) { mockClassType("kotlin.sequences.SequenceScope") },
mockTAType("kotlin.sequences.SequenceBuilder", nullable = true) { mockClassType("kotlin.sequences.SequenceScope") },
mockTAType("kotlin.sequences.SequenceBuilder", nullable = true) { mockClassType("kotlin.sequences.SequenceScope") }
expected = mockTAType("kotlin/sequences/SequenceBuilder", nullable = true) { mockClassType("kotlin/sequences/SequenceScope") },
mockTAType("kotlin/sequences/SequenceBuilder", nullable = true) { mockClassType("kotlin/sequences/SequenceScope") },
mockTAType("kotlin/sequences/SequenceBuilder", nullable = true) { mockClassType("kotlin/sequences/SequenceScope") },
mockTAType("kotlin/sequences/SequenceBuilder", nullable = true) { mockClassType("kotlin/sequences/SequenceScope") }
)
@Test(expected = IllegalCommonizerStateException::class)
fun taTypesInKotlinPackageWithDifferentNullability1() = doTestFailure(
mockTAType("kotlin.sequences.SequenceBuilder", nullable = false) { mockClassType("kotlin.sequences.SequenceScope") },
mockTAType("kotlin.sequences.SequenceBuilder", nullable = false) { mockClassType("kotlin.sequences.SequenceScope") },
mockTAType("kotlin.sequences.SequenceBuilder", nullable = true) { mockClassType("kotlin.sequences.SequenceScope") }
mockTAType("kotlin/sequences/SequenceBuilder", nullable = false) { mockClassType("kotlin/sequences/SequenceScope") },
mockTAType("kotlin/sequences/SequenceBuilder", nullable = false) { mockClassType("kotlin/sequences/SequenceScope") },
mockTAType("kotlin/sequences/SequenceBuilder", nullable = true) { mockClassType("kotlin/sequences/SequenceScope") }
)
@Test(expected = IllegalCommonizerStateException::class)
fun taTypesInKotlinPackageWithDifferentNullability2() = doTestFailure(
mockTAType("kotlin.sequences.SequenceBuilder", nullable = true) { mockClassType("kotlin.sequences.SequenceScope") },
mockTAType("kotlin.sequences.SequenceBuilder", nullable = true) { mockClassType("kotlin.sequences.SequenceScope") },
mockTAType("kotlin.sequences.SequenceBuilder", nullable = false) { mockClassType("kotlin.sequences.SequenceScope") }
mockTAType("kotlin/sequences/SequenceBuilder", nullable = true) { mockClassType("kotlin/sequences/SequenceScope") },
mockTAType("kotlin/sequences/SequenceBuilder", nullable = true) { mockClassType("kotlin/sequences/SequenceScope") },
mockTAType("kotlin/sequences/SequenceBuilder", nullable = false) { mockClassType("kotlin/sequences/SequenceScope") }
)
@Test
// why success: nullability of underlying type does not matter if typealias belongs to one of the standard Kotlin packages
fun taTypesInKotlinPackageWithDifferentNullability3() = doTestSuccess(
expected = mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.SequenceScope", nullable = false) },
mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.SequenceScope", nullable = false) },
mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.SequenceScope", nullable = false) },
mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.SequenceScope", nullable = true) }
expected = mockTAType("kotlin/sequences/SequenceBuilder") { mockClassType("kotlin/sequences/SequenceScope", nullable = false) },
mockTAType("kotlin/sequences/SequenceBuilder") { mockClassType("kotlin/sequences/SequenceScope", nullable = false) },
mockTAType("kotlin/sequences/SequenceBuilder") { mockClassType("kotlin/sequences/SequenceScope", nullable = false) },
mockTAType("kotlin/sequences/SequenceBuilder") { mockClassType("kotlin/sequences/SequenceScope", nullable = true) }
)
@Test
// why success: nullability of underlying type does not matter if typealias belongs to one of the standard Kotlin packages
fun taTypesInKotlinPackageWithDifferentNullability4() = doTestSuccess(
expected = mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.SequenceScope", nullable = true) },
mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.SequenceScope", nullable = true) },
mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.SequenceScope", nullable = true) },
mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.SequenceScope", nullable = false) }
expected = mockTAType("kotlin/sequences/SequenceBuilder") { mockClassType("kotlin/sequences/SequenceScope", nullable = true) },
mockTAType("kotlin/sequences/SequenceBuilder") { mockClassType("kotlin/sequences/SequenceScope", nullable = true) },
mockTAType("kotlin/sequences/SequenceBuilder") { mockClassType("kotlin/sequences/SequenceScope", nullable = true) },
mockTAType("kotlin/sequences/SequenceBuilder") { mockClassType("kotlin/sequences/SequenceScope", nullable = false) }
)
@Test
// why success: types with the same nullability are treated as equal
fun taTypesInUserPackageWithSameNullability1() = doTestSuccess(
expected = mockTAType("org.sample.FooAlias", nullable = false) { mockClassType("org.sample.Foo") },
mockTAType("org.sample.FooAlias", nullable = false) { mockClassType("org.sample.Foo") },
mockTAType("org.sample.FooAlias", nullable = false) { mockClassType("org.sample.Foo") },
mockTAType("org.sample.FooAlias", nullable = false) { mockClassType("org.sample.Foo") }
expected = mockTAType("org/sample/FooAlias", nullable = false) { mockClassType("org/sample/Foo") },
mockTAType("org/sample/FooAlias", nullable = false) { mockClassType("org/sample/Foo") },
mockTAType("org/sample/FooAlias", nullable = false) { mockClassType("org/sample/Foo") },
mockTAType("org/sample/FooAlias", nullable = false) { mockClassType("org/sample/Foo") }
)
@Test
// why success: types with the same nullability are treated as equal
fun taTypesInUserPackageWithSameNullability2() = doTestSuccess(
expected = mockTAType("org.sample.FooAlias", nullable = true) { mockClassType("org.sample.Foo") },
mockTAType("org.sample.FooAlias", nullable = true) { mockClassType("org.sample.Foo") },
mockTAType("org.sample.FooAlias", nullable = true) { mockClassType("org.sample.Foo") },
mockTAType("org.sample.FooAlias", nullable = true) { mockClassType("org.sample.Foo") }
expected = mockTAType("org/sample/FooAlias", nullable = true) { mockClassType("org/sample/Foo") },
mockTAType("org/sample/FooAlias", nullable = true) { mockClassType("org/sample/Foo") },
mockTAType("org/sample/FooAlias", nullable = true) { mockClassType("org/sample/Foo") },
mockTAType("org/sample/FooAlias", nullable = true) { mockClassType("org/sample/Foo") }
)
@Test(expected = IllegalCommonizerStateException::class)
fun taTypesInUserPackageWithDifferentNullability1() = doTestFailure(
mockTAType("org.sample.FooAlias", nullable = false) { mockClassType("org.sample.Foo") },
mockTAType("org.sample.FooAlias", nullable = false) { mockClassType("org.sample.Foo") },
mockTAType("org.sample.FooAlias", nullable = true) { mockClassType("org.sample.Foo") }
mockTAType("org/sample/FooAlias", nullable = false) { mockClassType("org/sample/Foo") },
mockTAType("org/sample/FooAlias", nullable = false) { mockClassType("org/sample/Foo") },
mockTAType("org/sample/FooAlias", nullable = true) { mockClassType("org/sample/Foo") }
)
@Test(expected = IllegalCommonizerStateException::class)
fun taTypesInUserPackageWithDifferentNullability2() = doTestFailure(
mockTAType("org.sample.FooAlias", nullable = true) { mockClassType("org.sample.Foo") },
mockTAType("org.sample.FooAlias", nullable = true) { mockClassType("org.sample.Foo") },
mockTAType("org.sample.FooAlias", nullable = false) { mockClassType("org.sample.Foo") }
mockTAType("org/sample/FooAlias", nullable = true) { mockClassType("org/sample/Foo") },
mockTAType("org/sample/FooAlias", nullable = true) { mockClassType("org/sample/Foo") },
mockTAType("org/sample/FooAlias", nullable = false) { mockClassType("org/sample/Foo") }
)
@Test
// why success: nullability of underlying type does not matter if expect class/actual TAs created
fun taTypesInUserPackageWithDifferentNullability3() = doTestSuccess(
expected = mockClassType("org.sample.FooAlias"),
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Foo", nullable = false) },
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Foo", nullable = true) }
expected = mockClassType("org/sample/FooAlias"),
mockTAType("org/sample/FooAlias") { mockClassType("org/sample/Foo", nullable = false) },
mockTAType("org/sample/FooAlias") { mockClassType("org/sample/Foo", nullable = true) }
)
@Test
// why success: nullability of underlying type does not matter if expect class/actual TAs created
fun taTypesInUserPackageWithDifferentNullability4() = doTestSuccess(
expected = mockClassType("org.sample.FooAlias"),
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Foo", nullable = true) },
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Foo", nullable = false) }
expected = mockClassType("org/sample/FooAlias"),
mockTAType("org/sample/FooAlias") { mockClassType("org/sample/Foo", nullable = true) },
mockTAType("org/sample/FooAlias") { mockClassType("org/sample/Foo", nullable = false) }
)
private fun prepareCache(variants: Array<out KotlinType>) {
private fun prepareCache(variants: Array<out CirClassOrTypeAliasType>) {
check(variants.isNotEmpty())
fun recurse(type: KotlinType, index: Int) {
@Suppress("MoveVariableDeclarationIntoWhen")
val descriptor = (type.getAbbreviation() ?: type).constructor.declarationDescriptor
when (descriptor) {
is ClassDescriptor -> {
val classId = descriptor.classifierId
val node = classifiers.classNode(classId) {
fun recurse(type: CirClassOrTypeAliasType, index: Int) {
when (type) {
is CirClassType -> {
val node = classifiers.classNode(type.classifierId) {
buildClassNode(
storageManager = LockBasedStorageManager.NO_LOCKS,
size = variants.size,
classifiers = classifiers,
parentCommonDeclaration = null,
classId = classId
classId = type.classifierId
)
}
node.targetDeclarations[index] = CirClassFactory.create(descriptor)
node.targetDeclarations[index] = CirClassFactory.create(
annotations = emptyList(),
name = type.classifierId.relativeNameSegments.last(),
typeParameters = emptyList(),
visibility = DescriptorVisibilities.PUBLIC,
modality = Modality.FINAL,
kind = ClassKind.CLASS,
companion = null,
isCompanion = false,
isData = false,
isInline = false,
isInner = false,
isExternal = false
)
}
is TypeAliasDescriptor -> {
val typeAliasId = descriptor.classifierId
val node = classifiers.typeAliasNode(typeAliasId) {
is CirTypeAliasType -> {
val node = classifiers.typeAliasNode(type.classifierId) {
buildTypeAliasNode(
storageManager = LockBasedStorageManager.NO_LOCKS,
size = variants.size,
classifiers = classifiers,
typeAliasId = typeAliasId
typeAliasId = type.classifierId
)
}
node.targetDeclarations[index] = CirTypeAliasFactory.create(descriptor)
node.targetDeclarations[index] = CirTypeAliasFactory.create(
annotations = emptyList(),
name = type.classifierId.relativeNameSegments.last(),
typeParameters = emptyList(),
visibility = DescriptorVisibilities.PUBLIC,
underlyingType = type.underlyingType,
expandedType = computeExpandedType(type.underlyingType)
)
recurse(descriptor.underlyingType, index) // expand underlying types recursively
recurse(type.underlyingType, index) // expand underlying types recursively
}
else -> error("Unexpected descriptor of KotlinType: $descriptor, $type")
}
}
@@ -508,22 +517,14 @@ class TypeCommonizerTest : AbstractCommonizerTest<CirType, CirType>() {
}
}
fun doTestSuccess(expected: KotlinType, vararg variants: KotlinType) {
fun doTestSuccess(expected: CirClassOrTypeAliasType, vararg variants: CirClassOrTypeAliasType) {
prepareCache(variants)
doTestSuccess(
expected = CirTypeFactory.create(expected),
variants = variants.map(CirTypeFactory::create).toTypedArray()
)
super.doTestSuccess(expected, *variants)
}
fun doTestFailure(vararg variants: KotlinType, shouldFailOnFirstVariant: Boolean = false) {
fun doTestFailure(vararg variants: CirClassOrTypeAliasType, shouldFailOnFirstVariant: Boolean = false) {
prepareCache(variants)
doTestFailure(
variants = variants.map(CirTypeFactory::create).toTypedArray(),
shouldFailOnFirstVariant = shouldFailOnFirstVariant
)
super.doTestFailure(*variants, shouldFailOnFirstVariant = shouldFailOnFirstVariant)
}
override fun createCommonizer() = TypeCommonizer(classifiers)
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeParameter
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeParameterFactory
import org.jetbrains.kotlin.descriptors.commonizer.utils.MOCK_CLASSIFIERS
import org.jetbrains.kotlin.descriptors.commonizer.utils.mockClassType
@@ -63,23 +62,23 @@ class TypeParameterCommonizerTest : AbstractCommonizerTest<CirTypeParameter, Cir
@Test(expected = IllegalCommonizerStateException::class)
fun differentUpperBounds1() = doTestFailure(
mockTypeParam(upperBounds = listOf("kotlin.String")),
mockTypeParam(upperBounds = listOf("kotlin.String")),
mockTypeParam(upperBounds = listOf("kotlin.Int"))
mockTypeParam(upperBounds = listOf("kotlin/String")),
mockTypeParam(upperBounds = listOf("kotlin/String")),
mockTypeParam(upperBounds = listOf("kotlin/Int"))
)
@Test(expected = IllegalCommonizerStateException::class)
fun differentUpperBounds2() = doTestFailure(
mockTypeParam(upperBounds = listOf("kotlin.String", "kotlin.Int")),
mockTypeParam(upperBounds = listOf("kotlin.String", "kotlin.Int")),
mockTypeParam(upperBounds = listOf("kotlin.String"))
mockTypeParam(upperBounds = listOf("kotlin/String", "kotlin/Int")),
mockTypeParam(upperBounds = listOf("kotlin/String", "kotlin/Int")),
mockTypeParam(upperBounds = listOf("kotlin/String"))
)
@Test(expected = IllegalCommonizerStateException::class)
fun differentUpperBounds3() = doTestFailure(
mockTypeParam(upperBounds = listOf("kotlin.String", "kotlin.Int")),
mockTypeParam(upperBounds = listOf("kotlin.String", "kotlin.Int")),
mockTypeParam(upperBounds = listOf("kotlin.Int", "kotlin.String"))
mockTypeParam(upperBounds = listOf("kotlin/String", "kotlin/Int")),
mockTypeParam(upperBounds = listOf("kotlin/String", "kotlin/Int")),
mockTypeParam(upperBounds = listOf("kotlin/Int", "kotlin/String"))
)
internal companion object {
@@ -87,13 +86,13 @@ class TypeParameterCommonizerTest : AbstractCommonizerTest<CirTypeParameter, Cir
name: String = "T",
isReified: Boolean = false,
variance: Variance = Variance.INVARIANT,
upperBounds: List<String> = listOf("kotlin.Any")
upperBounds: List<String> = listOf("kotlin/Any")
) = CirTypeParameterFactory.create(
annotations = emptyList(),
name = CirName.create(name),
isReified = isReified,
variance = variance,
upperBounds = upperBounds.map { CirTypeFactory.create(mockClassType(it)) }
upperBounds = upperBounds.map(::mockClassType)
)
}
}
@@ -22,38 +22,38 @@ class TypeParameterListCommonizerTest : AbstractCommonizerTest<List<CirTypeParam
@Test
fun matchedParameters() = doTestSuccess(
expected = mockTypeParams(
"T" to "kotlin.Any?",
"R" to "kotlin.CharSequence",
"Q" to "org.sample.Foo?"
"T" to "kotlin/Any",
"R" to "kotlin/CharSequence",
"Q" to "org/sample/Foo"
),
mockTypeParams(
"T" to "kotlin.Any?",
"R" to "kotlin.CharSequence",
"Q" to "org.sample.Foo?"
"T" to "kotlin/Any",
"R" to "kotlin/CharSequence",
"Q" to "org/sample/Foo"
),
mockTypeParams(
"T" to "kotlin.Any?",
"R" to "kotlin.CharSequence",
"Q" to "org.sample.Foo?"
"T" to "kotlin/Any",
"R" to "kotlin/CharSequence",
"Q" to "org/sample/Foo"
),
mockTypeParams(
"T" to "kotlin.Any?",
"R" to "kotlin.CharSequence",
"Q" to "org.sample.Foo?"
"T" to "kotlin/Any",
"R" to "kotlin/CharSequence",
"Q" to "org/sample/Foo"
)
)
@Test(expected = IllegalCommonizerStateException::class)
fun mismatchedParameterListSize1() = doTestFailure(
mockTypeParams(
"T" to "kotlin.Any?",
"R" to "kotlin.CharSequence",
"Q" to "org.sample.Foo?"
"T" to "kotlin/Any",
"R" to "kotlin/CharSequence",
"Q" to "org/sample/Foo"
),
mockTypeParams(
"T" to "kotlin.Any?",
"R" to "kotlin.CharSequence",
"Q" to "org.sample.Foo?"
"T" to "kotlin/Any",
"R" to "kotlin/CharSequence",
"Q" to "org/sample/Foo"
),
emptyList()
)
@@ -61,50 +61,50 @@ class TypeParameterListCommonizerTest : AbstractCommonizerTest<List<CirTypeParam
@Test(expected = IllegalCommonizerStateException::class)
fun mismatchedParameterListSize2() = doTestFailure(
mockTypeParams(
"T" to "kotlin.Any?",
"R" to "kotlin.CharSequence",
"Q" to "org.sample.Foo?"
"T" to "kotlin/Any",
"R" to "kotlin/CharSequence",
"Q" to "org/sample/Foo"
),
mockTypeParams(
"T" to "kotlin.Any?",
"R" to "kotlin.CharSequence",
"Q" to "org.sample.Foo?"
"T" to "kotlin/Any",
"R" to "kotlin/CharSequence",
"Q" to "org/sample/Foo"
),
mockTypeParams(
"T" to "kotlin.Any?",
"R" to "kotlin.CharSequence"
"T" to "kotlin/Any",
"R" to "kotlin/CharSequence"
)
)
@Test(expected = IllegalCommonizerStateException::class)
fun mismatchedParameterListSize3() = doTestFailure(
mockTypeParams(
"T" to "kotlin.Any?",
"R" to "kotlin.CharSequence",
"Q" to "org.sample.Foo?"
"T" to "kotlin/Any",
"R" to "kotlin/CharSequence",
"Q" to "org/sample/Foo"
),
mockTypeParams(
"T" to "kotlin.Any?",
"R" to "kotlin.CharSequence",
"Q" to "org.sample.Foo?"
"T" to "kotlin/Any",
"R" to "kotlin/CharSequence",
"Q" to "org/sample/Foo"
),
mockTypeParams(
"T" to "kotlin.Any?",
"R" to "kotlin.CharSequence",
"Q" to "org.sample.Foo?",
"V" to "org.sample.Bar"
"T" to "kotlin/Any",
"R" to "kotlin/CharSequence",
"Q" to "org/sample/Foo",
"V" to "org/sample/Bar"
)
)
@Test(expected = IllegalCommonizerStateException::class)
fun mismatchedParameterNames() = doTestFailure(
mockTypeParams(
"T" to "kotlin.Any?",
"R" to "kotlin.CharSequence"
"T" to "kotlin/Any",
"R" to "kotlin/CharSequence"
),
mockTypeParams(
"T" to "kotlin.Any?",
"Q" to "kotlin.CharSequence"
"T" to "kotlin/Any",
"Q" to "kotlin/CharSequence"
)
)
@@ -113,10 +113,10 @@ class TypeParameterListCommonizerTest : AbstractCommonizerTest<List<CirTypeParam
private companion object {
fun mockTypeParams(vararg params: Pair<String, String>): List<CirTypeParameter> {
check(params.isNotEmpty())
return params.map { (name, returnTypeFqName) ->
return params.map { (name, upperBounds) ->
TypeParameterCommonizerTest.mockTypeParam(
name = name,
upperBounds = listOf(returnTypeFqName)
upperBounds = listOf(upperBounds)
)
}
}
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirType
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirValueParameter
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory
import org.jetbrains.kotlin.descriptors.commonizer.core.CirTestValueParameter.Companion.areEqual
import org.jetbrains.kotlin.descriptors.commonizer.core.TypeCommonizerTest.Companion.areEqual
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirKnownClassifiers
@@ -21,124 +20,124 @@ class ValueParameterCommonizerTest : AbstractCommonizerTest<CirValueParameter, C
@Test
fun sameReturnType1() = doTestSuccess(
expected = mockValueParam("kotlin.String"),
mockValueParam("kotlin.String"),
mockValueParam("kotlin.String"),
mockValueParam("kotlin.String")
expected = mockValueParam("kotlin/String"),
mockValueParam("kotlin/String"),
mockValueParam("kotlin/String"),
mockValueParam("kotlin/String")
)
@Test
fun sameReturnType2() = doTestSuccess(
expected = mockValueParam("org.sample.Foo"),
mockValueParam("org.sample.Foo"),
mockValueParam("org.sample.Foo"),
mockValueParam("org.sample.Foo")
expected = mockValueParam("org/sample/Foo"),
mockValueParam("org/sample/Foo"),
mockValueParam("org/sample/Foo"),
mockValueParam("org/sample/Foo")
)
@Test(expected = IllegalCommonizerStateException::class)
fun differentReturnTypes1() = doTestFailure(
mockValueParam("kotlin.String"),
mockValueParam("kotlin.String"),
mockValueParam("kotlin.Int")
mockValueParam("kotlin/String"),
mockValueParam("kotlin/String"),
mockValueParam("kotlin/Int")
)
@Test(expected = IllegalCommonizerStateException::class)
fun differentReturnTypes2() = doTestFailure(
mockValueParam("kotlin.String"),
mockValueParam("kotlin.String"),
mockValueParam("org.sample.Foo")
mockValueParam("kotlin/String"),
mockValueParam("kotlin/String"),
mockValueParam("org/sample/Foo")
)
@Test(expected = IllegalCommonizerStateException::class)
fun differentReturnTypes3() = doTestFailure(
mockValueParam("org.sample.Foo"),
mockValueParam("org.sample.Foo"),
mockValueParam("org.sample.Bar")
mockValueParam("org/sample/Foo"),
mockValueParam("org/sample/Foo"),
mockValueParam("org/sample/Bar")
)
@Test
fun allHaveVararg1() = doTestSuccess(
expected = mockValueParam("kotlin.String", hasVarargElementType = true),
mockValueParam("kotlin.String", hasVarargElementType = true),
mockValueParam("kotlin.String", hasVarargElementType = true),
mockValueParam("kotlin.String", hasVarargElementType = true)
expected = mockValueParam("kotlin/String", hasVarargElementType = true),
mockValueParam("kotlin/String", hasVarargElementType = true),
mockValueParam("kotlin/String", hasVarargElementType = true),
mockValueParam("kotlin/String", hasVarargElementType = true)
)
@Test
fun allHaveVararg2() = doTestSuccess(
expected = mockValueParam("org.sample.Foo", hasVarargElementType = true),
mockValueParam("org.sample.Foo", hasVarargElementType = true),
mockValueParam("org.sample.Foo", hasVarargElementType = true),
mockValueParam("org.sample.Foo", hasVarargElementType = true)
expected = mockValueParam("org/sample/Foo", hasVarargElementType = true),
mockValueParam("org/sample/Foo", hasVarargElementType = true),
mockValueParam("org/sample/Foo", hasVarargElementType = true),
mockValueParam("org/sample/Foo", hasVarargElementType = true)
)
@Test(expected = IllegalCommonizerStateException::class)
fun someDoesNotHaveVararg1() = doTestFailure(
mockValueParam("kotlin.String", hasVarargElementType = true),
mockValueParam("kotlin.String", hasVarargElementType = true),
mockValueParam("kotlin.String", hasVarargElementType = false)
mockValueParam("kotlin/String", hasVarargElementType = true),
mockValueParam("kotlin/String", hasVarargElementType = true),
mockValueParam("kotlin/String", hasVarargElementType = false)
)
@Test(expected = IllegalCommonizerStateException::class)
fun someDoesNotHaveVararg2() = doTestFailure(
mockValueParam("org.sample.Foo", hasVarargElementType = false),
mockValueParam("org.sample.Foo", hasVarargElementType = false),
mockValueParam("org.sample.Foo", hasVarargElementType = true)
mockValueParam("org/sample/Foo", hasVarargElementType = false),
mockValueParam("org/sample/Foo", hasVarargElementType = false),
mockValueParam("org/sample/Foo", hasVarargElementType = true)
)
@Test
fun allHaveCrossinline() = doTestSuccess(
expected = mockValueParam("kotlin.String", isCrossinline = true),
mockValueParam("kotlin.String", isCrossinline = true),
mockValueParam("kotlin.String", isCrossinline = true),
mockValueParam("kotlin.String", isCrossinline = true)
expected = mockValueParam("kotlin/String", isCrossinline = true),
mockValueParam("kotlin/String", isCrossinline = true),
mockValueParam("kotlin/String", isCrossinline = true),
mockValueParam("kotlin/String", isCrossinline = true)
)
@Test
fun someHaveCrossinline1() = doTestSuccess(
expected = mockValueParam("kotlin.String", isCrossinline = false),
mockValueParam("kotlin.String", isCrossinline = true),
mockValueParam("kotlin.String", isCrossinline = true),
mockValueParam("kotlin.String", isCrossinline = false)
expected = mockValueParam("kotlin/String", isCrossinline = false),
mockValueParam("kotlin/String", isCrossinline = true),
mockValueParam("kotlin/String", isCrossinline = true),
mockValueParam("kotlin/String", isCrossinline = false)
)
@Test
fun someHaveCrossinline2() = doTestSuccess(
expected = mockValueParam("kotlin.String", isCrossinline = false),
mockValueParam("kotlin.String", isCrossinline = false),
mockValueParam("kotlin.String", isCrossinline = true),
mockValueParam("kotlin.String", isCrossinline = true)
expected = mockValueParam("kotlin/String", isCrossinline = false),
mockValueParam("kotlin/String", isCrossinline = false),
mockValueParam("kotlin/String", isCrossinline = true),
mockValueParam("kotlin/String", isCrossinline = true)
)
@Test
fun allHaveNoinline() = doTestSuccess(
expected = mockValueParam("kotlin.String", isNoinline = true),
mockValueParam("kotlin.String", isNoinline = true),
mockValueParam("kotlin.String", isNoinline = true),
mockValueParam("kotlin.String", isNoinline = true)
expected = mockValueParam("kotlin/String", isNoinline = true),
mockValueParam("kotlin/String", isNoinline = true),
mockValueParam("kotlin/String", isNoinline = true),
mockValueParam("kotlin/String", isNoinline = true)
)
@Test
fun someHaveNoinline1() = doTestSuccess(
expected = mockValueParam("kotlin.String", isNoinline = false),
mockValueParam("kotlin.String", isNoinline = true),
mockValueParam("kotlin.String", isNoinline = true),
mockValueParam("kotlin.String", isNoinline = false)
expected = mockValueParam("kotlin/String", isNoinline = false),
mockValueParam("kotlin/String", isNoinline = true),
mockValueParam("kotlin/String", isNoinline = true),
mockValueParam("kotlin/String", isNoinline = false)
)
@Test
fun someHaveNoinline2() = doTestSuccess(
expected = mockValueParam("kotlin.String", isNoinline = false),
mockValueParam("kotlin.String", isNoinline = false),
mockValueParam("kotlin.String", isNoinline = true),
mockValueParam("kotlin.String", isNoinline = true)
expected = mockValueParam("kotlin/String", isNoinline = false),
mockValueParam("kotlin/String", isNoinline = false),
mockValueParam("kotlin/String", isNoinline = true),
mockValueParam("kotlin/String", isNoinline = true)
)
@Test(expected = IllegalCommonizerStateException::class)
fun anyDeclaresDefaultValue() = doTestFailure(
mockValueParam("kotlin.String", declaresDefaultValue = false),
mockValueParam("kotlin.String", declaresDefaultValue = false),
mockValueParam("kotlin.String", declaresDefaultValue = true)
mockValueParam("kotlin/String", declaresDefaultValue = false),
mockValueParam("kotlin/String", declaresDefaultValue = false),
mockValueParam("kotlin/String", declaresDefaultValue = true)
)
override fun createCommonizer() = ValueParameterCommonizer(MOCK_CLASSIFIERS)
@@ -148,14 +147,14 @@ class ValueParameterCommonizerTest : AbstractCommonizerTest<CirValueParameter, C
internal companion object {
fun mockValueParam(
returnTypeFqName: String,
returnTypeClassId: String,
name: String = "myParameter",
hasVarargElementType: Boolean = false,
isCrossinline: Boolean = false,
isNoinline: Boolean = false,
declaresDefaultValue: Boolean = false
): CirValueParameter {
val returnType = CirTypeFactory.create(mockClassType(returnTypeFqName))
val returnType = mockClassType(returnTypeClassId)
return CirTestValueParameter(
name = CirName.create(name),
@@ -23,38 +23,38 @@ class ValueParameterListCommonizerTest : AbstractCommonizerTest<List<CirValuePar
@Test
fun matchedParameters() = doTestSuccess(
expected = mockValueParams(
"a" to "kotlin.String",
"b" to "kotlin.Int",
"c" to "org.sample.Foo"
"a" to "kotlin/String",
"b" to "kotlin/Int",
"c" to "org/sample/Foo"
),
mockValueParams(
"a" to "kotlin.String",
"b" to "kotlin.Int",
"c" to "org.sample.Foo"
"a" to "kotlin/String",
"b" to "kotlin/Int",
"c" to "org/sample/Foo"
),
mockValueParams(
"a" to "kotlin.String",
"b" to "kotlin.Int",
"c" to "org.sample.Foo"
"a" to "kotlin/String",
"b" to "kotlin/Int",
"c" to "org/sample/Foo"
),
mockValueParams(
"a" to "kotlin.String",
"b" to "kotlin.Int",
"c" to "org.sample.Foo"
"a" to "kotlin/String",
"b" to "kotlin/Int",
"c" to "org/sample/Foo"
)
)
@Test(expected = IllegalCommonizerStateException::class)
fun mismatchedParameterListSize1() = doTestFailure(
mockValueParams(
"a" to "kotlin.String",
"b" to "kotlin.Int",
"c" to "org.sample.Foo"
"a" to "kotlin/String",
"b" to "kotlin/Int",
"c" to "org/sample/Foo"
),
mockValueParams(
"a" to "kotlin.String",
"b" to "kotlin.Int",
"c" to "org.sample.Foo"
"a" to "kotlin/String",
"b" to "kotlin/Int",
"c" to "org/sample/Foo"
),
emptyList()
)
@@ -62,91 +62,91 @@ class ValueParameterListCommonizerTest : AbstractCommonizerTest<List<CirValuePar
@Test(expected = IllegalCommonizerStateException::class)
fun mismatchedParameterListSize2() = doTestFailure(
mockValueParams(
"a" to "kotlin.String",
"b" to "kotlin.Int",
"c" to "org.sample.Foo"
"a" to "kotlin/String",
"b" to "kotlin/Int",
"c" to "org/sample/Foo"
),
mockValueParams(
"a" to "kotlin.String",
"b" to "kotlin.Int",
"c" to "org.sample.Foo"
"a" to "kotlin/String",
"b" to "kotlin/Int",
"c" to "org/sample/Foo"
),
mockValueParams(
"a" to "kotlin.String",
"b" to "kotlin.Int",
"c" to "org.sample.Foo"
"a" to "kotlin/String",
"b" to "kotlin/Int",
"c" to "org/sample/Foo"
),
mockValueParams(
"a" to "kotlin.String",
"b" to "kotlin.Int"
"a" to "kotlin/String",
"b" to "kotlin/Int"
)
)
@Test(expected = IllegalCommonizerStateException::class)
fun mismatchedParameterListSize3() = doTestFailure(
mockValueParams(
"a" to "kotlin.String",
"b" to "kotlin.Int",
"c" to "org.sample.Foo"
"a" to "kotlin/String",
"b" to "kotlin/Int",
"c" to "org/sample/Foo"
),
mockValueParams(
"a" to "kotlin.String",
"b" to "kotlin.Int",
"c" to "org.sample.Foo"
"a" to "kotlin/String",
"b" to "kotlin/Int",
"c" to "org/sample/Foo"
),
mockValueParams(
"a" to "kotlin.String",
"b" to "kotlin.Int",
"c" to "org.sample.Foo"
"a" to "kotlin/String",
"b" to "kotlin/Int",
"c" to "org/sample/Foo"
),
mockValueParams(
"a" to "kotlin.String",
"b" to "kotlin.Int",
"c" to "org.sample.Foo",
"d" to "org.sample.Bar"
"a" to "kotlin/String",
"b" to "kotlin/Int",
"c" to "org/sample/Foo",
"d" to "org/sample/Bar"
)
)
@Test // types match, names doesn't match, without rewriting names the commonizer chooses the names from the first list of parameters
fun mismatchedParameterNames() = doTestSuccess(
expected = mockValueParams(
"a" to "kotlin.String",
"b" to "kotlin.Int",
"c" to "org.sample.Foo"
"a" to "kotlin/String",
"b" to "kotlin/Int",
"c" to "org/sample/Foo"
),
mockValueParams(
"a" to "kotlin.String",
"b" to "kotlin.Int",
"c" to "org.sample.Foo"
"a" to "kotlin/String",
"b" to "kotlin/Int",
"c" to "org/sample/Foo"
),
mockValueParams(
"d" to "kotlin.String",
"e" to "kotlin.Int",
"f" to "org.sample.Foo"
"d" to "kotlin/String",
"e" to "kotlin/Int",
"f" to "org/sample/Foo"
),
mockValueParams(
"h" to "kotlin.String",
"i" to "kotlin.Int",
"j" to "org.sample.Foo"
"h" to "kotlin/String",
"i" to "kotlin/Int",
"j" to "org/sample/Foo"
)
)
@Test(expected = IllegalCommonizerStateException::class)
fun mismatchedParameterTypes() = doTestFailure(
mockValueParams(
"a" to "kotlin.String",
"b" to "kotlin.Int",
"c" to "org.sample.Foo"
"a" to "kotlin/String",
"b" to "kotlin/Int",
"c" to "org/sample/Foo"
),
mockValueParams(
"a" to "kotlin.String",
"b" to "kotlin.Int",
"c" to "org.sample.Foo"
"a" to "kotlin/String",
"b" to "kotlin/Int",
"c" to "org/sample/Foo"
),
mockValueParams(
"a" to "kotlin.Int",
"b" to "kotlin.String",
"c" to "org.sample.Bar"
"a" to "kotlin/Int",
"b" to "kotlin/String",
"c" to "org/sample/Bar"
)
)
@@ -169,10 +169,10 @@ class ValueParameterListCommonizerTest : AbstractCommonizerTest<List<CirValuePar
private companion object {
fun mockValueParams(vararg params: Pair<String, String>): List<CirValueParameter> {
check(params.isNotEmpty())
return params.map { (name, returnTypeFqName) ->
return params.map { (name, returnTypeClassId) ->
ValueParameterCommonizerTest.mockValueParam(
name = name,
returnTypeFqName = returnTypeFqName
returnTypeClassId = returnTypeClassId
)
}
}
@@ -9,119 +9,48 @@ import org.jetbrains.kotlin.backend.common.serialization.metadata.KlibMetadataMo
import org.jetbrains.kotlin.backend.common.serialization.metadata.KlibMetadataVersion
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.commonizer.*
import org.jetbrains.kotlin.descriptors.commonizer.ResultsConsumer.ModuleResult
import org.jetbrains.kotlin.descriptors.commonizer.ModulesProvider.ModuleInfo
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName
import org.jetbrains.kotlin.descriptors.commonizer.ResultsConsumer.ModuleResult
import org.jetbrains.kotlin.descriptors.commonizer.cir.*
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirClassFactory
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeFactory
import org.jetbrains.kotlin.descriptors.commonizer.konan.NativeSensitiveManifestData
import org.jetbrains.kotlin.descriptors.commonizer.konan.TargetedNativeManifestDataProvider
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.*
import org.jetbrains.kotlin.descriptors.impl.AbstractTypeAliasDescriptor
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl
import org.jetbrains.kotlin.library.KotlinLibraryVersioning
import org.jetbrains.kotlin.library.SerializedMetadata
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.parentOrNull
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.types.*
import java.io.File
import kotlin.random.Random
import org.jetbrains.kotlin.storage.getValue
// expected special name for module
internal fun mockEmptyModule(moduleName: String): ModuleDescriptor {
val module = KotlinTestUtils.createEmptyModule(moduleName)
module.initialize(PackageFragmentProvider.Empty)
module.setDependencies(module)
return module
}
internal fun mockClassType(
fqName: String,
nullable: Boolean = false
): KotlinType = LazyWrappedType(LockBasedStorageManager.NO_LOCKS) {
val classFqName = FqName(fqName)
val classDescriptor = ClassDescriptorImpl(
/* containingDeclaration = */ createPackageFragmentForClassifier(classFqName),
/* name = */ classFqName.shortName(),
/* modality = */ Modality.FINAL,
/* classKind = */ ClassKind.CLASS,
/* supertypes = */ emptyList(),
/* source = */ SourceElement.NO_SOURCE,
/* isExternal = */ false,
/* storageManager = */ LockBasedStorageManager.NO_LOCKS
)
classDescriptor.initialize(
/* unsubstitutedMemberScope = */ MemberScope.Empty,
/* constructors = */ emptySet(),
/* primaryConstructor = */ null
)
classDescriptor.defaultType.makeNullableAsSpecified(nullable)
}
internal fun mockTAType(
fqName: String,
typeAliasId: String,
nullable: Boolean = false,
rightHandSideTypeProvider: () -> KotlinType
): KotlinType = LazyWrappedType(LockBasedStorageManager.NO_LOCKS) {
val typeAliasFqName = FqName(fqName)
underlyingType: () -> CirClassOrTypeAliasType
): CirTypeAliasType = CirTypeFactory.createTypeAliasType(
typeAliasId = createValidClassifierId(typeAliasId),
underlyingType = CirTypeFactory.makeNullableIfNecessary(underlyingType(), nullable),
arguments = emptyList(),
isMarkedNullable = nullable
)
val rightHandSideType = rightHandSideTypeProvider().lowerIfFlexible()
internal fun mockClassType(
classId: String,
nullable: Boolean = false
): CirClassType = CirTypeFactory.createClassType(
classId = createValidClassifierId(classId),
outerType = null,
visibility = DescriptorVisibilities.PUBLIC,
arguments = emptyList(),
isMarkedNullable = nullable
)
val typeAliasDescriptor = object : AbstractTypeAliasDescriptor(
containingDeclaration = createPackageFragmentForClassifier(typeAliasFqName),
annotations = Annotations.EMPTY,
name = typeAliasFqName.shortName(),
sourceElement = SourceElement.NO_SOURCE,
visibilityImpl = DescriptorVisibilities.PUBLIC
) {
override val storageManager get() = LockBasedStorageManager.NO_LOCKS
private val defaultTypeImpl = storageManager.createLazyValue { computeDefaultType() }
override fun getDefaultType() = defaultTypeImpl()
override val underlyingType by storageManager.createLazyValue { rightHandSideType.getAbbreviation() ?: rightHandSideType }
override val expandedType by storageManager.createLazyValue { rightHandSideType }
override val classDescriptor get() = expandedType.constructor.declarationDescriptor as? ClassDescriptor
override val constructors by storageManager.createLazyValue { getTypeAliasConstructors() }
private val typeConstructorTypeParametersImpl by storageManager.createLazyValue { computeConstructorTypeParameters() }
override fun getTypeConstructorTypeParameters() = typeConstructorTypeParametersImpl
override fun substitute(substitutor: TypeSubstitutor) = error("Unsupported")
}
typeAliasDescriptor.initialize(declaredTypeParameters = emptyList())
(rightHandSideType.getAbbreviatedType()?.expandedType ?: rightHandSideType)
.withAbbreviation(typeAliasDescriptor.defaultType)
.makeNullableAsSpecified(nullable)
private fun createValidClassifierId(classifierId: String): CirEntityId {
check(classifierId.none { it == '.' || it == '\\' || it == '?' }) { "Malformed classifier ID: $classifierId" }
return CirEntityId.create(classifierId)
}
private fun createPackageFragmentForClassifier(classifierFqName: FqName): PackageFragmentDescriptor =
object : PackageFragmentDescriptor {
private val module: ModuleDescriptor by lazy { mockEmptyModule("<module4_${classifierFqName.shortName()}_x${Random.nextInt()}>") }
override fun getContainingDeclaration(): ModuleDescriptor = module
override val fqName = classifierFqName.parentOrNull() ?: FqName.ROOT
override fun getMemberScope() = MemberScope.Empty
override fun getOriginal() = this
override fun getName() = fqName.shortNameOrSpecial()
override fun getSource() = SourceElement.NO_SOURCE
override val annotations = Annotations.EMPTY
override fun <R : Any?, D : Any?> accept(visitor: DeclarationDescriptorVisitor<R, D>?, data: D): R = error("not supported")
override fun acceptVoid(visitor: DeclarationDescriptorVisitor<Void, Void>?) = error("not supported")
override fun toString() = "package $name"
}
internal val MOCK_CLASSIFIERS = CirKnownClassifiers(
commonizedNodes = object : CirCommonizedClassifierNodes {
private val MOCK_CLASS_NODE = CirClassNode(
@@ -173,7 +102,13 @@ internal class MockModulesProvider private constructor(
companion object {
@JvmName("createByModuleNames")
fun create(moduleNames: List<String>) = MockModulesProvider(
moduleNames.associateWith { name -> mockEmptyModule("<$name>") }
moduleNames.associateWith { name ->
// expected special name for module
val module = KotlinTestUtils.createEmptyModule("<$name>")
module.initialize(PackageFragmentProvider.Empty)
module.setDependencies(module)
module
}
)
@JvmName("createByModules")