mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] J2K tests: optimize getFileTextWithErrors
Don't analyze the actual file for errors if the expected testdata doesn't have errors. GitOrigin-RevId: a5150153d30bf66197b8314ca5b0c4941e211cc7
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1d57188894
commit
6fb371be0f
+10
-1
@@ -83,7 +83,16 @@ abstract class AbstractJavaToKotlinConverterMultiFileTest : AbstractJavaToKotlin
|
||||
}
|
||||
|
||||
for ((i, kotlinFile) in resultFiles.withIndex()) {
|
||||
KotlinTestUtils.assertEqualsToFile(expectedResultFile(i), kotlinFile.getFileTextWithErrors())
|
||||
val expectedFile = expectedResultFile(i)
|
||||
val shouldCheckForErrors = expectedFile.readText().contains(ERROR_HEADER)
|
||||
val actualText = if (shouldCheckForErrors) {
|
||||
// Optimization: K2 `getFileTextWithErrors` is expensive
|
||||
kotlinFile.getFileTextWithErrors()
|
||||
} else {
|
||||
kotlinFile.text
|
||||
}
|
||||
|
||||
KotlinTestUtils.assertEqualsToFile(expectedFile, actualText)
|
||||
}
|
||||
|
||||
for ((externalFile, externalPsiFile) in externalFiles.zip(externalPsiFiles)) {
|
||||
|
||||
+5
-2
@@ -49,13 +49,16 @@ abstract class AbstractJavaToKotlinConverterSingleFileTest : AbstractJavaToKotli
|
||||
val directives = KotlinTestUtils.parseDirectives(javaCode)
|
||||
val settings = configureSettings(directives)
|
||||
val convertedText = convertJavaToKotlin(prefix, javaCode, settings)
|
||||
val expectedFile = File(javaFile.path.replace(".java", ".kt"))
|
||||
val shouldCheckForErrors = expectedFile.readText().contains(ERROR_HEADER)
|
||||
|
||||
val actualText = if (prefix == "file") {
|
||||
val actualText = if (prefix == "file" && shouldCheckForErrors) {
|
||||
// Optimization: K2 `getFileTextWithErrors` is expensive
|
||||
createKotlinFile(convertedText).getFileTextWithErrors()
|
||||
} else {
|
||||
convertedText
|
||||
}
|
||||
val expectedFile = File(javaFile.path.replace(".java", ".kt"))
|
||||
|
||||
KotlinTestUtils.assertEqualsToFile(expectedFile, actualText)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,9 +17,11 @@ val J2K_PROJECT_DESCRIPTOR: KotlinWithJdkAndRuntimeLightProjectDescriptor =
|
||||
override fun getSdk(): Sdk = IdeaTestUtil.getMockJdk21()
|
||||
}
|
||||
|
||||
val J2K_FULL_JDK_PROJECT_DESCRIPTOR: KotlinWithJdkAndRuntimeLightProjectDescriptor =
|
||||
internal val J2K_FULL_JDK_PROJECT_DESCRIPTOR: KotlinWithJdkAndRuntimeLightProjectDescriptor =
|
||||
KotlinWithJdkAndRuntimeLightProjectDescriptor.getInstanceFullJdk()
|
||||
|
||||
internal const val ERROR_HEADER: String = "// ERROR"
|
||||
|
||||
// TODO: adapted from `org.jetbrains.kotlin.idea.test.TestUtilsKt.dumpTextWithErrors`
|
||||
@OptIn(KtAllowAnalysisOnEdt::class)
|
||||
internal fun getK2FileTextWithErrors(file: KtFile): String {
|
||||
|
||||
Reference in New Issue
Block a user