[Commonizer] Fix AbstractListCommonizer and adapt ValueParameterListCommonizerTest
^KT-48288
This commit is contained in:
committed by
Space
parent
cdd917bd0b
commit
4e6ad03df6
+4
-4
@@ -15,14 +15,14 @@ import org.jetbrains.kotlin.commonizer.cir.CirType
|
||||
* Input: N lists of [CirType]
|
||||
* Output: list of [CirType]
|
||||
*/
|
||||
abstract class AbstractListCommonizer<T, R: Any>(
|
||||
abstract class AbstractListCommonizer<T, R : Any>(
|
||||
private val singleElementCommonizerFactory: (Int) -> Commonizer<T, R?>
|
||||
) : Commonizer<List<T>, List<R>> {
|
||||
) : Commonizer<List<T>, List<R>?> {
|
||||
private var commonizers: Array<Commonizer<T, R?>>? = null
|
||||
private var error = false
|
||||
|
||||
final override val result: List<R>
|
||||
get() = checkState(commonizers, error).mapNotNull { it.result }
|
||||
final override val result: List<R>?
|
||||
get() = checkState(commonizers, error).map { it.result ?: return null }
|
||||
|
||||
final override fun commonizeWith(next: List<T>): Boolean {
|
||||
if (error)
|
||||
|
||||
+3
-3
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.commonizer.utils.isObjCInteropCallableAnnotation
|
||||
|
||||
class CallableValueParametersCommonizer(
|
||||
typeCommonizer: TypeCommonizer,
|
||||
) : Commonizer<CirCallableMemberWithParameters, CallableValueParametersCommonizer.Result> {
|
||||
) : Commonizer<CirCallableMemberWithParameters, CallableValueParametersCommonizer.Result?> {
|
||||
class Result(
|
||||
val hasStableParameterNames: Boolean,
|
||||
val valueParameters: List<CirValueParameter>,
|
||||
@@ -121,7 +121,7 @@ class CallableValueParametersCommonizer(
|
||||
private var valueParameterNames: ValueParameterNames? = null
|
||||
private var error = false
|
||||
|
||||
override val result: Result
|
||||
override val result: Result?
|
||||
get() {
|
||||
// don't inline `patchCallables` property;
|
||||
// valueParameters.overwriteNames() should be called strongly before valueParameters.result
|
||||
@@ -141,7 +141,7 @@ class CallableValueParametersCommonizer(
|
||||
|
||||
return Result(
|
||||
hasStableParameterNames = hasStableParameterNames,
|
||||
valueParameters = valueParameters.result,
|
||||
valueParameters = valueParameters.result ?: return null,
|
||||
patchCallables = patchCallables
|
||||
)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
class ClassCommonizer internal constructor(
|
||||
typeCommonizer: TypeCommonizer,
|
||||
supertypesCommonizer: ClassSuperTypeCommonizer
|
||||
) : AbstractStandardCommonizer<CirClass, CirClass>() {
|
||||
) : AbstractStandardCommonizer<CirClass, CirClass?>() {
|
||||
private lateinit var name: CirName
|
||||
private lateinit var kind: ClassKind
|
||||
private var isInner = false
|
||||
@@ -23,21 +23,23 @@ class ClassCommonizer internal constructor(
|
||||
private val modalityCommonizer: ModalityCommonizer = ModalityCommonizer()
|
||||
private val visibilityCommonizer: VisibilityCommonizer = VisibilityCommonizer.equalizing()
|
||||
|
||||
override fun commonizationResult() = CirClass.create(
|
||||
annotations = emptyList(),
|
||||
name = name,
|
||||
typeParameters = typeParameterListCommonizer.result,
|
||||
supertypes = supertypesCommonizer.result,
|
||||
visibility = visibilityCommonizer.result,
|
||||
modality = modalityCommonizer.result,
|
||||
kind = kind,
|
||||
companion = null,
|
||||
isCompanion = isCompanion,
|
||||
isData = false,
|
||||
isValue = isValue,
|
||||
isInner = isInner,
|
||||
isExternal = false
|
||||
)
|
||||
override fun commonizationResult(): CirClass? {
|
||||
return CirClass.create(
|
||||
annotations = emptyList(),
|
||||
name = name,
|
||||
typeParameters = typeParameterListCommonizer.result ?: return null,
|
||||
supertypes = supertypesCommonizer.result,
|
||||
visibility = visibilityCommonizer.result,
|
||||
modality = modalityCommonizer.result,
|
||||
kind = kind,
|
||||
companion = null,
|
||||
isCompanion = isCompanion,
|
||||
isData = false,
|
||||
isValue = isValue,
|
||||
isInner = isInner,
|
||||
isExternal = false
|
||||
)
|
||||
}
|
||||
|
||||
override fun initialize(first: CirClass) {
|
||||
name = first.name
|
||||
|
||||
+4
-4
@@ -12,20 +12,20 @@ import org.jetbrains.kotlin.descriptors.Modality
|
||||
|
||||
class ClassConstructorCommonizer(
|
||||
typeCommonizer: TypeCommonizer,
|
||||
) : AbstractStandardCommonizer<CirClassConstructor, CirClassConstructor>() {
|
||||
) : AbstractStandardCommonizer<CirClassConstructor, CirClassConstructor?>() {
|
||||
private var isPrimary = false
|
||||
private val visibility = VisibilityCommonizer.equalizing()
|
||||
private val typeParameterListCommonizer = TypeParameterListCommonizer(typeCommonizer)
|
||||
private val valueParametersCommonizer = CallableValueParametersCommonizer(typeCommonizer)
|
||||
private val annotationsCommonizer: AnnotationsCommonizer = AnnotationsCommonizer()
|
||||
|
||||
override fun commonizationResult(): CirClassConstructor {
|
||||
val valueParameters = valueParametersCommonizer.result
|
||||
override fun commonizationResult(): CirClassConstructor? {
|
||||
val valueParameters = valueParametersCommonizer.result ?: return null
|
||||
valueParameters.patchCallables()
|
||||
|
||||
return CirClassConstructor.create(
|
||||
annotations = annotationsCommonizer.result,
|
||||
typeParameters = typeParameterListCommonizer.result,
|
||||
typeParameters = typeParameterListCommonizer.result ?: return null,
|
||||
visibility = visibility.result,
|
||||
containingClass = CONTAINING_CLASS_DOES_NOT_MATTER, // does not matter
|
||||
valueParameters = valueParameters.valueParameters,
|
||||
|
||||
+10
-8
@@ -10,19 +10,21 @@ import org.jetbrains.kotlin.commonizer.cir.CirType
|
||||
import org.jetbrains.kotlin.commonizer.cir.CirTypeParameter
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
class TypeParameterCommonizer(typeCommonizer: TypeCommonizer) : AbstractStandardCommonizer<CirTypeParameter, CirTypeParameter>() {
|
||||
class TypeParameterCommonizer(typeCommonizer: TypeCommonizer) : AbstractStandardCommonizer<CirTypeParameter, CirTypeParameter?>() {
|
||||
private lateinit var name: CirName
|
||||
private var isReified = false
|
||||
private lateinit var variance: Variance
|
||||
private val upperBounds = TypeParameterUpperBoundsCommonizer(typeCommonizer)
|
||||
|
||||
override fun commonizationResult() = CirTypeParameter(
|
||||
annotations = emptyList(),
|
||||
name = name,
|
||||
isReified = isReified,
|
||||
variance = variance,
|
||||
upperBounds = upperBounds.result
|
||||
)
|
||||
override fun commonizationResult(): CirTypeParameter? {
|
||||
return CirTypeParameter(
|
||||
annotations = emptyList(),
|
||||
name = name,
|
||||
isReified = isReified,
|
||||
variance = variance,
|
||||
upperBounds = upperBounds.result ?: return null
|
||||
)
|
||||
}
|
||||
|
||||
override fun initialize(first: CirTypeParameter) {
|
||||
name = first.name
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.commonizer.utils.mockClassType
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.junit.Test
|
||||
|
||||
class TypeParameterCommonizerTest : AbstractCommonizerTest<CirTypeParameter, CirTypeParameter>() {
|
||||
class TypeParameterCommonizerTest : AbstractCommonizerTest<CirTypeParameter, CirTypeParameter?>() {
|
||||
override fun createCommonizer() = TypeParameterCommonizer(TypeCommonizer(MOCK_CLASSIFIERS))
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.commonizer.cir.CirTypeParameter
|
||||
import org.jetbrains.kotlin.commonizer.utils.MOCK_CLASSIFIERS
|
||||
import org.junit.Test
|
||||
|
||||
class TypeParameterListCommonizerTest : AbstractCommonizerTest<List<CirTypeParameter>, List<CirTypeParameter>>() {
|
||||
class TypeParameterListCommonizerTest : AbstractCommonizerTest<List<CirTypeParameter>, List<CirTypeParameter>?>() {
|
||||
|
||||
@Test
|
||||
fun emptyValueParameters() = doTestSuccess(
|
||||
|
||||
+25
-18
@@ -8,8 +8,9 @@ package org.jetbrains.kotlin.commonizer.core
|
||||
import org.jetbrains.kotlin.commonizer.cir.CirValueParameter
|
||||
import org.jetbrains.kotlin.commonizer.utils.MOCK_CLASSIFIERS
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class ValueParameterListCommonizerTest : AbstractCommonizerTest<List<CirValueParameter>, List<CirValueParameter>>() {
|
||||
class ValueParameterListCommonizerTest : AbstractCommonizerTest<List<CirValueParameter>, List<CirValueParameter>?>() {
|
||||
|
||||
@Test
|
||||
fun emptyValueParameters() = doTestSuccess(
|
||||
@@ -130,24 +131,30 @@ class ValueParameterListCommonizerTest : AbstractCommonizerTest<List<CirValuePar
|
||||
)
|
||||
)
|
||||
|
||||
@Test(expected = IllegalCommonizerStateException::class)
|
||||
fun mismatchedParameterTypes() = doTestFailure(
|
||||
mockValueParams(
|
||||
"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"
|
||||
),
|
||||
mockValueParams(
|
||||
"a" to "kotlin/Int",
|
||||
"b" to "kotlin/String",
|
||||
"c" to "org/sample/Bar"
|
||||
@Test
|
||||
fun mismatchedParameterTypes() {
|
||||
assertEquals(
|
||||
null, createCommonizer().commonize(
|
||||
listOf(
|
||||
mockValueParams(
|
||||
"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"
|
||||
),
|
||||
mockValueParams(
|
||||
"a" to "kotlin/Int",
|
||||
"b" to "kotlin/String",
|
||||
"c" to "org/sample/Bar"
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun createCommonizer() = ValueParameterListCommonizer(TypeCommonizer(MOCK_CLASSIFIERS))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user