Kotlin Facet: Fix language/API version initialization

#KT-21180 Fixed
This commit is contained in:
Alexey Sedunov
2017-11-17 15:46:36 +03:00
parent 200d7f0718
commit 3f66d11624
2 changed files with 43 additions and 2 deletions
@@ -29,6 +29,7 @@ import com.intellij.openapi.util.text.StringUtil
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinStatus
import org.jetbrains.kotlin.idea.configuration.ModuleSourceRootMap
import org.jetbrains.kotlin.idea.configuration.allConfigurators
@@ -1618,6 +1619,43 @@ compileTestKotlin {
assertAllModulesConfigured()
}
@Test
fun testIgnoreProjectLanguageAndAPIVersion() {
KotlinCommonCompilerArgumentsHolder.getInstance(myProject).update {
languageVersion = "1.0"
apiVersion = "1.0"
}
createProjectSubFile("build.gradle", """
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")
}
}
apply plugin: 'kotlin'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0"
}
""")
importProject()
with (facetSettings) {
Assert.assertEquals("1.1", languageLevel!!.versionString)
Assert.assertEquals("1.1", apiLevel!!.versionString)
}
assertAllModulesConfigured()
}
private fun assertAllModulesConfigured() {
runReadAction {
for (moduleGroup in ModuleSourceRootMap(myProject).groupByBaseModules(myProject.allModules())) {
@@ -68,6 +68,9 @@ fun KotlinFacetSettings.initializeIfNeeded(
) {
val project = module.project
val shouldInferLanguageLevel = languageLevel == null
val shouldInferAPILevel = apiLevel == null
if (compilerSettings == null) {
compilerSettings = KotlinCompilerSettings.getInstance(project).settings
}
@@ -82,12 +85,12 @@ fun KotlinFacetSettings.initializeIfNeeded(
}
}
if (languageLevel == null) {
if (shouldInferLanguageLevel) {
languageLevel = (if (useProjectSettings) LanguageVersion.fromVersionString(commonArguments.languageVersion) else null)
?: getDefaultLanguageLevel(module, languageVersion)
}
if (apiLevel == null) {
if (shouldInferAPILevel) {
apiLevel = if (useProjectSettings) {
LanguageVersion.fromVersionString(commonArguments.apiVersion) ?: languageLevel
}