Refactoring: change assertion signature, proper source set copying way
This commit is contained in:
committed by
Yaroslav.Chernyshev
parent
b2017a9c9c
commit
b32db1ac02
+2
-2
@@ -444,7 +444,7 @@ class HierarchicalMultiplatformProjectImportingTest : MultiplePluginVersionGradl
|
||||
targetPlatform(jvm, js)
|
||||
}
|
||||
module("my-app") {
|
||||
diagnostics(OrphanSourceSetsImportingDiagnostic::class.java to 1)
|
||||
assertDiagnosticsCount<OrphanSourceSetsImportingDiagnostic>(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -536,7 +536,7 @@ class HierarchicalMultiplatformProjectImportingTest : MultiplePluginVersionGradl
|
||||
checkProjectStructure(exhaustiveModuleList = false, exhaustiveSourceSourceRootList = false, exhaustiveDependencyList = false) {
|
||||
|
||||
module("my-app") {
|
||||
diagnostics(OrphanSourceSetsImportingDiagnostic::class.java to 3)
|
||||
assertDiagnosticsCount<OrphanSourceSetsImportingDiagnostic>(3)
|
||||
}
|
||||
|
||||
// (jvm, js, native) is highly undesirable
|
||||
|
||||
@@ -277,17 +277,14 @@ class ModuleInfo(
|
||||
}
|
||||
|
||||
@Suppress("UnstableApiUsage")
|
||||
fun diagnostics(vararg expectedByType: Pair<Class<out KotlinImportingDiagnostic>, Int>) {
|
||||
internal inline fun <reified T : KotlinImportingDiagnostic> assertDiagnosticsCount(count: Int) {
|
||||
val moduleNode = GradleUtil.findGradleModuleData(module)
|
||||
val diagnostics = moduleNode!!.kotlinImportingDiagnosticsContainer!!
|
||||
expectedByType.forEach { (expectedClazz, expectedCount) ->
|
||||
val typedDiagnostics = diagnostics.filterIsInstance(expectedClazz)
|
||||
if (typedDiagnostics.size != expectedCount) {
|
||||
val actualCount = typedDiagnostics.size
|
||||
projectInfo.messageCollector.report(
|
||||
"Expected number of ${expectedClazz.simpleName} diagnostics $expectedCount doesn't match the actual one: $actualCount"
|
||||
)
|
||||
}
|
||||
val typedDiagnostics = diagnostics.filterIsInstance<T>()
|
||||
if (typedDiagnostics.size != count) {
|
||||
projectInfo.messageCollector.report(
|
||||
"Expected number of ${T::class.java.simpleName} diagnostics $count doesn't match the actual one: ${typedDiagnostics.size}"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,12 +8,18 @@ package org.jetbrains.kotlin.gradle
|
||||
import java.io.Serializable
|
||||
|
||||
|
||||
interface KotlinImportingDiagnostic : Serializable
|
||||
interface KotlinImportingDiagnostic : Serializable {
|
||||
fun deepCopy(cache: MutableMap<Any, Any>): KotlinImportingDiagnostic
|
||||
}
|
||||
|
||||
typealias KotlinImportingDiagnosticsContainer = MutableSet<KotlinImportingDiagnostic>
|
||||
|
||||
interface KotlinSourceSetImportingDiagnostic : KotlinImportingDiagnostic {
|
||||
val kotlinSourceSet: KotlinSourceSet
|
||||
}
|
||||
|
||||
typealias KotlinImportingDiagnosticsContainer = MutableSet<KotlinImportingDiagnostic>
|
||||
|
||||
data class OrphanSourceSetsImportingDiagnostic(override val kotlinSourceSet: KotlinSourceSet) : KotlinSourceSetImportingDiagnostic
|
||||
data class OrphanSourceSetsImportingDiagnostic(override val kotlinSourceSet: KotlinSourceSet) : KotlinSourceSetImportingDiagnostic {
|
||||
override fun deepCopy(cache: MutableMap<Any, Any>): OrphanSourceSetsImportingDiagnostic =
|
||||
(cache[kotlinSourceSet] as? KotlinSourceSet)?.let { OrphanSourceSetsImportingDiagnostic(it) }
|
||||
?: OrphanSourceSetsImportingDiagnostic(KotlinSourceSetImpl(kotlinSourceSet, cache).apply { cache[kotlinSourceSet] = this })
|
||||
}
|
||||
@@ -266,7 +266,7 @@ data class KotlinMPPGradleModelImpl(
|
||||
),
|
||||
mppModel.kotlinNativeHome,
|
||||
mppModel.dependencyMap.map { it.key to it.value.deepCopy(cloningCache) }.toMap(),
|
||||
mppModel.kotlinImportingDiagnostics.toMutableSet()
|
||||
mppModel.kotlinImportingDiagnostics.mapTo(mutableSetOf()) { it.deepCopy(cloningCache) }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@ internal object OrphanSourceSetImportingChecker : MultiplatformModelImportingChe
|
||||
model: KotlinMPPGradleModel,
|
||||
reportTo: KotlinImportingDiagnosticsContainer,
|
||||
context: MultiplatformModelImportingContext
|
||||
) = model.sourceSets.values.filter { context.isOrphanSourceSet(it) }
|
||||
.map { OrphanSourceSetsImportingDiagnostic(it) }
|
||||
.forEach { reportTo += it }
|
||||
) {
|
||||
model.sourceSets.values.filter { context.isOrphanSourceSet(it) }
|
||||
.mapTo(reportTo) { OrphanSourceSetsImportingDiagnostic(it) }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user