Replace transitiveClosure (commonizer-api) with closure (tooling-core)
This commit is contained in:
committed by
Space
parent
530a3bb6ea
commit
14046b81ff
@@ -9,7 +9,7 @@ standardPublicJars()
|
||||
|
||||
dependencies {
|
||||
implementation(kotlinStdlib())
|
||||
|
||||
implementation(project(":kotlin-tooling-core"))
|
||||
testImplementation(kotlin("test-junit"))
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
package org.jetbrains.kotlin.project.model
|
||||
|
||||
import org.jetbrains.kotlin.project.model.utils.variantsContainingFragment
|
||||
import org.jetbrains.kotlin.tooling.core.closure
|
||||
import org.jetbrains.kotlin.tooling.core.withClosure
|
||||
import java.io.File
|
||||
|
||||
interface KotlinModuleFragment {
|
||||
@@ -39,13 +41,10 @@ val KotlinModuleFragment.fragmentAttributeSets: Map<KotlinAttributeKey, Set<Stri
|
||||
}
|
||||
|
||||
val KotlinModuleFragment.refinesClosure: Set<KotlinModuleFragment>
|
||||
get() = mutableSetOf<KotlinModuleFragment>().apply {
|
||||
fun visit(moduleFragment: KotlinModuleFragment) {
|
||||
if (add(moduleFragment))
|
||||
moduleFragment.directRefinesDependencies.forEach(::visit)
|
||||
}
|
||||
visit(this@refinesClosure)
|
||||
}
|
||||
get() = this.closure { it.directRefinesDependencies }
|
||||
|
||||
val KotlinModuleFragment.withRefinesClosure: Set<KotlinModuleFragment>
|
||||
get() = this.withClosure { it.directRefinesDependencies }
|
||||
|
||||
val KotlinModuleVariant.platform get() = variantAttributes[KotlinPlatformTypeAttribute]
|
||||
|
||||
@@ -67,7 +66,7 @@ class BasicKotlinModuleVariant(
|
||||
containingModule: KotlinModule,
|
||||
fragmentName: String,
|
||||
languageSettings: LanguageSettings? = null
|
||||
) : BasicKotlinModuleFragment (
|
||||
) : BasicKotlinModuleFragment(
|
||||
containingModule,
|
||||
fragmentName,
|
||||
languageSettings
|
||||
|
||||
@@ -49,7 +49,7 @@ class DefaultModuleFragmentsResolver(
|
||||
|
||||
val chosenFragments = chosenVariants.map { variantResolution ->
|
||||
when (variantResolution) {
|
||||
is VariantResolution.VariantMatch -> variantResolution.chosenVariant.refinesClosure
|
||||
is VariantResolution.VariantMatch -> variantResolution.chosenVariant.withRefinesClosure
|
||||
else -> emptySet()
|
||||
}
|
||||
}
|
||||
@@ -63,4 +63,4 @@ class DefaultModuleFragmentsResolver(
|
||||
|
||||
return FragmentResolution.ChosenFragments(requestingFragment, dependencyModule, result, chosenVariants)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,22 +8,14 @@ package org.jetbrains.kotlin.project.model.utils
|
||||
import org.jetbrains.kotlin.project.model.KotlinModule
|
||||
import org.jetbrains.kotlin.project.model.KotlinModuleFragment
|
||||
import org.jetbrains.kotlin.project.model.KotlinModuleVariant
|
||||
import org.jetbrains.kotlin.project.model.refinesClosure
|
||||
import org.jetbrains.kotlin.project.model.withRefinesClosure
|
||||
import org.jetbrains.kotlin.tooling.core.closure
|
||||
|
||||
fun KotlinModule.variantsContainingFragment(fragment: KotlinModuleFragment): Iterable<KotlinModuleVariant> =
|
||||
variants.filter { fragment in it.refinesClosure }
|
||||
variants.filter { variant -> fragment in variant.withRefinesClosure }
|
||||
|
||||
fun KotlinModule.findRefiningFragments(fragment: KotlinModuleFragment): Iterable<KotlinModuleFragment> {
|
||||
val refining = mutableSetOf<KotlinModuleFragment>()
|
||||
val notRefining = mutableSetOf<KotlinModuleFragment>()
|
||||
|
||||
fun isRefining(other: KotlinModuleFragment): Boolean = when {
|
||||
other in refining -> true
|
||||
other in notRefining -> false
|
||||
fragment in other.directRefinesDependencies -> true.also { refining.add(other) }
|
||||
fragment.directRefinesDependencies.any { isRefining(it) } -> true.also { refining.add(other) }
|
||||
else -> false.also { notRefining.add(other) }
|
||||
return fragment.closure { seedFragment ->
|
||||
fragments.filter { otherFragment -> seedFragment in otherFragment.directRefinesDependencies }
|
||||
}
|
||||
|
||||
return fragments.filter(::isRefining)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user