diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/gradle/GradleMultiplatformHighlightingTest.kt b/idea/idea-gradle/tests/org/jetbrains/kotlin/gradle/GradleMultiplatformHighlightingTest.kt index d41cba4ad10..e52e8a6c797 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/gradle/GradleMultiplatformHighlightingTest.kt +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/gradle/GradleMultiplatformHighlightingTest.kt @@ -27,17 +27,22 @@ class GradleMultiplatformHighlightingTest : GradleImportingTestCase() { @TargetVersions("4.7+") @Test fun testFirst() { + doTest() + } + + private fun doTest() { val files = importProjectFromTestData() val project = myTestFixture.project checkFiles(files, project) { editor -> - daemonAnalyzerTestCase.checkHighlighting(editor, project) + daemonAnalyzerTestCase.checkHighlighting(project, editor) } - } private val daemonAnalyzerTestCase = object : DaemonAnalyzerTestCase() { - fun checkHighlighting(editor: Editor, project: Project) { + override fun doTestLineMarkers() = true + + fun checkHighlighting(project: Project, editor: Editor) { myProject = project runInEdtAndWait { checkHighlighting(editor, /* checkWarnings = */ true, /* checkInfos = */ false) @@ -47,34 +52,50 @@ class GradleMultiplatformHighlightingTest : GradleImportingTestCase() { private fun checkFiles(files: List, project: Project, check: (Editor) -> Unit) { var atLeastOneFile = false - files.filter { it.extension == "kt" }.forEach { file -> - val editor = configureEditorByExistingFile(file, project) + val kotlinFiles = files.filter { it.extension == "kt" } + val content = mutableMapOf() + kotlinFiles.forEach { file -> + val (_, textWithTags) = configureEditorByExistingFile(file, project) atLeastOneFile = true - check(editor) + content[file] = textWithTags } Assert.assertTrue(atLeastOneFile) + kotlinFiles.forEach { file -> + val (editor, _) = configureEditorByExistingFile(file, project, content[file]) + check(editor) + } } - private fun configureEditorByExistingFile(virtualFile: VirtualFile, project: Project): Editor { - var result: Editor? = null + private fun configureEditorByExistingFile( + virtualFile: VirtualFile, + project: Project, + contentToSet: String? = null + ): Pair { + var result: Pair? = null runInEdtAndWait { val editor = createEditor(virtualFile, project) val document = editor.document val editorInfo = EditorInfo(document.text) - val newFileText = editorInfo.newFileText + val textWithTags = editorInfo.newFileText ApplicationManager.getApplication().runWriteAction { - if (document.text != newFileText) { - document.setText(newFileText) + val newText = contentToSet ?: textWithTags.withoutTags() + if (document.text != newText) { + document.setText(newText) } editorInfo.applyToEditor(editor) } PsiDocumentManager.getInstance(project).commitAllDocuments() - result = editor + result = editor to textWithTags } return result!! } + private fun String.withoutTags(): String { + val regex = "".toRegex() + return regex.replace(this, "") + } + private fun createEditor(file: VirtualFile, project: Project): Editor { val instance = FileEditorManager.getInstance(this.myProject) PsiDocumentManager.getInstance(project).commitAllDocuments() diff --git a/idea/testData/gradle/newMultiplatformHighlighting/first/src/commonMain/kotlin/My.kt b/idea/testData/gradle/newMultiplatformHighlighting/first/src/commonMain/kotlin/My.kt index 13cbde660aa..3105c058a07 100644 --- a/idea/testData/gradle/newMultiplatformHighlighting/first/src/commonMain/kotlin/My.kt +++ b/idea/testData/gradle/newMultiplatformHighlighting/first/src/commonMain/kotlin/My.kt @@ -1,3 +1,3 @@ -expect class My { - fun foo() +expect class My { + fun foo() } \ No newline at end of file diff --git a/idea/testData/gradle/newMultiplatformHighlighting/first/src/jvmMain/kotlin/My.kt b/idea/testData/gradle/newMultiplatformHighlighting/first/src/jvmMain/kotlin/My.kt index 25d70fe1e89..ec1ab12b76a 100644 --- a/idea/testData/gradle/newMultiplatformHighlighting/first/src/jvmMain/kotlin/My.kt +++ b/idea/testData/gradle/newMultiplatformHighlighting/first/src/jvmMain/kotlin/My.kt @@ -1,5 +1,5 @@ -actual class My { - actual fun foo() {} +actual class My { + actual fun foo() {} actual fun bar() {} } \ No newline at end of file