[Commonizer] Internal improvements, p.2

This commit is contained in:
Dmitriy Dolovov
2019-09-08 16:28:00 +07:00
parent 81eef5152e
commit e6b17e4bb5
27 changed files with 110 additions and 118 deletions
@@ -16,7 +16,7 @@ abstract class AbstractCallableMemberCommonizer<T : CallableMemberDescriptor, R:
IN_PROGRESS
}
protected var name: Name? = null
protected lateinit var name: Name
protected val modality = ModalityCommonizer.default()
// TODO: visibility - what if virtual declaration?
protected val visibility = VisibilityCommonizer.lowering()
@@ -30,7 +30,7 @@ abstract class AbstractCallableMemberCommonizer<T : CallableMemberDescriptor, R:
if (state == State.ERROR)
return false
if (name == null)
if (state == State.EMPTY)
name = next.name
val result = canBeCommonized(next)
@@ -6,14 +6,13 @@
package org.jetbrains.kotlin.descriptors.commonizer.core
abstract class AbstractListCommonizer<T, R>(
private val subject: String,
private val singleElementCommonizerFactory: () -> Commonizer<T, R>
) : Commonizer<List<T>, List<R>> {
private var commonizers: List<Commonizer<T, R>>? = null
private var error = false
final override val result: List<R>
get() = commonizers?.takeIf { !error }?.map { it.result } ?: error("Can't commonize list of $subject")
get() = commonizers?.takeIf { !error }?.map { it.result } ?: throw IllegalCommonizerStateException()
final override fun commonizeWith(next: List<T>): Boolean {
if (error)
@@ -9,14 +9,13 @@ import org.jetbrains.kotlin.descriptors.Named
import org.jetbrains.kotlin.name.Name
abstract class AbstractNamedListCommonizer<T : Named, R>(
private val subject: String,
private val singleElementCommonizerFactory: () -> Commonizer<T, R>
) : Commonizer<List<T>, List<R>> {
private var commonizers: List<Pair<Name, Commonizer<T, R>>>? = null
private var error = false
final override val result: List<R>
get() = commonizers?.takeIf { !error }?.map { it.second.result } ?: error("Can't commonize list of $subject")
get() = commonizers?.takeIf { !error }?.map { it.second.result } ?: throw IllegalCommonizerStateException()
final override fun commonizeWith(next: List<T>): Boolean {
if (error)
@@ -6,7 +6,6 @@
package org.jetbrains.kotlin.descriptors.commonizer.core
abstract class AbstractNullableCommonizer<T : Any, R : Any, WT, WR>(
private val subject: String,
private val wrappedCommonizerFactory: () -> Commonizer<WT, WR>,
private val extractor: (T) -> WT,
private val builder: (WR) -> R
@@ -19,12 +18,12 @@ abstract class AbstractNullableCommonizer<T : Any, R : Any, WT, WR>(
}
private var state = State.EMPTY
private var wrapped: Commonizer<WT, WR>? = null
private lateinit var wrapped: Commonizer<WT, WR>
final override val result: R?
get() = when (state) {
State.EMPTY, State.ERROR -> error("$subject setter can't be commonized")
State.WITH_WRAPPED -> builder(wrapped!!.result)
State.EMPTY, State.ERROR -> throw IllegalCommonizerStateException()
State.WITH_WRAPPED -> builder(wrapped.result)
State.WITHOUT_WRAPPED -> null // null means there is no commonized result
}
@@ -43,5 +42,5 @@ abstract class AbstractNullableCommonizer<T : Any, R : Any, WT, WR>(
}
private fun doCommonizeWith(next: T) =
if (wrapped!!.commonizeWith(extractor(next))) State.WITH_WRAPPED else State.ERROR
if (wrapped.commonizeWith(extractor(next))) State.WITH_WRAPPED else State.ERROR
}
@@ -9,3 +9,5 @@ interface Commonizer<T, R> {
val result: R
fun commonizeWith(next: T): Boolean
}
class IllegalCommonizerStateException : IllegalStateException("Illegal commonizer state: error or empty")
@@ -23,12 +23,12 @@ private class DefaultExtensionReceiverCommonizer : ExtensionReceiverCommonizer {
}
private var state = State.EMPTY
private var receiverType: TypeCommonizer? = null
private lateinit var receiverType: TypeCommonizer
override val result: UnwrappedType?
get() = when (state) {
State.EMPTY, State.ERROR -> error("Receiver parameter type can't be commonized")
State.WITH_RECEIVER -> receiverType!!.result
State.EMPTY, State.ERROR -> throw IllegalCommonizerStateException()
State.WITH_RECEIVER -> receiverType.result
State.WITHOUT_RECEIVER -> null // null receiverType means there is no extension receiver
}
@@ -47,5 +47,5 @@ private class DefaultExtensionReceiverCommonizer : ExtensionReceiverCommonizer {
}
private fun doCommonizeWith(receiverParameter: ReceiverParameterDescriptor) =
if (receiverType!!.commonizeWith(receiverParameter.type)) State.WITH_RECEIVER else State.ERROR
if (receiverType.commonizeWith(receiverParameter.type)) State.WITH_RECEIVER else State.ERROR
}
@@ -16,9 +16,9 @@ class FunctionCommonizer : AbstractCallableMemberCommonizer<SimpleFunctionDescri
override val result: Function
get() = when (state) {
State.EMPTY, State.ERROR -> error("Can't commonize function")
State.EMPTY, State.ERROR -> throw IllegalCommonizerStateException()
State.IN_PROGRESS -> CommonFunction(
name = name!!,
name = name,
modality = modality.result,
visibility = visibility.result,
extensionReceiver = extensionReceiver.result?.toReceiverNoAnnotations(),
@@ -19,7 +19,7 @@ private class DefaultFunctionModifiersCommonizer : FunctionModifiersCommonizer {
private var error = false
override val result: FunctionModifiers
get() = modifiers?.takeIf { !error } ?: error("Function modifiers setter can't be commonized")
get() = modifiers?.takeIf { !error } ?: throw IllegalCommonizerStateException()
override fun commonizeWith(next: SimpleFunctionDescriptor): Boolean {
if (error)
@@ -64,7 +64,7 @@ private class DefaultModalityCommonizer : ModalityCommonizer {
State.CAN_HAVE_ONLY_ABSTRACT -> Modality.ABSTRACT
State.HAS_FINAL, State.HAS_FINAL_AND_OPEN -> Modality.FINAL
State.HAS_OPEN -> Modality.OPEN
else -> error("Modality can't be commonized")
else -> throw IllegalCommonizerStateException()
}
override fun commonizeWith(next: Modality): Boolean {
@@ -16,9 +16,9 @@ class PropertyCommonizer : AbstractCallableMemberCommonizer<PropertyDescriptor,
override val result: Property
get() = when (state) {
State.EMPTY, State.ERROR -> error("Can't commonize property")
State.EMPTY, State.ERROR -> throw IllegalCommonizerStateException()
State.IN_PROGRESS -> CommonProperty(
name = name!!,
name = name,
modality = modality.result,
visibility = visibility.result,
isExternal = isExternal,
@@ -18,7 +18,6 @@ interface PropertySetterCommonizer : Commonizer<PropertySetterDescriptor?, Sette
private class DefaultPropertySetterCommonizer :
PropertySetterCommonizer,
AbstractNullableCommonizer<PropertySetterDescriptor, Setter, Visibility, Visibility>(
subject = "Property",
wrappedCommonizerFactory = { VisibilityCommonizer.equalizing() },
extractor = { it.visibility },
builder = { Setter.createDefaultNoAnnotations(it) }
@@ -28,12 +28,12 @@ private class DefaultTypeCommonizer : TypeCommonizer {
}
private var state = State.EMPTY
private var temp: UnwrappedType? = null
private lateinit var temp: UnwrappedType
override val result: UnwrappedType
get() = when (state) {
State.EMPTY, State.ERROR -> error("Can't commonize type")
State.IN_PROGRESS -> temp!!
State.EMPTY, State.ERROR -> throw IllegalCommonizerStateException()
State.IN_PROGRESS -> temp
}
override fun commonizeWith(next: KotlinType): Boolean {
@@ -45,7 +45,7 @@ private class DefaultTypeCommonizer : TypeCommonizer {
}
// TODO: maybe cache type comparison results?
State.IN_PROGRESS -> {
if (!areTypesEqual(temp!!, next.unwrap())) State.ERROR else State.IN_PROGRESS
if (!areTypesEqual(temp, next.unwrap())) State.ERROR else State.IN_PROGRESS
}
}
@@ -89,11 +89,10 @@ private fun areAbbreviatedTypesEqual(a: SimpleType, aExpanded: SimpleType, b: Si
// N.B. only for descriptors that represent classes or type aliases, but not type parameters:
val aFqName = aDescriptor.fqNameSafe
val bFqName = bDescriptor.fqNameSafe
aFqName.isUnderStandardKotlinPackages
// make sure that FQ names of abbreviated types (e.g. representing type aliases) are equal
&& aFqName == bFqName
&& aFqName == bDescriptor.fqNameSafe
// if classes are from the standard Kotlin packages, compare them only by type constructors
// effectively, this includes 1) comparison of FQ names and 2) number of type constructor parameters
// see org.jetbrains.kotlin.types.AbstractClassTypeConstructor.equals() for details
@@ -110,9 +109,7 @@ private fun areAbbreviatedTypesEqual(a: SimpleType, aExpanded: SimpleType, b: Si
if (!descriptorsCanBeCommonized)
return false
if (a.arguments.size != b.arguments.size)
return false
// N.B. both lists of arguments are already known to be of the same size
for (i in 0 until a.arguments.size) {
val aArg = a.arguments[i]
val bArg = b.arguments[i]
@@ -170,7 +167,7 @@ private fun canBeCommonized(a: TypeAliasDescriptor, b: TypeAliasDescriptor): Boo
}
private fun canBeCommonized(a: TypeParameterDescriptor, b: TypeParameterDescriptor): Boolean {
// N.B. real type parameter commonization is performed in TypeParameterCommonizer,
// real type parameter commonization is performed in TypeParameterCommonizer,
// here it is enough to check FQ names
return areFqNamesEqual(a, b)
}
@@ -34,7 +34,7 @@ private class DefaultTypeParameterCommonizer : TypeParameterCommonizer {
override val result: TypeParameter
get() = when (state) {
State.EMPTY, State.ERROR -> error("Can't commonize type parameter")
State.EMPTY, State.ERROR -> throw IllegalCommonizerStateException()
State.IN_PROGRESS -> CommonTypeParameter(
name = name,
isReified = isReified,
@@ -66,7 +66,6 @@ private class DefaultTypeParameterCommonizer : TypeParameterCommonizer {
}
private class TypeParameterUpperBoundsCommonizer : AbstractListCommonizer<KotlinType, UnwrappedType>(
subject = "type parameter upper bounds",
singleElementCommonizerFactory = { TypeCommonizer.default() }
)
@@ -79,6 +78,5 @@ interface TypeParameterListCommonizer : Commonizer<List<TypeParameterDescriptor>
private class DefaultTypeParameterListCommonizer :
TypeParameterListCommonizer,
AbstractNamedListCommonizer<TypeParameterDescriptor, TypeParameter>(
subject = "type parameters",
singleElementCommonizerFactory = { TypeParameterCommonizer.default() }
)
@@ -25,7 +25,7 @@ private class DefaultValueParameterCommonizer : ValueParameterCommonizer {
IN_PROGRESS
}
private var name: Name? = null
private lateinit var name: Name
private val returnType = TypeCommonizer.default()
private var varargElementType: UnwrappedType? = null
private var isCrossinline = true
@@ -35,9 +35,9 @@ private class DefaultValueParameterCommonizer : ValueParameterCommonizer {
override val result: ValueParameter
get() = when (state) {
State.EMPTY, State.ERROR -> error("Can't commonize value parameter")
State.EMPTY, State.ERROR -> throw IllegalCommonizerStateException()
State.IN_PROGRESS -> CommonValueParameter(
name = name!!,
name = name,
returnType = returnType.result,
varargElementType = varargElementType,
isCrossinline = isCrossinline,
@@ -83,6 +83,5 @@ interface ValueParameterListCommonizer : Commonizer<List<ValueParameterDescripto
private class DefaultValueParameterListCommonizer :
ValueParameterListCommonizer,
AbstractNamedListCommonizer<ValueParameterDescriptor, ValueParameter>(
subject = "value parameters",
singleElementCommonizerFactory = { ValueParameterCommonizer.default() }
)
@@ -19,7 +19,7 @@ abstract class VisibilityCommonizer : Commonizer<Visibility, Visibility> {
override val result: Visibility
get() {
return temp?.takeIf { it != Visibilities.UNKNOWN } ?: error("Visibility can't be commonized")
return temp?.takeIf { it != Visibilities.UNKNOWN } ?: throw IllegalCommonizerStateException()
}
override fun commonizeWith(next: Visibility): Boolean {
@@ -10,7 +10,7 @@ import org.junit.Test
abstract class AbstractCommonizerTest<T, R> {
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun failOnNoVariantsSubmitted() {
createCommonizer().result
fail()
@@ -31,21 +31,21 @@ class DefaultExtensionReceiverCommonizerTest : AbstractCommonizerTest<ReceiverPa
mock(receiverTypeFqName = "kotlin.String").extensionReceiverParameter
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun differentReceivers() = doTestFailure(
mock(receiverTypeFqName = "kotlin.String").extensionReceiverParameter,
mock(receiverTypeFqName = "kotlin.String").extensionReceiverParameter,
mock(receiverTypeFqName = "kotlin.Int").extensionReceiverParameter
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun nullAndNonNullReceivers1() = doTestFailure(
mock(receiverTypeFqName = "kotlin.String").extensionReceiverParameter,
mock(receiverTypeFqName = "kotlin.String").extensionReceiverParameter,
mock(receiverTypeFqName = null).extensionReceiverParameter
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun nullAndNonNullReceivers2() = doTestFailure(
mock(receiverTypeFqName = null).extensionReceiverParameter,
mock(receiverTypeFqName = null).extensionReceiverParameter,
@@ -33,14 +33,14 @@ class DefaultFunctionModifiersCommonizerTest : AbstractCommonizerTest<SimpleFunc
create(isSuspend = true).toMockFunction()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun suspendAndNotSuspend() = doTestFailure(
create(isSuspend = true).toMockFunction(),
create(isSuspend = true).toMockFunction(),
create().toMockFunction()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun notSuspendAndSuspend() = doTestFailure(
create().toMockFunction(),
create().toMockFunction(),
@@ -23,13 +23,13 @@ class DefaultModalityCommonizerTest : AbstractCommonizerTest<Modality, Modality>
@Test
fun onlyAbstract() = doTestSuccess(ABSTRACT, ABSTRACT, ABSTRACT, ABSTRACT)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun sealedAndAbstract() = doTestFailure(SEALED, ABSTRACT)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun sealedAndFinal() = doTestFailure(SEALED, FINAL)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun abstractAndFinal() = doTestFailure(ABSTRACT, FINAL)
@Test
@@ -19,16 +19,16 @@ class DefaultPropertySetterCommonizerTest : AbstractCommonizerTest<PropertySette
@Test
fun absentOnly() = super.doTestSuccess(null, null, null, null)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun absentAndPublic() = doTestFailure(null, null, null, PUBLIC)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun publicAndAbsent() = doTestFailure(PUBLIC, PUBLIC, PUBLIC, null)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun protectedAndAbsent() = doTestFailure(PROTECTED, PROTECTED, null)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun absentAndInternal() = doTestFailure(null, null, INTERNAL)
@Test
@@ -40,22 +40,22 @@ class DefaultPropertySetterCommonizerTest : AbstractCommonizerTest<PropertySette
@Test
fun internalOnly() = doTestSuccess(INTERNAL, INTERNAL, INTERNAL, INTERNAL)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun privateOnly() = doTestFailure(PRIVATE)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun publicAndProtected() = doTestFailure(PUBLIC, PUBLIC, PROTECTED)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun publicAndInternal() = doTestFailure(PUBLIC, PUBLIC, INTERNAL)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun protectedAndInternal() = doTestFailure(PROTECTED, PROTECTED, INTERNAL)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun publicAndPrivate() = doTestFailure(PUBLIC, PUBLIC, PRIVATE)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun somethingUnexpected() = doTestFailure(PUBLIC, LOCAL)
private fun doTestSuccess(expected: Visibility?, vararg variants: Visibility?) =
@@ -24,21 +24,21 @@ class DefaultTypeCommonizerTest : AbstractCommonizerTest<KotlinType, UnwrappedTy
mockClassType("kotlin.collections.List")
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInKotlinPackageWithDifferentNames1() = doTestFailure(
mockClassType("kotlin.collections.List"),
mockClassType("kotlin.collections.List"),
mockClassType("kotlin.fictitiousPackageName.List")
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInKotlinPackageWithDifferentNames2() = doTestFailure(
mockClassType("kotlin.collections.List"),
mockClassType("kotlin.collections.List"),
mockClassType("kotlin.collections.Set")
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInKotlinPackageWithDifferentNames3() = doTestFailure(
mockClassType("kotlin.collections.List"),
mockClassType("kotlin.collections.List"),
@@ -53,21 +53,21 @@ class DefaultTypeCommonizerTest : AbstractCommonizerTest<KotlinType, UnwrappedTy
mockClassType("kotlinx.cinterop.CPointer")
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInKotlinxPackageWithDifferentNames1() = doTestFailure(
mockClassType("kotlinx.cinterop.CPointer"),
mockClassType("kotlinx.cinterop.CPointer"),
mockClassType("kotlinx.fictitiousPackageName.CPointer")
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInKotlinxPackageWithDifferentNames2() = doTestFailure(
mockClassType("kotlinx.cinterop.CPointer"),
mockClassType("kotlinx.cinterop.CPointer"),
mockClassType("kotlinx.cinterop.ObjCObject")
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInKotlinxPackageWithDifferentNames3() = doTestFailure(
mockClassType("kotlinx.cinterop.CPointer"),
mockClassType("kotlinx.cinterop.CPointer"),
@@ -82,21 +82,21 @@ class DefaultTypeCommonizerTest : AbstractCommonizerTest<KotlinType, UnwrappedTy
mockClassType("org.sample.Foo")
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInUserPackageWithDifferentNames1() = doTestFailure(
mockClassType("org.sample.Foo"),
mockClassType("org.sample.Foo"),
mockClassType("org.fictitiousPackageName.Foo")
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInUserPackageWithDifferentNames2() = doTestFailure(
mockClassType("org.sample.Foo"),
mockClassType("org.sample.Foo"),
mockClassType("org.sample.Bar")
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInUserPackageWithDifferentNames3() = doTestFailure(
mockClassType("org.sample.Foo"),
mockClassType("org.sample.Foo"),
@@ -119,14 +119,14 @@ class DefaultTypeCommonizerTest : AbstractCommonizerTest<KotlinType, UnwrappedTy
mockClassType("kotlin.collections.List", nullable = true)
)
@Test(expected = IllegalStateException::class)
@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)
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInKotlinPackageWithDifferentNullability2() = doTestFailure(
mockClassType("kotlin.collections.List", nullable = true),
mockClassType("kotlin.collections.List", nullable = true),
@@ -149,14 +149,14 @@ class DefaultTypeCommonizerTest : AbstractCommonizerTest<KotlinType, UnwrappedTy
mockClassType("org.sample.Foo", nullable = true)
)
@Test(expected = IllegalStateException::class)
@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)
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun classTypesInUserPackageWithDifferentNullability2() = doTestFailure(
mockClassType("org.sample.Foo", nullable = true),
mockClassType("org.sample.Foo", nullable = true),
@@ -171,14 +171,14 @@ class DefaultTypeCommonizerTest : AbstractCommonizerTest<KotlinType, UnwrappedTy
mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.SequenceScope") }
)
@Test(expected = IllegalStateException::class)
@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") }
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun taTypesInKotlinPackageWithDifferentClasses() = doTestFailure(
mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.SequenceScope") },
mockTAType("kotlin.sequences.SequenceBuilder") { mockClassType("kotlin.sequences.SequenceScope") },
@@ -193,14 +193,14 @@ class DefaultTypeCommonizerTest : AbstractCommonizerTest<KotlinType, UnwrappedTy
mockTAType("kotlinx.cinterop.CArrayPointer") { mockClassType("kotlinx.cinterop.CPointer") }
)
@Test(expected = IllegalStateException::class)
@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") }
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun taTypesInKotlinxPackageWithDifferentClasses() = doTestFailure(
mockTAType("kotlinx.cinterop.CArrayPointer") { mockClassType("kotlinx.cinterop.CPointer") },
mockTAType("kotlinx.cinterop.CArrayPointer") { mockClassType("kotlinx.cinterop.CPointer") },
@@ -241,21 +241,21 @@ class DefaultTypeCommonizerTest : AbstractCommonizerTest<KotlinType, UnwrappedTy
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Foo") }
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun taTypesInUserPackageWithDifferentNames() = doTestFailure(
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Foo") },
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Foo") },
mockTAType("org.sample.BarAlias") { mockClassType("org.sample.Foo") }
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun taTypesInUserPackageWithDifferentClasses() = doTestFailure(
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Foo") },
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Foo") },
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Bar") }
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun multilevelTATypesInUserPackageWithSameNameAndRightHandSideClass() = doTestFailure(
mockTAType("org.sample.FooAlias") {
mockClassType("org.sample.Foo")
@@ -284,14 +284,14 @@ class DefaultTypeCommonizerTest : AbstractCommonizerTest<KotlinType, UnwrappedTy
mockTAType("kotlin.sequences.SequenceBuilder", nullable = true) { mockClassType("kotlin.sequences.SequenceScope") }
)
@Test(expected = IllegalStateException::class)
@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") }
)
@Test(expected = IllegalStateException::class)
@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") },
@@ -330,28 +330,28 @@ class DefaultTypeCommonizerTest : AbstractCommonizerTest<KotlinType, UnwrappedTy
mockTAType("org.sample.FooAlias", nullable = true) { mockClassType("org.sample.Foo") }
)
@Test(expected = IllegalStateException::class)
@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") }
)
@Test(expected = IllegalStateException::class)
@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") }
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun taTypesInUserPackageWithDifferentNullability3() = doTestFailure(
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Foo", nullable = false) },
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Foo", nullable = false) },
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Foo", nullable = true) }
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun taTypesInUserPackageWithDifferentNullability4() = doTestFailure(
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Foo", nullable = true) },
mockTAType("org.sample.FooAlias") { mockClassType("org.sample.Foo", nullable = true) },
@@ -35,49 +35,49 @@ class DefaultTypeParameterCommonizerTest : AbstractCommonizerTest<TypeParameterD
create(isReified = false).toMockParam()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun someAreReified1() = doTestFailure(
create(isReified = true).toMockParam(),
create(isReified = true).toMockParam(),
create(isReified = false).toMockParam()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun someAreReified2() = doTestFailure(
create(isReified = false).toMockParam(),
create(isReified = false).toMockParam(),
create(isReified = true).toMockParam()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun differentVariance1() = doTestFailure(
create(variance = Variance.IN_VARIANCE).toMockParam(),
create(variance = Variance.IN_VARIANCE).toMockParam(),
create(variance = Variance.OUT_VARIANCE).toMockParam()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun differentVariance2() = doTestFailure(
create(variance = Variance.OUT_VARIANCE).toMockParam(),
create(variance = Variance.OUT_VARIANCE).toMockParam(),
create(variance = Variance.INVARIANT).toMockParam()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun differentUpperBounds1() = doTestFailure(
create(upperBounds = listOf("kotlin.String")).toMockParam(),
create(upperBounds = listOf("kotlin.String")).toMockParam(),
create(upperBounds = listOf("kotlin.Int")).toMockParam()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun differentUpperBounds2() = doTestFailure(
create(upperBounds = listOf("kotlin.String", "kotlin.Int")).toMockParam(),
create(upperBounds = listOf("kotlin.String", "kotlin.Int")).toMockParam(),
create(upperBounds = listOf("kotlin.String")).toMockParam()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun differentUpperBounds3() = doTestFailure(
create(upperBounds = listOf("kotlin.String", "kotlin.Int")).toMockParam(),
create(upperBounds = listOf("kotlin.String", "kotlin.Int")).toMockParam(),
@@ -45,7 +45,7 @@ class DefaultTypeParameterListCommonizerTest : AbstractCommonizerTest<List<TypeP
).toMockParams()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun mismatchedParameterListSize1() = doTestFailure(
create(
"T" to "kotlin.Any?",
@@ -60,7 +60,7 @@ class DefaultTypeParameterListCommonizerTest : AbstractCommonizerTest<List<TypeP
emptyList()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun mismatchedParameterListSize2() = doTestFailure(
create(
"T" to "kotlin.Any?",
@@ -78,7 +78,7 @@ class DefaultTypeParameterListCommonizerTest : AbstractCommonizerTest<List<TypeP
).toMockParams()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun mismatchedParameterListSize3() = doTestFailure(
create(
"T" to "kotlin.Any?",
@@ -98,7 +98,7 @@ class DefaultTypeParameterListCommonizerTest : AbstractCommonizerTest<List<TypeP
).toMockParams()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun mismatchedParameterNames() = doTestFailure(
create(
"T" to "kotlin.Any?",
@@ -33,21 +33,21 @@ class DefaultValueParameterCommonizerTest : AbstractCommonizerTest<ValueParamete
create("org.sample.Foo").toMockParam()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun differentReturnTypes1() = doTestFailure(
create("kotlin.String").toMockParam(),
create("kotlin.String").toMockParam(),
create("kotlin.Int").toMockParam()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun differentReturnTypes2() = doTestFailure(
create("kotlin.String").toMockParam(),
create("kotlin.String").toMockParam(),
create("org.sample.Foo").toMockParam()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun differentReturnTypes3() = doTestFailure(
create("org.sample.Foo").toMockParam(),
create("org.sample.Foo").toMockParam(),
@@ -70,14 +70,14 @@ class DefaultValueParameterCommonizerTest : AbstractCommonizerTest<ValueParamete
create("org.sample.Foo", hasVarargElementType = true).toMockParam()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun someDoesNotHaveVararg1() = doTestFailure(
create("kotlin.String", hasVarargElementType = true).toMockParam(),
create("kotlin.String", hasVarargElementType = true).toMockParam(),
create("kotlin.String", hasVarargElementType = false).toMockParam()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun someDoesNotHaveVararg2() = doTestFailure(
create("org.sample.Foo", hasVarargElementType = false).toMockParam(),
create("org.sample.Foo", hasVarargElementType = false).toMockParam(),
@@ -132,7 +132,7 @@ class DefaultValueParameterCommonizerTest : AbstractCommonizerTest<ValueParamete
create("kotlin.String", isNoinline = true).toMockParam()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun anyDeclaresDefaultValue() = doTestFailure(
create("kotlin.String").toMockParam(declaresDefaultValue = false),
create("kotlin.String").toMockParam(declaresDefaultValue = false),
@@ -45,7 +45,7 @@ class DefaultValueParameterListCommonizerTest : AbstractCommonizerTest<List<Valu
).toMockParams()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun mismatchedParameterListSize1() = doTestFailure(
create(
"a" to "kotlin.String",
@@ -60,7 +60,7 @@ class DefaultValueParameterListCommonizerTest : AbstractCommonizerTest<List<Valu
emptyList()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun mismatchedParameterListSize2() = doTestFailure(
create(
"a" to "kotlin.String",
@@ -83,7 +83,7 @@ class DefaultValueParameterListCommonizerTest : AbstractCommonizerTest<List<Valu
).toMockParams()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun mismatchedParameterListSize3() = doTestFailure(
create(
"a" to "kotlin.String",
@@ -108,7 +108,7 @@ class DefaultValueParameterListCommonizerTest : AbstractCommonizerTest<List<Valu
).toMockParams()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun mismatchedParameterNames1() = doTestFailure(
create(
"a" to "kotlin.String",
@@ -127,7 +127,7 @@ class DefaultValueParameterListCommonizerTest : AbstractCommonizerTest<List<Valu
).toMockParams()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun mismatchedParameterNames2() = doTestFailure(
create(
"a" to "kotlin.String",
@@ -146,7 +146,7 @@ class DefaultValueParameterListCommonizerTest : AbstractCommonizerTest<List<Valu
).toMockParams()
)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun mismatchedParameterTypes() = doTestFailure(
create(
"a" to "kotlin.String",
@@ -20,22 +20,22 @@ class EqualizingVisibilityCommonizerTest : AbstractCommonizerTest<Visibility, Vi
@Test
fun internalOnly() = doTestSuccess(INTERNAL, INTERNAL, INTERNAL, INTERNAL)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun privateOnly() = doTestFailure(PRIVATE)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun publicAndProtected() = doTestFailure(PROTECTED, PROTECTED, PROTECTED, PUBLIC)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun publicAndInternal() = doTestFailure(INTERNAL, INTERNAL, INTERNAL, PUBLIC)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun protectedAndInternal() = doTestFailure(PROTECTED, PROTECTED, PROTECTED, INTERNAL)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun publicAndPrivate() = doTestFailure(PUBLIC, PUBLIC, PRIVATE)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun somethingUnexpected() = doTestFailure(PUBLIC, LOCAL)
override fun createCommonizer() = VisibilityCommonizer.equalizing()
@@ -20,7 +20,7 @@ class LoweringVisibilityCommonizerTest : AbstractCommonizerTest<Visibility, Visi
@Test
fun internalOnly() = doTestSuccess(INTERNAL, INTERNAL, INTERNAL, INTERNAL)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun privateOnly() = doTestFailure(PRIVATE)
@Test
@@ -29,13 +29,13 @@ class LoweringVisibilityCommonizerTest : AbstractCommonizerTest<Visibility, Visi
@Test
fun publicAndInternal() = doTestSuccess(INTERNAL, PUBLIC, INTERNAL, PUBLIC)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun protectedAndInternal() = doTestFailure(PUBLIC, INTERNAL, PROTECTED)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun publicAndPrivate() = doTestFailure(PUBLIC, INTERNAL, PRIVATE)
@Test(expected = IllegalStateException::class)
@Test(expected = IllegalCommonizerStateException::class)
fun somethingUnexpected() = doTestFailure(PUBLIC, LOCAL)
override fun createCommonizer() = VisibilityCommonizer.lowering()