Introduce LanguageFeature.State, drop coroutines-related pseudofeatures
Previously there were three LanguageFeature instances -- Coroutines, DoNotWarnOnCoroutines and ErrorOnCoroutines -- which were handled very awkwardly in the compiler and in the IDE to basically support a language feature with a more complex state: not just enabled/disabled, but also enabled with warning and enabled with error. Introduce a new enum LanguageFeature.State for this and allow LanguageVersionSettings to get the state of any language feature with 'getFeatureSupport'. One noticeable drawback of this approach is that looking at the API, one may assume that any language feature can be in one of the four states (enabled, warning, error, disabled). This is not true however; there's only one language feature at the moment (coroutines) for which these intermediate states (warning, error) are handled in any way. This may be refactored further by abstracting the logic that checks the language feature availability so that it would work exactly the same for any feature. Another issue is that the difference among ENABLED_WITH_ERROR and DISABLED is not clear. They are left as separate states because at the moment, different diagnostics are reported in these two cases and quick-fixes in IDE rely on that
This commit is contained in:
@@ -40,8 +40,9 @@ import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStat
|
||||
import org.jetbrains.kotlin.utils.StringsKt;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.jetbrains.kotlin.cli.common.ExitCode.*;
|
||||
@@ -261,17 +262,17 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
);
|
||||
}
|
||||
|
||||
List<LanguageFeature> extraLanguageFeatures = new ArrayList<LanguageFeature>(0);
|
||||
Map<LanguageFeature, LanguageFeature.State> extraLanguageFeatures = new HashMap<LanguageFeature, LanguageFeature.State>(0);
|
||||
if (arguments.multiPlatform) {
|
||||
extraLanguageFeatures.add(LanguageFeature.MultiPlatformProjects);
|
||||
extraLanguageFeatures.put(LanguageFeature.MultiPlatformProjects, LanguageFeature.State.ENABLED);
|
||||
}
|
||||
if (arguments.noCheckImpl) {
|
||||
extraLanguageFeatures.add(LanguageFeature.MultiPlatformDoNotCheckImpl);
|
||||
extraLanguageFeatures.put(LanguageFeature.MultiPlatformDoNotCheckImpl, LanguageFeature.State.ENABLED);
|
||||
}
|
||||
|
||||
LanguageFeature coroutinesApplicabilityLevel = chooseCoroutinesApplicabilityLevel(configuration, arguments);
|
||||
if (coroutinesApplicabilityLevel != null) {
|
||||
extraLanguageFeatures.add(coroutinesApplicabilityLevel);
|
||||
LanguageFeature.State coroutinesState = chooseCoroutinesApplicabilityLevel(configuration, arguments);
|
||||
if (coroutinesState != null) {
|
||||
extraLanguageFeatures.put(LanguageFeature.Coroutines, coroutinesState);
|
||||
}
|
||||
|
||||
CommonConfigurationKeysKt.setLanguageVersionSettings(
|
||||
@@ -287,15 +288,15 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static LanguageFeature chooseCoroutinesApplicabilityLevel(
|
||||
private static LanguageFeature.State chooseCoroutinesApplicabilityLevel(
|
||||
@NotNull CompilerConfiguration configuration,
|
||||
@NotNull CommonCompilerArguments arguments
|
||||
) {
|
||||
if (arguments.coroutinesError && !arguments.coroutinesWarn && !arguments.coroutinesEnable) {
|
||||
return LanguageFeature.ErrorOnCoroutines;
|
||||
return LanguageFeature.State.ENABLED_WITH_ERROR;
|
||||
}
|
||||
else if (arguments.coroutinesEnable && !arguments.coroutinesWarn && !arguments.coroutinesError) {
|
||||
return LanguageFeature.DoNotWarnOnCoroutines;
|
||||
return LanguageFeature.State.ENABLED;
|
||||
}
|
||||
else if (!arguments.coroutinesEnable && !arguments.coroutinesError) {
|
||||
return null;
|
||||
|
||||
+5
-9
@@ -123,17 +123,13 @@ object JvmRuntimeVersionsConsistencyChecker {
|
||||
if (@Suppress("DEPRECATION") languageVersionSettings.isApiVersionExplicit)
|
||||
languageVersionSettings.apiVersion
|
||||
else
|
||||
// "minOf" is needed in case when API version was inferred from language version and it's older than actualApi.
|
||||
// For example, in "kotlinc-1.2 -language-version 1.0 -cp kotlin-runtime-1.1.jar" we should still infer API = 1.0
|
||||
minOf(languageVersionSettings.apiVersion, actualApi)
|
||||
|
||||
// "minOf" is needed in case when API version was inferred from language version and it's older than actualApi.
|
||||
// For example, in "kotlinc-1.2 -language-version 1.0 -cp kotlin-runtime-1.1.jar" we should still infer API = 1.0
|
||||
val newSettings = LanguageVersionSettingsImpl(
|
||||
languageVersionSettings.languageVersion,
|
||||
inferredApiVersion,
|
||||
languageVersionSettings.skipMetadataVersionCheck,
|
||||
languageVersionSettings.additionalFeatures,
|
||||
isApiVersionExplicit = false
|
||||
)
|
||||
val newSettings = object : LanguageVersionSettings by languageVersionSettings {
|
||||
override val apiVersion: ApiVersion get() = inferredApiVersion
|
||||
}
|
||||
|
||||
messageCollector.issue(null, "Old runtime has been found in the classpath. " +
|
||||
"Initial language version settings: $languageVersionSettings. " +
|
||||
|
||||
Reference in New Issue
Block a user