Drop cli-parser, use simple reflection-based parser instead
The main reason of this change is that major changes are required in how command line arguments are parsed in kotlinc, and it's much easier to make them in our own codebase (given that the code is short and simple enough) than in a third-party library
This commit is contained in:
@@ -16,16 +16,16 @@
|
||||
|
||||
package org.jetbrains.kotlin.compilerRunner;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ComparatorUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.Argument;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments;
|
||||
import org.jetbrains.kotlin.cli.common.parser.com.sampullara.cli.Argument;
|
||||
import org.jetbrains.kotlin.utils.StringsKt;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ArgumentUtils {
|
||||
private ArgumentUtils() {}
|
||||
@@ -60,23 +60,17 @@ public class ArgumentUtils {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ComparatorUtil.equalsNullable(value, defaultValue)) continue;
|
||||
|
||||
String name = getAlias(argument);
|
||||
if (name == null) {
|
||||
name = getName(argument, field);
|
||||
}
|
||||
if (Objects.equals(value, defaultValue)) continue;
|
||||
|
||||
Class<?> fieldType = field.getType();
|
||||
|
||||
if (fieldType.isArray()) {
|
||||
Object[] values = (Object[]) value;
|
||||
if (values.length == 0) continue;
|
||||
//noinspection unchecked
|
||||
value = StringUtil.join(values, Function.TO_STRING, argument.delimiter());
|
||||
value = StringsKt.join(Arrays.asList(values), ",");
|
||||
}
|
||||
|
||||
result.add(argument.prefix() + name);
|
||||
result.add(argument.value());
|
||||
|
||||
if (fieldType == boolean.class || fieldType == Boolean.class) continue;
|
||||
|
||||
@@ -88,14 +82,4 @@ public class ArgumentUtils {
|
||||
convertArgumentsToStringList(arguments, defaultArguments, superClazz, result);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getAlias(Argument argument) {
|
||||
String alias = argument.alias();
|
||||
return alias.isEmpty() ? null : alias;
|
||||
}
|
||||
|
||||
private static String getName(Argument argument, Field field) {
|
||||
String name = argument.value();
|
||||
return name.isEmpty() ? field.getName() : name;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user