From 8c84717cbc54fbaf139afcb9d6bd9aeff272949c Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Tue, 14 Feb 2017 14:44:56 +0300 Subject: [PATCH] Kotlin Facet: Reset all coroutine support flags before importing them frm Gradle --- .../jetbrains/kotlin/idea/facet/facetUtils.kt | 15 ++++-- .../gradle/GradleFacetImportTest.kt | 48 +++++++++++++++++++ 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt b/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt index 1fa56b75958..c882f473921 100644 --- a/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt @@ -231,11 +231,16 @@ fun parseCompilerArgumentsToFacet(arguments: List, defaultArguments: Lis commonCompilerArguments.coroutinesWarn = false commonCompilerArguments.coroutinesError = false + if (compilerArguments != commonCompilerArguments) { + compilerArguments.coroutinesEnable = false + compilerArguments.coroutinesWarn = false + compilerArguments.coroutinesError = false + } + parseArguments(argumentArray, compilerArguments, true) - if (!compilerArguments.coroutinesEnable && !compilerArguments.coroutinesWarn && !compilerArguments.coroutinesError) { - compilerInfo.coroutineSupport = oldCoroutineSupport - } + val restoreCoroutineSupport = + !compilerArguments.coroutinesEnable && !compilerArguments.coroutinesWarn && !compilerArguments.coroutinesError versionInfo.apiLevel = LanguageVersion.fromVersionString(compilerArguments.apiVersion) versionInfo.languageLevel = LanguageVersion.fromVersionString(compilerArguments.languageVersion) @@ -268,5 +273,9 @@ fun parseCompilerArgumentsToFacet(arguments: List, defaultArguments: Lis } copyInheritedFields(compilerArguments, commonCompilerArguments) + + if (restoreCoroutineSupport) { + compilerInfo.coroutineSupport = oldCoroutineSupport + } } } \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt index 60c7b4fae11..bfbfade9db4 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt @@ -109,6 +109,54 @@ class GradleFacetImportTest : GradleImportingTestCase() { } } + @Test + fun testFixCorruptedCoroutines() { + createProjectSubFile("build.gradle", """ + group 'Again' + version '1.0-SNAPSHOT' + + buildscript { + repositories { + mavenCentral() + maven { + url 'http://dl.bintray.com/kotlin/kotlin-eap-1.1' + } + } + + dependencies { + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0-beta-38") + } + } + + apply plugin: 'kotlin' + + dependencies { + compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0-beta-38" + } + + kotlin { + experimental { + coroutines 'enable' + } + } + """) + + importProject() + + with (facetSettings) { + compilerInfo.k2jvmCompilerArguments!!.coroutinesEnable = true + compilerInfo.k2jvmCompilerArguments!!.coroutinesWarn = true + compilerInfo.k2jvmCompilerArguments!!.coroutinesError = true + + importProject() + + Assert.assertEquals(CoroutineSupport.ENABLED, compilerInfo.coroutineSupport) + Assert.assertEquals(true, compilerInfo.k2jvmCompilerArguments!!.coroutinesEnable) + Assert.assertEquals(false, compilerInfo.k2jvmCompilerArguments!!.coroutinesWarn) + Assert.assertEquals(false, compilerInfo.k2jvmCompilerArguments!!.coroutinesError) + } + } + @Test fun testCoroutineImportByProperties() { createProjectSubFile("gradle.properties", "kotlin.coroutines=enable")