KotlinCacheService: Correctly deal with code fragments in getAnalysisResults()
Fix evaluate expression for breakpoints in library source
This commit is contained in:
+16
-5
@@ -182,17 +182,28 @@ public class KotlinCacheService(val project: Project) {
|
|||||||
val files = elements.map { it.getContainingJetFile() }.toSet()
|
val files = elements.map { it.getContainingJetFile() }.toSet()
|
||||||
assertAreInSameModule(files)
|
assertAreInSameModule(files)
|
||||||
|
|
||||||
if (files.all { !ProjectRootsUtil.isInProjectSource(it) }
|
val syntheticFiles = findSyntheticFiles(files)
|
||||||
// TODO: decide what to do with this
|
if (syntheticFiles.isNotEmpty()) {
|
||||||
// && files.all { it !is JetCodeFragment }
|
return getCacheForSyntheticFile(syntheticFiles).getAnalysisResultsForElements(elements)
|
||||||
) {
|
|
||||||
return getCacheForSyntheticFile(files).getAnalysisResultsForElements(elements)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val firstFile = elements.first().getContainingJetFile()
|
val firstFile = elements.first().getContainingJetFile()
|
||||||
return getGlobalCache(TargetPlatformDetector.getPlatform(firstFile)).getAnalysisResultsForElements(elements)
|
return getGlobalCache(TargetPlatformDetector.getPlatform(firstFile)).getAnalysisResultsForElements(elements)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun findSyntheticFiles(files: Collection<JetFile>) = files.map {
|
||||||
|
if (it is JetCodeFragment) it.getContextFile() else it
|
||||||
|
}.filter {
|
||||||
|
!ProjectRootsUtil.isInProjectSource(it)
|
||||||
|
}.toSet()
|
||||||
|
|
||||||
|
private fun JetCodeFragment.getContextFile(): JetFile {
|
||||||
|
val contextElement = getContext() ?: throw AssertionError("Analyzing code fragment of type $javaClass with no context")
|
||||||
|
val contextFile = (contextElement as? JetElement)?.getContainingJetFile()
|
||||||
|
?: throw AssertionError("Analyzing kotlin code fragment of type $javaClass with java context of type ${contextElement.javaClass}")
|
||||||
|
return if (contextFile is JetCodeFragment) contextFile.getContextFile() else contextFile
|
||||||
|
}
|
||||||
|
|
||||||
private fun assertAreInSameModule(elements: Collection<JetElement>) {
|
private fun assertAreInSameModule(elements: Collection<JetElement>) {
|
||||||
if (elements.size <= 1) {
|
if (elements.size <= 1) {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user