Configuration: Support selection of "Latest stable" version vs specific one

#KT-21229 Fixed
This commit is contained in:
Alexey Sedunov
2017-12-06 13:42:13 +03:00
parent 5252cd4da4
commit 38d3362bcb
42 changed files with 286 additions and 62 deletions
@@ -21,45 +21,37 @@ import com.intellij.openapi.project.Project
import com.intellij.util.text.VersionComparatorUtil
import org.jdom.Element
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.config.LanguageVersion
import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_COMMON_COMPILER_ARGUMENTS_SECTION
import org.jetbrains.kotlin.config.getOption
import org.jetbrains.kotlin.config.detectVersionAutoAdvance
import org.jetbrains.kotlin.config.dropVersionsIfNecessary
@State(name = KOTLIN_COMMON_COMPILER_ARGUMENTS_SECTION,
storages = arrayOf(Storage(file = StoragePathMacros.PROJECT_FILE),
Storage(file = BaseKotlinCompilerSettings.KOTLIN_COMPILER_SETTINGS_PATH,
scheme = StorageScheme.DIRECTORY_BASED)))
class KotlinCommonCompilerArgumentsHolder(project: Project) : BaseKotlinCompilerSettings<CommonCompilerArguments>(project) {
private fun Element.dropElementIfDefault() {
if (DEFAULT_LANGUAGE_VERSION == getAttribute("value")?.value) {
detach()
}
}
override fun getState(): Element {
return super.getState().apply {
// Do not serialize language/api version if they correspond to the default language version
getOption("languageVersion")?.dropElementIfDefault()
getOption("apiVersion")?.dropElementIfDefault()
dropVersionsIfNecessary(settings)
}
}
override fun loadState(state: Element) {
super.loadState(state)
// To fix earlier configurations with incorrect combination of language and API version
update {
// To fix earlier configurations with incorrect combination of language and API version
if (VersionComparatorUtil.compare(languageVersion, apiVersion) < 0) {
apiVersion = languageVersion
}
detectVersionAutoAdvance()
}
}
override fun createSettings() = CommonCompilerArguments.DummyImpl()
companion object {
private val DEFAULT_LANGUAGE_VERSION = LanguageVersion.LATEST_STABLE.versionString
fun getInstance(project: Project) =
ServiceManager.getService<KotlinCommonCompilerArgumentsHolder>(project, KotlinCommonCompilerArgumentsHolder::class.java)!!
}