Kotlin Facet: Reset all coroutine support flags before importing them frm Gradle

This commit is contained in:
Alexey Sedunov
2017-02-14 14:44:56 +03:00
parent a2e429a912
commit 8c84717cbc
2 changed files with 60 additions and 3 deletions
@@ -231,11 +231,16 @@ fun parseCompilerArgumentsToFacet(arguments: List<String>, 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<String>, defaultArguments: Lis
}
copyInheritedFields(compilerArguments, commonCompilerArguments)
if (restoreCoroutineSupport) {
compilerInfo.coroutineSupport = oldCoroutineSupport
}
}
}
@@ -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")