Delegate to global cache when building ModuleResolverProvider for synthetic files

This commit is contained in:
Pavel V. Talanov
2014-09-16 17:23:15 +04:00
parent 5847c3559b
commit 68201c3e86
2 changed files with 36 additions and 12 deletions
@@ -65,9 +65,9 @@ public class KotlinCacheService(val project: Project) {
fun globalResolveSessionProvider(
platform: TargetPlatform,
dependencies: Collection<Any>,
moduleFilter: (IdeaModuleInfo) -> Boolean,
reuseDataFromCache: KotlinResolveCache? = null,
syntheticFiles: Collection<JetFile> = listOf(),
moduleFilter: (IdeaModuleInfo) -> Boolean = { true }
syntheticFiles: Collection<JetFile> = listOf()
): () -> CachedValueProvider.Result<ModuleResolverProvider> = {
val analyzerFacade = AnalyzerFacadeProvider.getAnalyzerFacade(platform)
val delegateResolverProvider = reuseDataFromCache?.moduleResolverProvider ?: EmptyModuleResolverProvider
@@ -94,20 +94,43 @@ public class KotlinCacheService(val project: Project) {
}
private fun getGlobalCache(platform: TargetPlatform) = globalCachesPerPlatform[platform]!!.modulesCache
private fun getGlobalLibrariesCache(platform: TargetPlatform) = globalCachesPerPlatform[platform]!!.librariesCache
private val syntheticFileCaches = object : SLRUCache<JetFile, KotlinResolveCache>(2, 3) {
override fun createValue(file: JetFile?): KotlinResolveCache {
val targetPlatform = TargetPlatformDetector.getPlatform(file!!)
return KotlinResolveCache(
project,
globalResolveSessionProvider(
targetPlatform,
syntheticFiles = listOf(file),
reuseDataFromCache = globalCachesPerPlatform[targetPlatform]!!.librariesCache,
moduleFilter = { !it.isLibraryClasses() },
dependencies = listOf(PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT)
val syntheticFileModule = file.getModuleInfo()
return when {
syntheticFileModule is ModuleSourceInfo -> {
val dependentModules = syntheticFileModule.getDependentModules()
KotlinResolveCache(
project,
globalResolveSessionProvider(
targetPlatform,
syntheticFiles = listOf(file),
reuseDataFromCache = getGlobalCache(targetPlatform),
moduleFilter = { it in dependentModules },
dependencies = listOf(PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT)
)
)
)
}
else -> {
if (syntheticFileModule.isLibraryClasses()) {
LOG.error("Creating cache with synthetic file ($file) in classes of library $syntheticFileModule")
}
KotlinResolveCache(
project,
globalResolveSessionProvider(
targetPlatform,
syntheticFiles = listOf(file),
reuseDataFromCache = getGlobalLibrariesCache(targetPlatform),
moduleFilter = { it == syntheticFileModule },
dependencies = listOf(PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT)
)
)
}
}
}
}
@@ -48,7 +48,8 @@ fun createModuleResolverProvider(
val globalContext = (delegateProvider as? ModuleResolverProviderImpl)?.globalContext ?: GlobalContext()
val syntheticFilesByModule = syntheticFiles.groupBy { it.getModuleInfo() }
allModuleInfos.addAll(syntheticFilesByModule.keySet())
val syntheticFilesModules = syntheticFilesByModule.keySet()
allModuleInfos.addAll(syntheticFilesModules)
val modulesToCreateResolversFor = allModuleInfos.filter(moduleFilter)