[Expect/Actual] Introduce ModuleStructureOracle
This commit is contained in:
@@ -107,7 +107,8 @@ fun createContainerForBodyResolve(
|
||||
platform: TargetPlatform,
|
||||
statementFilter: StatementFilter,
|
||||
analyzerServices: PlatformDependentAnalyzerServices,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
moduleStructureOracle: ModuleStructureOracle
|
||||
): StorageComponentContainer = createContainer("BodyResolve", analyzerServices) {
|
||||
configureModule(moduleContext, platform, analyzerServices, bindingTrace, languageVersionSettings)
|
||||
|
||||
@@ -117,6 +118,7 @@ fun createContainerForBodyResolve(
|
||||
useImpl<AnnotationResolverImpl>()
|
||||
|
||||
useImpl<BodyResolver>()
|
||||
useInstance(moduleStructureOracle)
|
||||
}
|
||||
|
||||
fun createContainerForLazyBodyResolve(
|
||||
@@ -126,7 +128,8 @@ fun createContainerForLazyBodyResolve(
|
||||
platform: TargetPlatform,
|
||||
bodyResolveCache: BodyResolveCache,
|
||||
analyzerServices: PlatformDependentAnalyzerServices,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
moduleStructureOracle: ModuleStructureOracle
|
||||
): StorageComponentContainer = createContainer("LazyBodyResolve", analyzerServices) {
|
||||
configureModule(moduleContext, platform, analyzerServices, bindingTrace, languageVersionSettings)
|
||||
|
||||
@@ -136,6 +139,7 @@ fun createContainerForLazyBodyResolve(
|
||||
useImpl<AnnotationResolverImpl>()
|
||||
useImpl<LazyTopDownAnalyzer>()
|
||||
useImpl<BasicAbsentDescriptorHandler>()
|
||||
useInstance(moduleStructureOracle)
|
||||
}
|
||||
|
||||
fun createContainerForLazyLocalClassifierAnalyzer(
|
||||
|
||||
@@ -27,5 +27,6 @@ object CompilerEnvironment : TargetEnvironment("Compiler") {
|
||||
container.useInstance(BodyResolveCache.ThrowException)
|
||||
container.useImpl<CompilerLocalDescriptorResolver>()
|
||||
container.useImpl<BasicAbsentDescriptorHandler>()
|
||||
container.useInstance(ModuleStructureOracle.SingleModule)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. 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.resolve
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
|
||||
interface ModuleStructureOracle {
|
||||
// May be faster than `findAllImplementingModules(module).isNotEmpty()`
|
||||
fun hasImplementingModules(module: ModuleDescriptor): Boolean
|
||||
|
||||
fun findAllReversedDependsOnPaths(module: ModuleDescriptor): List<ModulePath>
|
||||
|
||||
fun findAllDependsOnPaths(module: ModuleDescriptor): List<ModulePath>
|
||||
|
||||
/**
|
||||
* Works like all sources are effectively in one module.
|
||||
*
|
||||
* This is the mode CLI currently operates in.
|
||||
*/
|
||||
object SingleModule : ModuleStructureOracle {
|
||||
override fun hasImplementingModules(module: ModuleDescriptor): Boolean = false
|
||||
|
||||
override fun findAllReversedDependsOnPaths(module: ModuleDescriptor): List<ModulePath> = listOf(ModulePath(module))
|
||||
|
||||
override fun findAllDependsOnPaths(module: ModuleDescriptor): List<ModulePath> = listOf(ModulePath(module))
|
||||
}
|
||||
}
|
||||
|
||||
class ModulePath(val nodes: List<ModuleDescriptor>) {
|
||||
constructor(vararg nodes: ModuleDescriptor) : this(nodes.toList())
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
|
||||
import org.jetbrains.kotlin.container.StorageComponentContainer
|
||||
import org.jetbrains.kotlin.container.getValue
|
||||
import org.jetbrains.kotlin.container.useImpl
|
||||
import org.jetbrains.kotlin.container.useInstance
|
||||
import org.jetbrains.kotlin.context.ModuleContext
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.frontend.di.configureModule
|
||||
@@ -41,6 +42,7 @@ fun createContainerForTests(project: Project, module: ModuleDescriptor): Contain
|
||||
LanguageVersionSettingsImpl.DEFAULT
|
||||
)
|
||||
useImpl<AnnotationResolverImpl>()
|
||||
useInstance(ModuleStructureOracle.SingleModule)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils
|
||||
import org.jetbrains.kotlin.frontend.di.createContainerForLazyBodyResolve
|
||||
import org.jetbrains.kotlin.idea.caches.project.getModuleInfo
|
||||
import org.jetbrains.kotlin.idea.project.IdeaModuleStructureOracle
|
||||
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
|
||||
import org.jetbrains.kotlin.idea.project.findAnalyzerServices
|
||||
import org.jetbrains.kotlin.idea.project.languageVersionSettings
|
||||
@@ -198,7 +199,8 @@ private object KotlinResolveDataProvider {
|
||||
targetPlatform,
|
||||
bodyResolveCache,
|
||||
targetPlatform.findAnalyzerServices,
|
||||
analyzableElement.languageVersionSettings
|
||||
analyzableElement.languageVersionSettings,
|
||||
IdeaModuleStructureOracle()
|
||||
).get<LazyTopDownAnalyzer>()
|
||||
|
||||
lazyTopDownAnalyzer.analyzeDeclarations(TopDownAnalysisMode.TopLevelDeclarations, listOf(analyzableElement))
|
||||
|
||||
@@ -27,5 +27,6 @@ object IdeaEnvironment : TargetEnvironment("Idea") {
|
||||
container.useImpl<IdeaLocalDescriptorResolver>()
|
||||
container.useImpl<IdeaAbsentDescriptorHandler>()
|
||||
container.useImpl<LazyLightClassDataHolder.DiagnosticsHolder>()
|
||||
container.useImpl<IdeaModuleStructureOracle>()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. 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.idea.project
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.project.implementingDescriptors
|
||||
import org.jetbrains.kotlin.resolve.ModulePath
|
||||
import org.jetbrains.kotlin.resolve.ModuleStructureOracle
|
||||
import java.util.*
|
||||
|
||||
class IdeaModuleStructureOracle : ModuleStructureOracle {
|
||||
override fun hasImplementingModules(module: ModuleDescriptor): Boolean {
|
||||
return module.implementingDescriptors.isNotEmpty()
|
||||
}
|
||||
|
||||
override fun findAllReversedDependsOnPaths(module: ModuleDescriptor): List<ModulePath> {
|
||||
val currentPath: Stack<ModuleDescriptor> = Stack()
|
||||
|
||||
return sequence<ModulePath> {
|
||||
yieldPathsFromSubgraph(module, currentPath, getChilds = { it.implementingDescriptors })
|
||||
}.toList()
|
||||
}
|
||||
|
||||
override fun findAllDependsOnPaths(module: ModuleDescriptor): List<ModulePath> {
|
||||
val currentPath: Stack<ModuleDescriptor> = Stack()
|
||||
|
||||
return sequence<ModulePath> {
|
||||
yieldPathsFromSubgraph(module, currentPath, getChilds = { it.expectedByModules })
|
||||
}.toList()
|
||||
}
|
||||
|
||||
private suspend fun SequenceScope<ModulePath>.yieldPathsFromSubgraph(
|
||||
root: ModuleDescriptor,
|
||||
currentPath: Stack<ModuleDescriptor>,
|
||||
getChilds: (ModuleDescriptor) -> List<ModuleDescriptor>
|
||||
) {
|
||||
currentPath.push(root)
|
||||
|
||||
val childs = getChilds(root)
|
||||
if (childs.isEmpty()) {
|
||||
yield(ModulePath(currentPath.toList()))
|
||||
} else {
|
||||
childs.forEach {
|
||||
yieldPathsFromSubgraph(it, currentPath, getChilds)
|
||||
}
|
||||
}
|
||||
|
||||
currentPath.pop()
|
||||
}
|
||||
}
|
||||
@@ -714,7 +714,8 @@ class ResolveElementCache(
|
||||
targetPlatform,
|
||||
statementFilter,
|
||||
targetPlatform.findAnalyzerServices,
|
||||
file.languageVersionSettings
|
||||
file.languageVersionSettings,
|
||||
IdeaModuleStructureOracle()
|
||||
).get()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user