Report warning for non-boolean CLI argument passed multiple times

Only if its values are different, see the test
This commit is contained in:
Alexander Udalov
2017-04-06 16:15:28 +03:00
parent be54e4b93b
commit ff846e787f
17 changed files with 54 additions and 45 deletions
@@ -20,7 +20,9 @@ import com.intellij.util.SmartList;
import org.jetbrains.annotations.NotNull;
import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public abstract class CommonCompilerArguments implements Serializable {
public static final long serialVersionUID = 0L;
@@ -105,6 +107,10 @@ public abstract class CommonCompilerArguments implements Serializable {
// Names of extra (-X...) arguments which have been passed in an obsolete form ("-Xaaa bbb", instead of "-Xaaa=bbb")
public List<String> extraArgumentsPassedInObsoleteForm = new SmartList<>();
// Non-boolean arguments which have been passed multiple times, possibly with different values.
// The key in the map is the name of the argument, the value is the last passed value.
public Map<String, String> duplicateArguments = new LinkedHashMap<>();
@NotNull
public static CommonCompilerArguments createDefaultInstance() {
return new DummyImpl();
@@ -30,6 +30,7 @@ val Argument.isAdvanced: Boolean
private val ADVANCED_ARGUMENT_PREFIX = "-X"
// Parses arguments in the passed [result] object, or throws an [IllegalArgumentException] with the message to be displayed to the user
fun <A : CommonCompilerArguments> parseCommandLineArguments(args: Array<String>, result: A) {
data class ArgumentField(val field: Field, val argument: Argument)
@@ -38,6 +39,8 @@ fun <A : CommonCompilerArguments> parseCommandLineArguments(args: Array<String>,
if (argument != null) ArgumentField(field, argument) else null
}
val visitedArgs = mutableSetOf<String>()
var i = 0
while (i < args.size) {
val arg = args[i++]
@@ -74,6 +77,10 @@ fun <A : CommonCompilerArguments> parseCommandLineArguments(args: Array<String>,
}
}
if (!field.type.isArray && !visitedArgs.add(argument.value) && value is String && field.get(result) != value) {
result.duplicateArguments.put(argument.value, value)
}
updateField(field, result, value)
}
}
@@ -136,7 +136,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
messageCollector = new FilteringMessageCollector(messageCollector, Predicate.isEqual(WARNING));
}
reportUnknownAndObsoleteExtraFlags(messageCollector, arguments);
reportArgumentParseProblems(messageCollector, arguments);
GroupingMessageCollector groupingCollector = new GroupingMessageCollector(messageCollector);
@@ -311,7 +311,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
@NotNull CompilerConfiguration configuration, @NotNull A arguments, @NotNull Services services
);
private void reportUnknownAndObsoleteExtraFlags(@NotNull MessageCollector collector, @NotNull A arguments) {
private void reportArgumentParseProblems(@NotNull MessageCollector collector, @NotNull A arguments) {
for (String flag : arguments.unknownExtraFlags) {
collector.report(STRONG_WARNING, "Flag is not supported by this version of the compiler: " + flag, null);
}
@@ -319,6 +319,10 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
collector.report(STRONG_WARNING, "Advanced option value is passed in an obsolete form. Please use the '=' character " +
"to specify the value: " + argument + "=...", null);
}
for (Map.Entry<String, String> argument : arguments.duplicateArguments.entrySet()) {
collector.report(STRONG_WARNING, "Argument " + argument.getKey() + " is passed multiple times. " +
"Only the last value will be used: " + argument.getValue(), null);
}
}
@NotNull