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