Synchronization logic extracted into a method

This commit is contained in:
Andrey Breslav
2014-04-22 20:24:23 +04:00
parent 35b2d6536e
commit 04b28b14e5
@@ -135,6 +135,12 @@ class KotlinCacheService(val project: Project) {
} }
} }
private fun getCacheForSyntheticFile(file: JetFile): KotlinResolveCache {
return synchronized(syntheticFileCaches) {
syntheticFileCaches[file]
}
}
public fun getGlobalLazyResolveSession(platform: TargetPlatform): ResolveSessionForBodies { public fun getGlobalLazyResolveSession(platform: TargetPlatform): ResolveSessionForBodies {
return globalCachesPerPlatform[platform]!!.getLazyResolveSession() return globalCachesPerPlatform[platform]!!.getLazyResolveSession()
} }
@@ -142,9 +148,7 @@ class KotlinCacheService(val project: Project) {
public fun getLazyResolveSession(element: JetElement): ResolveSessionForBodies { public fun getLazyResolveSession(element: JetElement): ResolveSessionForBodies {
val file = element.getContainingJetFile() val file = element.getContainingJetFile()
if (!isFileInScope(file)) { if (!isFileInScope(file)) {
return synchronized(syntheticFileCaches) { return getCacheForSyntheticFile(file).getLazyResolveSession()
syntheticFileCaches[file].getLazyResolveSession()
}
} }
return getGlobalLazyResolveSession(TargetPlatformDetector.getPlatform(file)) return getGlobalLazyResolveSession(TargetPlatformDetector.getPlatform(file))
@@ -155,9 +159,7 @@ class KotlinCacheService(val project: Project) {
val firstFile = elements.first().getContainingJetFile() val firstFile = elements.first().getContainingJetFile()
if (elements.size == 1 && !isFileInScope(firstFile)) { if (elements.size == 1 && !isFileInScope(firstFile)) {
return synchronized(syntheticFileCaches) { return getCacheForSyntheticFile(firstFile).getAnalysisResultsForElements(elements)
syntheticFileCaches[firstFile].getAnalysisResultsForElements(elements)
}
} }
val resolveCache = globalCachesPerPlatform[TargetPlatformDetector.getPlatform(firstFile)]!! val resolveCache = globalCachesPerPlatform[TargetPlatformDetector.getPlatform(firstFile)]!!