More compact and meaningful error reporting in ResolverForProject
No more enormous module lists
This commit is contained in:
+1
@@ -88,6 +88,7 @@ public class BuiltInsSerializer(private val dependOnOldBuiltIns: Boolean) {
|
||||
|
||||
val builtInModule = BuiltinsSourcesModule()
|
||||
val resolver = JvmAnalyzerFacade.setupResolverForProject(
|
||||
"builtIns source",
|
||||
ProjectContext(environment.project), listOf(builtInModule),
|
||||
{ ModuleContent(files, GlobalSearchScope.EMPTY_SCOPE) },
|
||||
JvmPlatformParameters { throw IllegalStateException() },
|
||||
|
||||
@@ -40,33 +40,43 @@ public class ResolverForModule(
|
||||
public val componentProvider: ComponentProvider
|
||||
)
|
||||
|
||||
public interface ResolverForProject<M : ModuleInfo> {
|
||||
public fun resolverForModule(moduleInfo: M): ResolverForModule = resolverForModuleDescriptor(descriptorForModule(moduleInfo))
|
||||
public fun descriptorForModule(moduleInfo: M): ModuleDescriptor
|
||||
public fun resolverForModuleDescriptor(descriptor: ModuleDescriptor): ResolverForModule
|
||||
abstract class ResolverForProject<M : ModuleInfo> {
|
||||
fun resolverForModule(moduleInfo: M): ResolverForModule = resolverForModuleDescriptor(descriptorForModule(moduleInfo))
|
||||
abstract fun descriptorForModule(moduleInfo: M): ModuleDescriptor
|
||||
abstract fun resolverForModuleDescriptor(descriptor: ModuleDescriptor): ResolverForModule
|
||||
|
||||
val allModules: Collection<M>
|
||||
abstract val name: String
|
||||
abstract val allModules: Collection<M>
|
||||
|
||||
override fun toString() = "$name"
|
||||
}
|
||||
|
||||
public class EmptyResolverForProject<M : ModuleInfo> : ResolverForProject<M> {
|
||||
public class EmptyResolverForProject<M : ModuleInfo> : ResolverForProject<M>() {
|
||||
override val name: String
|
||||
get() = "Empty resolver"
|
||||
|
||||
override fun resolverForModuleDescriptor(descriptor: ModuleDescriptor): ResolverForModule = throw IllegalStateException("$descriptor is not contained in this resolver")
|
||||
override fun descriptorForModule(moduleInfo: M) = throw IllegalStateException("Should not be called for $moduleInfo")
|
||||
override val allModules: Collection<M> = listOf()
|
||||
}
|
||||
|
||||
public class ResolverForProjectImpl<M : ModuleInfo>(
|
||||
private val debugName: String,
|
||||
val descriptorByModule: Map<M, ModuleDescriptorImpl>,
|
||||
val delegateResolver: ResolverForProject<M> = EmptyResolverForProject()
|
||||
) : ResolverForProject<M> {
|
||||
) : ResolverForProject<M>() {
|
||||
val resolverByModuleDescriptor: MutableMap<ModuleDescriptor, () -> ResolverForModule> = HashMap()
|
||||
|
||||
override val allModules: Collection<M> by lazy {
|
||||
(descriptorByModule.keySet() + delegateResolver.allModules).toSet()
|
||||
}
|
||||
|
||||
override val name: String
|
||||
get() = "Resolver for '$debugName'"
|
||||
|
||||
private fun assertCorrectModuleInfo(moduleInfo: M) {
|
||||
if (moduleInfo !in allModules) {
|
||||
throw AssertionError("Requested data for $moduleInfo not contained in this resolver.\nThis resolver was created for following infos:\n${allModules.joinToString("\n")}")
|
||||
throw AssertionError("$name does not know how to resolve $moduleInfo")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +133,7 @@ public interface ModuleInfo {
|
||||
|
||||
public abstract class AnalyzerFacade<in P : PlatformAnalysisParameters> {
|
||||
public fun <M : ModuleInfo> setupResolverForProject(
|
||||
debugName: String,
|
||||
projectContext: ProjectContext,
|
||||
modules: Collection<M>,
|
||||
modulesContent: (M) -> ModuleContent,
|
||||
@@ -138,7 +149,7 @@ public abstract class AnalyzerFacade<in P : PlatformAnalysisParameters> {
|
||||
module ->
|
||||
descriptorByModule[module] = targetPlatform.createModule(module.name, storageManager)
|
||||
}
|
||||
return ResolverForProjectImpl(descriptorByModule, delegateResolver)
|
||||
return ResolverForProjectImpl(debugName, descriptorByModule, delegateResolver)
|
||||
}
|
||||
|
||||
val resolverForProject = createResolverForProject()
|
||||
|
||||
@@ -59,6 +59,7 @@ public class MultiModuleJavaAnalysisCustomTest : UsefulTestCase() {
|
||||
val environment = createEnvironment(moduleDirs)
|
||||
val modules = setupModules(environment, moduleDirs)
|
||||
val resolverForProject = JvmAnalyzerFacade.setupResolverForProject(
|
||||
"test",
|
||||
ProjectContext(environment.project), modules,
|
||||
{ m -> ModuleContent(m.kotlinFiles, m.javaFilesScope) },
|
||||
JvmPlatformParameters {
|
||||
|
||||
@@ -36,6 +36,7 @@ public fun createResolveSessionForFiles(
|
||||
val projectContext = ProjectContext(project)
|
||||
val testModule = TestModule(addBuiltIns)
|
||||
val resolverForProject = JvmAnalyzerFacade.setupResolverForProject(
|
||||
"test",
|
||||
projectContext, listOf(testModule),
|
||||
{ ModuleContent(syntheticFiles, GlobalSearchScope.allScope(project)) },
|
||||
JvmPlatformParameters { testModule },
|
||||
|
||||
+8
-1
@@ -55,6 +55,7 @@ public class KotlinCacheService(val project: Project) {
|
||||
private inner class GlobalFacade(platform: TargetPlatform) {
|
||||
val facadeForLibraries = ProjectResolutionFacade(project) {
|
||||
globalResolveSessionProvider(
|
||||
"project libraries for platform $platform",
|
||||
project,
|
||||
platform,
|
||||
logProcessCanceled = true,
|
||||
@@ -68,6 +69,7 @@ public class KotlinCacheService(val project: Project) {
|
||||
|
||||
val facadeForModules = ProjectResolutionFacade(project) {
|
||||
globalResolveSessionProvider(
|
||||
"project source roots and libraries for platform $platform",
|
||||
project,
|
||||
platform,
|
||||
reuseDataFrom = facadeForLibraries,
|
||||
@@ -93,11 +95,13 @@ public class KotlinCacheService(val project: Project) {
|
||||
PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT,
|
||||
KotlinOutOfBlockCompletionModificationTracker.getInstance(project)
|
||||
)
|
||||
val debugName = "completion/highlighting in $syntheticFileModule for files ${files.joinToString { it.name }} for platform $targetPlatform"
|
||||
return when {
|
||||
syntheticFileModule is ModuleSourceInfo -> {
|
||||
val dependentModules = syntheticFileModule.getDependentModules()
|
||||
ProjectResolutionFacade(project) {
|
||||
globalResolveSessionProvider(
|
||||
debugName,
|
||||
project,
|
||||
targetPlatform,
|
||||
syntheticFiles = files,
|
||||
@@ -111,6 +115,7 @@ public class KotlinCacheService(val project: Project) {
|
||||
syntheticFileModule is LibrarySourceInfo || syntheticFileModule is NotUnderContentRootModuleInfo -> {
|
||||
ProjectResolutionFacade(project) {
|
||||
globalResolveSessionProvider(
|
||||
debugName,
|
||||
project,
|
||||
targetPlatform,
|
||||
syntheticFiles = files,
|
||||
@@ -128,6 +133,7 @@ public class KotlinCacheService(val project: Project) {
|
||||
LOG.warn("Creating cache with synthetic files ($files) in classes of library $syntheticFileModule")
|
||||
ProjectResolutionFacade(project) {
|
||||
globalResolveSessionProvider(
|
||||
debugName,
|
||||
project,
|
||||
targetPlatform,
|
||||
syntheticFiles = files,
|
||||
@@ -186,6 +192,7 @@ public class KotlinCacheService(val project: Project) {
|
||||
}
|
||||
|
||||
private fun globalResolveSessionProvider(
|
||||
debugName: String,
|
||||
project: Project,
|
||||
platform: TargetPlatform,
|
||||
dependencies: Collection<Any>,
|
||||
@@ -201,7 +208,7 @@ private fun globalResolveSessionProvider(
|
||||
?: GlobalContext(logProcessCanceled)
|
||||
|
||||
val moduleResolverProvider = createModuleResolverProvider(
|
||||
project, globalContext,
|
||||
debugName, project, globalContext,
|
||||
AnalyzerFacadeProvider.getAnalyzerFacade(platform),
|
||||
syntheticFiles, delegateResolverForProject, moduleFilter
|
||||
)
|
||||
|
||||
+2
-1
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.resolve.jvm.JvmPlatformParameters
|
||||
import org.jetbrains.kotlin.storage.ExceptionTracker
|
||||
|
||||
fun createModuleResolverProvider(
|
||||
debugName: String,
|
||||
project: Project,
|
||||
globalContext: GlobalContextImpl,
|
||||
analyzerFacade: AnalyzerFacade<JvmPlatformParameters>,
|
||||
@@ -62,7 +63,7 @@ fun createModuleResolverProvider(
|
||||
}
|
||||
|
||||
val resolverForProject = analyzerFacade.setupResolverForProject(
|
||||
globalContext.withProject(project), modulesToCreateResolversFor, modulesContent,
|
||||
debugName, globalContext.withProject(project), modulesToCreateResolversFor, modulesContent,
|
||||
jvmPlatformParameters, IdeaEnvironment, delegateResolver,
|
||||
{ m, c -> IDEPackagePartProvider(c.moduleContentScope) }
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user