[Commonizer] Nicer API for CirProvidedClassifiers
This commit is contained in:
@@ -41,9 +41,9 @@ private fun mergeAndCommonize(storageManager: StorageManager, parameters: Common
|
||||
val classifiers = CirKnownClassifiers(
|
||||
commonizedNodes = CirCommonizedClassifierNodes.default(),
|
||||
forwardDeclarations = CirForwardDeclarations.default(),
|
||||
commonDependencies = CirCompositeClassifiers(
|
||||
commonDependencies = CirProvidedClassifiers.of(
|
||||
CirFictitiousFunctionClassifiers,
|
||||
CirLoadedClassifiers.from(parameters.dependencyModulesProvider)
|
||||
CirProvidedClassifiers.by(parameters.dependencyModulesProvider)
|
||||
)
|
||||
)
|
||||
val mergeResult = CirTreeMerger(storageManager, classifiers, parameters).merge()
|
||||
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId
|
||||
|
||||
class CirCompositeClassifiers(private val delegates: List<CirProvidedClassifiers>) : CirProvidedClassifiers {
|
||||
constructor(vararg delegates: CirProvidedClassifiers) : this(delegates.toList())
|
||||
|
||||
override fun hasClassifier(classifierId: CirEntityId): Boolean = delegates.any { it.hasClassifier(classifierId) }
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.ModulesProvider
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId
|
||||
|
||||
/** A set of classes and type aliases provided by libraries (either the libraries to commonize, or their dependency libraries)/ */
|
||||
interface CirProvidedClassifiers {
|
||||
fun hasClassifier(classifierId: CirEntityId): Boolean
|
||||
|
||||
// TODO: implement later
|
||||
//fun classifier(classifierId: ClassId): Any?
|
||||
|
||||
object EMPTY : CirProvidedClassifiers {
|
||||
override fun hasClassifier(classifierId: CirEntityId) = false
|
||||
}
|
||||
|
||||
private class CompositeClassifiers(val delegates: List<CirProvidedClassifiers>) : CirProvidedClassifiers {
|
||||
override fun hasClassifier(classifierId: CirEntityId) = delegates.any { it.hasClassifier(classifierId) }
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun of(vararg delegates: CirProvidedClassifiers): CirProvidedClassifiers {
|
||||
val unwrappedDelegates: List<CirProvidedClassifiers> = delegates.fold(ArrayList()) { acc, delegate ->
|
||||
when (delegate) {
|
||||
EMPTY -> Unit
|
||||
is CompositeClassifiers -> acc.addAll(delegate.delegates)
|
||||
else -> acc.add(delegate)
|
||||
}
|
||||
acc
|
||||
}
|
||||
|
||||
return when (unwrappedDelegates.size) {
|
||||
0 -> EMPTY
|
||||
1 -> unwrappedDelegates.first()
|
||||
else -> CompositeClassifiers(unwrappedDelegates)
|
||||
}
|
||||
}
|
||||
|
||||
fun by(modulesProvider: ModulesProvider?): CirProvidedClassifiers =
|
||||
if (modulesProvider != null) CirProvidedClassifiersByModules(modulesProvider) else EMPTY
|
||||
}
|
||||
}
|
||||
+1
-6
@@ -14,15 +14,10 @@ import org.jetbrains.kotlin.library.metadata.parsePackageFragment
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolverImpl
|
||||
|
||||
class CirLoadedClassifiers(modulesProvider: ModulesProvider) : CirProvidedClassifiers {
|
||||
internal class CirProvidedClassifiersByModules(modulesProvider: ModulesProvider) : CirProvidedClassifiers {
|
||||
private val classifiers: Set<CirEntityId> = loadClassifiers(modulesProvider)
|
||||
|
||||
override fun hasClassifier(classifierId: CirEntityId): Boolean = classifierId in classifiers
|
||||
|
||||
companion object {
|
||||
fun from(modulesProvider: ModulesProvider?): CirProvidedClassifiers =
|
||||
if (modulesProvider != null) CirLoadedClassifiers(modulesProvider) else CirProvidedClassifiers.EMPTY
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadClassifiers(modulesProvider: ModulesProvider): Set<CirEntityId> {
|
||||
+1
-15
@@ -67,18 +67,4 @@ interface CirForwardDeclarations {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** A set of classes and type aliases provided by libraries (either the libraries to commonize, or their dependency libraries)/ */
|
||||
interface CirProvidedClassifiers {
|
||||
fun hasClassifier(classifierId: CirEntityId): Boolean
|
||||
|
||||
// TODO: implement later
|
||||
//fun classifier(classifierId: ClassId): Any?
|
||||
|
||||
companion object {
|
||||
internal val EMPTY = object : CirProvidedClassifiers {
|
||||
override fun hasClassifier(classifierId: CirEntityId) = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user