Introduce LT file abstraction in tests parallel to KtFile
allows to create a valid LT-based file with synthetic path important for dumps comparisons in tests
This commit is contained in:
+16
@@ -6,6 +6,8 @@
|
||||
package org.jetbrains.kotlin.test.services
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.fir.lightTree.LightTree2Fir
|
||||
import org.jetbrains.kotlin.fir.lightTree.LightTreeFile
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.test.model.TestFile
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
@@ -97,6 +99,20 @@ fun SourceFileProvider.getKtFilesForSourceFiles(testFiles: Collection<TestFile>,
|
||||
}.toMap()
|
||||
}
|
||||
|
||||
fun SourceFileProvider.getLightTreeKtFileForSourceFile(testFile: TestFile): LightTreeFile {
|
||||
val shortName = testFile.name.substringAfterLast('/').substringAfterLast('\\')
|
||||
val file = getRealFileForSourceFile(testFile)
|
||||
val lightTree = LightTree2Fir.buildLightTree(file.readText())
|
||||
return LightTreeFile(lightTree, shortName, "/$shortName") // emulating behavior of KtTestUtil.createFile so path looks the same in testdata
|
||||
}
|
||||
|
||||
fun SourceFileProvider.getLightTreeFilesForSourceFiles(testFiles: Collection<TestFile>): Map<TestFile, LightTreeFile> {
|
||||
return testFiles.mapNotNull {
|
||||
if (!it.isKtFile) return@mapNotNull null
|
||||
it to getLightTreeKtFileForSourceFile(it)
|
||||
}.toMap()
|
||||
}
|
||||
|
||||
val TestFile.isKtFile: Boolean
|
||||
get() = name.endsWith(".kt") || name.endsWith(".kts")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user