diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/gradle/GradleMultiplatformHighlightingTest.kt b/idea/idea-gradle/tests/org/jetbrains/kotlin/gradle/GradleMultiplatformHighlightingTest.kt new file mode 100644 index 00000000000..d41cba4ad10 --- /dev/null +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/gradle/GradleMultiplatformHighlightingTest.kt @@ -0,0 +1,91 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.gradle + +import com.intellij.codeInsight.EditorInfo +import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase +import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.editor.impl.EditorImpl +import com.intellij.openapi.fileEditor.FileEditorManager +import com.intellij.openapi.fileEditor.OpenFileDescriptor +import com.intellij.openapi.project.Project +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.psi.PsiDocumentManager +import org.jetbrains.kotlin.idea.codeInsight.gradle.GradleImportingTestCase +import org.jetbrains.kotlin.test.testFramework.runInEdtAndWait +import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions +import org.junit.Assert +import org.junit.Test + +class GradleMultiplatformHighlightingTest : GradleImportingTestCase() { + + @TargetVersions("4.7+") + @Test + fun testFirst() { + val files = importProjectFromTestData() + val project = myTestFixture.project + + checkFiles(files, project) { editor -> + daemonAnalyzerTestCase.checkHighlighting(editor, project) + } + + } + + private val daemonAnalyzerTestCase = object : DaemonAnalyzerTestCase() { + fun checkHighlighting(editor: Editor, project: Project) { + myProject = project + runInEdtAndWait { + checkHighlighting(editor, /* checkWarnings = */ true, /* checkInfos = */ false) + } + } + } + + 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) + atLeastOneFile = true + check(editor) + } + Assert.assertTrue(atLeastOneFile) + } + + private fun configureEditorByExistingFile(virtualFile: VirtualFile, project: Project): Editor { + var result: Editor? = null + runInEdtAndWait { + val editor = createEditor(virtualFile, project) + val document = editor.document + val editorInfo = EditorInfo(document.text) + val newFileText = editorInfo.newFileText + ApplicationManager.getApplication().runWriteAction { + if (document.text != newFileText) { + document.setText(newFileText) + } + + editorInfo.applyToEditor(editor) + } + PsiDocumentManager.getInstance(project).commitAllDocuments() + result = editor + } + return result!! + } + + private fun createEditor(file: VirtualFile, project: Project): Editor { + val instance = FileEditorManager.getInstance(this.myProject) + PsiDocumentManager.getInstance(project).commitAllDocuments() + val editor = instance.openTextEditor(OpenFileDescriptor(this.myProject, file, 0), false) + (editor as EditorImpl).setCaretActive() + PsiDocumentManager.getInstance(project).commitAllDocuments() + DaemonCodeAnalyzer.getInstance(project).restart() + return editor + } + + override fun testDataDirName(): String { + return "newMultiplatformHighlighting" + } +} \ No newline at end of file diff --git a/idea/testData/gradle/newMultiplatformHighlighting/first/build.gradle b/idea/testData/gradle/newMultiplatformHighlighting/first/build.gradle new file mode 100644 index 00000000000..29adfe9c1e3 --- /dev/null +++ b/idea/testData/gradle/newMultiplatformHighlighting/first/build.gradle @@ -0,0 +1,30 @@ +plugins { + id 'kotlin-multiplatform' version '1.3.0' +} +repositories { + mavenCentral() + jcenter() +} +kotlin { + targets { + fromPreset(presets.jvm, 'jvm') + fromPreset(presets.js, 'js') + } + sourceSets { + commonMain { + dependencies { + implementation 'org.jetbrains.kotlin:kotlin-stdlib-common' + } + } + jvmMain { + dependencies { + implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' + } + } + jsMain { + dependencies { + implementation 'org.jetbrains.kotlin:kotlin-stdlib-js' + } + } + } +} diff --git a/idea/testData/gradle/newMultiplatformHighlighting/first/settings.gradle b/idea/testData/gradle/newMultiplatformHighlighting/first/settings.gradle new file mode 100644 index 00000000000..22d979e37ee --- /dev/null +++ b/idea/testData/gradle/newMultiplatformHighlighting/first/settings.gradle @@ -0,0 +1,18 @@ +pluginManagement { + resolutionStrategy { + eachPlugin { + if (requested.id.id == "kotlin-multiplatform") { + useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}") + } + } + } + + repositories { + mavenCentral() + + maven { url 'https://plugins.gradle.org/m2/' } + + jcenter() + } +} +rootProject.name = 'first' \ No newline at end of file diff --git a/idea/testData/gradle/newMultiplatformHighlighting/first/src/commonMain/kotlin/My.kt b/idea/testData/gradle/newMultiplatformHighlighting/first/src/commonMain/kotlin/My.kt new file mode 100644 index 00000000000..13cbde660aa --- /dev/null +++ b/idea/testData/gradle/newMultiplatformHighlighting/first/src/commonMain/kotlin/My.kt @@ -0,0 +1,3 @@ +expect class My { + fun foo() +} \ No newline at end of file diff --git a/idea/testData/gradle/newMultiplatformHighlighting/first/src/jsMain/kotlin/foo.kt b/idea/testData/gradle/newMultiplatformHighlighting/first/src/jsMain/kotlin/foo.kt new file mode 100644 index 00000000000..f209aeca5e6 --- /dev/null +++ b/idea/testData/gradle/newMultiplatformHighlighting/first/src/jsMain/kotlin/foo.kt @@ -0,0 +1 @@ +fun foo() = "Java Script" \ 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 new file mode 100644 index 00000000000..25d70fe1e89 --- /dev/null +++ b/idea/testData/gradle/newMultiplatformHighlighting/first/src/jvmMain/kotlin/My.kt @@ -0,0 +1,5 @@ +actual class My { + actual fun foo() {} + + actual fun bar() {} +} \ No newline at end of file