Introduce keys to control applicability of coroutines

By default now we produce warnings on coroutines
This commit is contained in:
Mikhail Zarechenskiy
2016-12-14 15:22:41 +03:00
committed by Stanislav Erokhin
parent 30710955dc
commit 664485f4bb
25 changed files with 228 additions and 10 deletions
@@ -285,12 +285,41 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
extraLanguageFeatures.add(LanguageFeature.MultiPlatformDoNotCheckImpl);
}
LanguageFeature coroutinesApplicabilityLevel = chooseCoroutinesApplicabilityLevel(configuration, arguments);
if (coroutinesApplicabilityLevel != null) {
extraLanguageFeatures.add(coroutinesApplicabilityLevel);
}
configuration.put(
CommonConfigurationKeys.LANGUAGE_VERSION_SETTINGS,
new LanguageVersionSettingsImpl(languageVersion, ApiVersion.createByLanguageVersion(apiVersion), extraLanguageFeatures)
);
}
@Nullable
private static LanguageFeature chooseCoroutinesApplicabilityLevel(
@NotNull CompilerConfiguration configuration, @NotNull CommonCompilerArguments arguments) {
if (!arguments.coroutinesEnable && !arguments.coroutinesError && !arguments.coroutinesWarn) {
return LanguageFeature.WarnOnCoroutines;
}
else if (arguments.coroutinesError && !arguments.coroutinesWarn && !arguments.coroutinesEnable) {
return LanguageFeature.ErrorOnCoroutines;
}
else if (arguments.coroutinesWarn && !arguments.coroutinesError && !arguments.coroutinesEnable) {
return LanguageFeature.WarnOnCoroutines;
}
else if (arguments.coroutinesEnable && !arguments.coroutinesWarn && !arguments.coroutinesError) {
return null;
} else {
String message = "The -Xcoroutines can only have one value";
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(
CompilerMessageSeverity.ERROR, message, CompilerMessageLocation.NO_LOCATION
);
return null;
}
}
@Nullable
private static LanguageVersion parseVersion(
@NotNull CompilerConfiguration configuration, @Nullable String value, @NotNull String versionOf
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 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.
@@ -29,13 +29,22 @@ class Usage {
// The magic number 29 corresponds to the similar padding width in javac and scalac command line compilers
private static final int OPTION_NAME_PADDING_WIDTH = 29;
private static final String coroutinesKeyDescription = "Enable coroutines or report warnings or report errors on declarations and use sites of suspend modifier";
public static void print(@NotNull PrintStream target, @NotNull CommonCompilerArguments arguments, boolean extraHelp) {
target.println("Usage: " + arguments.executableScriptFileName() + " <options> <source files>");
target.println("where " + (extraHelp ? "advanced" : "possible") + " options include:");
boolean coroutinesUsagePrinted = false;
for (Class<?> clazz = arguments.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
for (Field field : clazz.getDeclaredFields()) {
String usage = fieldUsage(field, extraHelp);
if (usage != null) {
boolean coroutinesUsage = usage.contains("Xcoroutines");
if (coroutinesUsage && coroutinesUsagePrinted) {
continue;
} else if (coroutinesUsage) {
coroutinesUsagePrinted = true;
}
target.println(usage);
}
}
@@ -51,9 +60,13 @@ class Usage {
private static String fieldUsage(@NotNull Field field, boolean extraHelp) {
Argument argument = field.getAnnotation(Argument.class);
if (argument == null) return null;
ValueDescription description = field.getAnnotation(ValueDescription.class);
String value = argument.value();
String argumentValue = argument.value();
// TODO: this is a dirty hack, provide better mechanism for keys that can have several values
boolean isXCoroutinesKey = argumentValue.contains("Xcoroutines");
String value = isXCoroutinesKey ? "Xcoroutines={enable|warn|error}" : argument.value();
boolean extraOption = value.startsWith("X") && value.length() > 1;
if (extraHelp != extraOption) return null;
@@ -73,6 +86,11 @@ class Usage {
sb.append(description.value());
}
if (isXCoroutinesKey) {
sb.append(" ");
sb.append(coroutinesKeyDescription);
}
int width = OPTION_NAME_PADDING_WIDTH - 1;
if (sb.length() >= width + 5) { // Break the line if it's too long
sb.append("\n");