diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt index 2d03b4da713..01ccc960b0d 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.cli.common.arguments @@ -50,7 +39,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() { @get:Transient var autoAdvanceApiVersion: Boolean by FreezableVar(true) - @GradleOption(DefaultValues.LanguageVersions::class) + @GradleOption(DefaultValues.ApiVersions::class) @Argument( value = "-api-version", valueDescription = "", @@ -548,13 +537,13 @@ abstract class CommonCompilerArguments : CommonToolArguments() { // If only "-language-version" is specified, API version is assumed to be equal to the language version // (API version cannot be greater than the language version) - val apiVersion = parseVersion(collector, apiVersion, "API") ?: languageVersion + val apiVersion = ApiVersion.createByLanguageVersion(parseVersion(collector, apiVersion, "API") ?: languageVersion) checkApiVersionIsNotGreaterThenLanguageVersion(languageVersion, apiVersion, collector) val languageVersionSettings = LanguageVersionSettingsImpl( languageVersion, - ApiVersion.createByLanguageVersion(apiVersion), + apiVersion, configureAnalysisFlags(collector, languageVersion), configureLanguageFeatures(collector) ) @@ -570,10 +559,10 @@ abstract class CommonCompilerArguments : CommonToolArguments() { private fun checkApiVersionIsNotGreaterThenLanguageVersion( languageVersion: LanguageVersion, - apiVersion: LanguageVersion, + apiVersion: ApiVersion, collector: MessageCollector ) { - if (apiVersion > languageVersion) { + if (apiVersion > ApiVersion.createByLanguageVersion(languageVersion)) { collector.report( CompilerMessageSeverity.ERROR, "-api-version (${apiVersion.versionString}) cannot be greater than -language-version (${languageVersion.versionString})" @@ -591,14 +580,14 @@ abstract class CommonCompilerArguments : CommonToolArguments() { } } - private fun checkOutdatedVersions(language: LanguageVersion, api: LanguageVersion, collector: MessageCollector) { - val (version, versionKind) = findOutdatedVersion(language, api) ?: return + private fun checkOutdatedVersions(language: LanguageVersion, api: ApiVersion, collector: MessageCollector) { + val (version, supportedVersion, versionKind) = findOutdatedVersion(language, api) ?: return when { version.isUnsupported -> { collector.report( CompilerMessageSeverity.ERROR, "${versionKind.text} version ${version.versionString} is no longer supported; " + - "please, use version ${LanguageVersion.OLDEST_DEPRECATED.versionString} or greater." + "please, use version ${supportedVersion!!.versionString} or greater." ) } version.isDeprecated -> { @@ -611,12 +600,12 @@ abstract class CommonCompilerArguments : CommonToolArguments() { } } - private fun findOutdatedVersion(language: LanguageVersion, api: LanguageVersion): Pair? { + private fun findOutdatedVersion(language: LanguageVersion, api: ApiVersion): Triple? { return when { - language.isUnsupported -> language to VersionKind.LANGUAGE - api.isUnsupported -> api to VersionKind.API - language.isDeprecated -> language to VersionKind.LANGUAGE - api.isDeprecated -> api to VersionKind.API + language.isUnsupported -> Triple(language, LanguageVersion.FIRST_SUPPORTED, VersionKind.LANGUAGE) + api.isUnsupported -> Triple(api, ApiVersion.FIRST_SUPPORTED, VersionKind.API) + language.isDeprecated -> Triple(language, null, VersionKind.LANGUAGE) + api.isDeprecated -> Triple(api, null, VersionKind.API) else -> null } } diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/DefaultValues.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/DefaultValues.kt index f9e09120399..693c2919265 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/DefaultValues.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/DefaultValues.kt @@ -1,23 +1,13 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.cli.common.arguments import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.CALL import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.NO_CALL +import org.jetbrains.kotlin.config.ApiVersion import org.jetbrains.kotlin.config.JvmTarget import org.jetbrains.kotlin.config.LanguageVersion @@ -37,6 +27,14 @@ open class DefaultValues(val defaultValue: String, val possibleValues: List, DescriptionAware { - val isStable: Boolean - get() = this <= ApiVersion.LATEST_STABLE + override val versionString: String +) : Comparable, DescriptionAware, LanguageOrApiVersion { - override val description: String - get() = if (isStable) versionString else "$versionString (EXPERIMENTAL)" + override val isStable: Boolean + get() = this <= LATEST_STABLE + + override val isDeprecated: Boolean + get() = FIRST_SUPPORTED <= this && this < FIRST_NON_DEPRECATED + + override val isUnsupported: Boolean + get() = this < FIRST_SUPPORTED override fun compareTo(other: ApiVersion): Int = version.compareTo(other.version) @@ -70,6 +63,12 @@ class ApiVersion private constructor( @JvmField val LATEST_STABLE: ApiVersion = createByLanguageVersion(LanguageVersion.LATEST_STABLE) + @JvmField + val FIRST_SUPPORTED: ApiVersion = createByLanguageVersion(LanguageVersion.FIRST_API_SUPPORTED) + + @JvmField + val FIRST_NON_DEPRECATED: ApiVersion = createByLanguageVersion(LanguageVersion.FIRST_NON_DEPRECATED) + @JvmStatic fun createByLanguageVersion(version: LanguageVersion): ApiVersion = parse(version.versionString)!! diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index 8fa59a5fa94..d6475df783a 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -326,7 +326,7 @@ enum class LanguageFeature( } } -enum class LanguageVersion(val major: Int, val minor: Int) : DescriptionAware { +enum class LanguageVersion(val major: Int, val minor: Int) : DescriptionAware, LanguageOrApiVersion { KOTLIN_1_0(1, 0), KOTLIN_1_1(1, 1), KOTLIN_1_2(1, 2), @@ -337,26 +337,18 @@ enum class LanguageVersion(val major: Int, val minor: Int) : DescriptionAware { KOTLIN_1_7(1, 7), ; - val isStable: Boolean + override val isStable: Boolean get() = this <= LATEST_STABLE - val isDeprecated: Boolean - get() = OLDEST_DEPRECATED <= this && this < FIRST_SUPPORTED + override val isDeprecated: Boolean + get() = FIRST_SUPPORTED <= this && this < FIRST_NON_DEPRECATED - val isUnsupported: Boolean - get() = this < OLDEST_DEPRECATED + override val isUnsupported: Boolean + get() = this < FIRST_SUPPORTED - val versionString: String + override val versionString: String get() = "$major.$minor" - override val description: String - get() = when { - !isStable -> "$versionString (EXPERIMENTAL)" - isDeprecated -> "$versionString (DEPRECATED)" - isUnsupported -> "$versionString (UNSUPPORTED)" - else -> versionString - } - override fun toString() = versionString companion object { @@ -367,17 +359,43 @@ enum class LanguageVersion(val major: Int, val minor: Int) : DescriptionAware { fun fromFullVersionString(str: String) = str.split(".", "-").let { if (it.size >= 2) fromVersionString("${it[0]}.${it[1]}") else null } - @JvmField - val OLDEST_DEPRECATED = KOTLIN_1_4 + // Version status + // 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 + // Language: UNSUPPORTED -------> DEPRECATED -> STABLE ---> EXPERIMENTAL + // API: UNSUPPORTED --> DEPRECATED ------> STABLE ---> EXPERIMENTAL @JvmField - val FIRST_SUPPORTED = KOTLIN_1_5 + val FIRST_API_SUPPORTED = KOTLIN_1_3 + + @JvmField + val FIRST_SUPPORTED = KOTLIN_1_4 + + @JvmField + val FIRST_NON_DEPRECATED = KOTLIN_1_5 @JvmField val LATEST_STABLE = KOTLIN_1_6 } } +interface LanguageOrApiVersion : DescriptionAware { + val versionString: String + + val isStable: Boolean + + val isDeprecated: Boolean + + val isUnsupported: Boolean + + override val description: String + get() = when { + !isStable -> "$versionString (EXPERIMENTAL)" + isDeprecated -> "$versionString (DEPRECATED)" + isUnsupported -> "$versionString (UNSUPPORTED)" + else -> versionString + } +} + fun LanguageVersion.isStableOrReadyForPreview(): Boolean = isStable diff --git a/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinCommonOptions.kt b/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinCommonOptions.kt index d342d88ace1..a9a82ebf074 100644 --- a/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinCommonOptions.kt +++ b/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinCommonOptions.kt @@ -7,7 +7,7 @@ interface KotlinCommonOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonToo /** * Allow using declarations only from the specified version of bundled libraries - * Possible values: "1.4 (DEPRECATED)", "1.5", "1.6", "1.7 (EXPERIMENTAL)" + * Possible values: "1.3 (DEPRECATED)", "1.4 (DEPRECATED)", "1.5", "1.6", "1.7 (EXPERIMENTAL)" * Default value: null */ var apiVersion: kotlin.String?