Refactor LanguageVersionSettings.isApiVersionExplicit
Pass it in the CompilerConfiguration instead of LanguageVersionSettings. This is better because LanguageVersionSettings is accessible everywhere in front-end and back-end, and this flag should not be used there
This commit is contained in:
@@ -247,11 +247,15 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
|||||||
// If only "-api-version" is specified, language version is assumed to be the latest
|
// If only "-api-version" is specified, language version is assumed to be the latest
|
||||||
languageVersion = LanguageVersion.LATEST;
|
languageVersion = LanguageVersion.LATEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apiVersion == null) {
|
if (apiVersion == null) {
|
||||||
// If only "-language-version" is specified, API version is assumed to be equal to the language version
|
// 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)
|
// (API version cannot be greater than the language version)
|
||||||
apiVersion = languageVersion;
|
apiVersion = languageVersion;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
configuration.put(CLIConfigurationKeys.IS_API_VERSION_EXPLICIT, true);
|
||||||
|
}
|
||||||
|
|
||||||
if (apiVersion.compareTo(languageVersion) > 0) {
|
if (apiVersion.compareTo(languageVersion) > 0) {
|
||||||
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(
|
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(
|
||||||
@@ -281,8 +285,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
|||||||
languageVersion,
|
languageVersion,
|
||||||
ApiVersion.createByLanguageVersion(apiVersion),
|
ApiVersion.createByLanguageVersion(apiVersion),
|
||||||
arguments.skipMetadataVersionCheck,
|
arguments.skipMetadataVersionCheck,
|
||||||
extraLanguageFeatures,
|
extraLanguageFeatures
|
||||||
arguments.apiVersion != null
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ public class CLIConfigurationKeys {
|
|||||||
CompilerConfigurationKey.create("allow kotlin package");
|
CompilerConfigurationKey.create("allow kotlin package");
|
||||||
public static final CompilerConfigurationKey<Boolean> REPORT_PERF =
|
public static final CompilerConfigurationKey<Boolean> REPORT_PERF =
|
||||||
CompilerConfigurationKey.create("report performance information");
|
CompilerConfigurationKey.create("report performance information");
|
||||||
|
public static final CompilerConfigurationKey<Boolean> IS_API_VERSION_EXPLICIT =
|
||||||
|
CompilerConfigurationKey.create("is API version explicit");
|
||||||
|
|
||||||
// Used in Eclipse plugin (see KotlinCLICompiler)
|
// Used in Eclipse plugin (see KotlinCLICompiler)
|
||||||
public static final CompilerConfigurationKey<CompilerJarLocator> COMPILER_JAR_LOCATOR =
|
public static final CompilerConfigurationKey<CompilerJarLocator> COMPILER_JAR_LOCATOR =
|
||||||
|
|||||||
+2
-1
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.cli.jvm
|
|||||||
import com.intellij.openapi.diagnostic.Logger
|
import com.intellij.openapi.diagnostic.Logger
|
||||||
import com.intellij.openapi.vfs.VfsUtilCore
|
import com.intellij.openapi.vfs.VfsUtilCore
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
|
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||||
@@ -120,7 +121,7 @@ object JvmRuntimeVersionsConsistencyChecker {
|
|||||||
val actualApi = ApiVersion.parse(actualRuntimeVersion.toString())
|
val actualApi = ApiVersion.parse(actualRuntimeVersion.toString())
|
||||||
if (actualApi != null) {
|
if (actualApi != null) {
|
||||||
val inferredApiVersion =
|
val inferredApiVersion =
|
||||||
if (@Suppress("DEPRECATION") languageVersionSettings.isApiVersionExplicit)
|
if (configuration.getBoolean(CLIConfigurationKeys.IS_API_VERSION_EXPLICIT))
|
||||||
languageVersionSettings.apiVersion
|
languageVersionSettings.apiVersion
|
||||||
else
|
else
|
||||||
// "minOf" is needed in case when API version was inferred from language version and it's older than actualApi.
|
// "minOf" is needed in case when API version was inferred from language version and it's older than actualApi.
|
||||||
|
|||||||
@@ -109,9 +109,6 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
|||||||
languageFeatures[feature] ?: delegate.getFeatureSupport(feature)
|
languageFeatures[feature] ?: delegate.getFeatureSupport(feature)
|
||||||
|
|
||||||
override val skipMetadataVersionCheck: Boolean get() = false
|
override val skipMetadataVersionCheck: Boolean get() = false
|
||||||
|
|
||||||
override val isApiVersionExplicit: Boolean
|
|
||||||
get() = error("Must not be called")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class TestFile(
|
inner class TestFile(
|
||||||
|
|||||||
@@ -112,17 +112,13 @@ interface LanguageVersionSettings {
|
|||||||
val languageVersion: LanguageVersion
|
val languageVersion: LanguageVersion
|
||||||
|
|
||||||
val skipMetadataVersionCheck: Boolean
|
val skipMetadataVersionCheck: Boolean
|
||||||
|
|
||||||
@Deprecated("This is a temporary solution, please do not use.")
|
|
||||||
val isApiVersionExplicit: Boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class LanguageVersionSettingsImpl @JvmOverloads constructor(
|
class LanguageVersionSettingsImpl @JvmOverloads constructor(
|
||||||
override val languageVersion: LanguageVersion,
|
override val languageVersion: LanguageVersion,
|
||||||
override val apiVersion: ApiVersion,
|
override val apiVersion: ApiVersion,
|
||||||
override val skipMetadataVersionCheck: Boolean = false,
|
override val skipMetadataVersionCheck: Boolean = false,
|
||||||
private val specificFeatures: Map<LanguageFeature, LanguageFeature.State> = emptyMap(),
|
private val specificFeatures: Map<LanguageFeature, LanguageFeature.State> = emptyMap()
|
||||||
override val isApiVersionExplicit: Boolean = false
|
|
||||||
) : LanguageVersionSettings {
|
) : LanguageVersionSettings {
|
||||||
override fun getFeatureSupport(feature: LanguageFeature): LanguageFeature.State {
|
override fun getFeatureSupport(feature: LanguageFeature): LanguageFeature.State {
|
||||||
specificFeatures[feature]?.let { return it }
|
specificFeatures[feature]?.let { return it }
|
||||||
|
|||||||
Reference in New Issue
Block a user