Kotlin Facet: Fix language/API version initialization
#KT-21180 Fixed
This commit is contained in:
+38
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user