Get rid of coroutinesWarn/coroutinesEnable/coroutinesError

Use a single coroutinesState instead. Change the coroutines state in
some tests from "warn" to "enable"/"error" to test that deserialization
of older config files works ("warn" is the default value, so it wasn't
testing anything here)
This commit is contained in:
Alexander Udalov
2017-04-05 19:00:53 +03:00
parent f4b6db4dc0
commit be54e4b93b
20 changed files with 194 additions and 164 deletions
@@ -91,14 +91,12 @@ public abstract class CommonCompilerArguments implements Serializable {
@Argument(value = "-Xno-check-impl", description = "Do not check presence of 'impl' modifier in multi-platform projects")
public boolean noCheckImpl;
@Argument(value = "-Xcoroutines=warn", description = "")
public boolean coroutinesWarn;
@Argument(value = "-Xcoroutines=error", description = "")
public boolean coroutinesError;
@Argument(value = "-Xcoroutines=enable", description = "")
public boolean coroutinesEnable;
@Argument(
value = "-Xcoroutines",
valueDescription = "{enable|warn|error}",
description = "Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier"
)
public String coroutinesState = WARN;
public List<String> freeArgs = new SmartList<>();
@@ -109,11 +107,7 @@ public abstract class CommonCompilerArguments implements Serializable {
@NotNull
public static CommonCompilerArguments createDefaultInstance() {
DummyImpl arguments = new DummyImpl();
arguments.coroutinesEnable = false;
arguments.coroutinesWarn = true;
arguments.coroutinesError = false;
return arguments;
return new DummyImpl();
}
@NotNull
@@ -121,6 +115,10 @@ public abstract class CommonCompilerArguments implements Serializable {
return "kotlinc";
}
public static final String WARN = "warn";
public static final String ERROR = "error";
public static final String ENABLE = "enable";
// Used only for serialize and deserialize settings. Don't use in other places!
public static final class DummyImpl extends CommonCompilerArguments {}
}
@@ -275,19 +275,17 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
@NotNull CompilerConfiguration configuration,
@NotNull CommonCompilerArguments arguments
) {
if (arguments.coroutinesError && !arguments.coroutinesWarn && !arguments.coroutinesEnable) {
return LanguageFeature.State.ENABLED_WITH_ERROR;
}
else if (arguments.coroutinesEnable && !arguments.coroutinesWarn && !arguments.coroutinesError) {
return LanguageFeature.State.ENABLED;
}
else if (!arguments.coroutinesEnable && !arguments.coroutinesError) {
return null;
}
else {
String message = "The -Xcoroutines can only have one value";
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(ERROR, message, null);
return null;
switch (arguments.coroutinesState) {
case CommonCompilerArguments.ERROR:
return LanguageFeature.State.ENABLED_WITH_ERROR;
case CommonCompilerArguments.ENABLE:
return LanguageFeature.State.ENABLED;
case CommonCompilerArguments.WARN:
return null;
default:
String message = "Invalid value of -Xcoroutines (should be: enable, warn or error): " + arguments.coroutinesState;
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(ERROR, message, null);
return null;
}
}
@@ -29,20 +29,13 @@ 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 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) {
if (usage.contains("Xcoroutines")) {
if (coroutinesUsagePrinted) continue;
coroutinesUsagePrinted = true;
}
target.println(usage);
}
}
@@ -59,14 +52,10 @@ class Usage {
Argument argument = field.getAnnotation(Argument.class);
if (argument == null) return null;
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}" : argumentValue;
if (extraHelp != ParseCommandLineArgumentsKt.isAdvanced(argument)) return null;
StringBuilder sb = new StringBuilder(" ");
sb.append(value);
sb.append(argument.value());
if (!argument.shortName().isEmpty()) {
sb.append(" (");
@@ -79,12 +68,6 @@ class Usage {
sb.append(argument.valueDescription());
}
if (isXCoroutinesKey) {
sb.append(" ");
sb.append(coroutinesKeyDescription);
return sb.toString();
}
int width = OPTION_NAME_PADDING_WIDTH - 1;
if (sb.length() >= width + 5) { // Break the line if it's too long
sb.append("\n");