use of com.beust.jcommander.Parameterized in project jslint4java by happygiraffe.
the class Main method processOptions.
private List<String> processOptions(String[] args) {
JSLintFlags jslintFlags = new JSLintFlags();
Flags flags = new Flags();
JCommander jc = new JCommander(new Object[] { flags, jslintFlags });
jc.setProgramName(FULL_PROGRAM_NAME);
try {
jc.parse(args);
} catch (ParameterException e) {
info(e.getMessage());
usage(jc);
}
if (flags.version) {
version();
}
if (flags.help) {
usage(jc);
}
if (flags.encoding != null) {
encoding = flags.encoding;
}
lint = makeLint(flags);
setResultFormatter(flags.report);
for (ParameterDescription pd : jc.getParameters()) {
Parameterized p = pd.getParameterized();
// Is it declared on JSLintFlags?
if (!pd.getObject().getClass().isAssignableFrom(JSLintFlags.class)) {
continue;
}
try {
// Need to get Option.
Option o = getOption(p.getName());
// Need to get value.
Object val = p.get(jslintFlags);
if (val == null) {
continue;
}
Class<?> type = p.getType();
if (type.isAssignableFrom(Boolean.class)) {
lint.addOption(o);
} else // In theory, everything else should be a String for later parsing.
if (type.isAssignableFrom(String.class)) {
lint.addOption(o, (String) val);
} else {
die("unknown type \"" + type + "\" (for " + p.getName() + ")");
}
} catch (IllegalArgumentException e) {
die(e.getMessage());
}
}
if (flags.files.isEmpty()) {
usage(jc);
// can never happen
return null;
} else {
return flags.files;
}
}
use of com.beust.jcommander.Parameterized in project smali by JesusFreke.
the class ExtendedCommands method parameterArgumentNames.
@Nonnull
public static String[] parameterArgumentNames(ParameterDescription parameterDescription) {
Parameterized parameterized = parameterDescription.getParameterized();
Class cls = parameterDescription.getObject().getClass();
Field field = null;
while (cls != Object.class) {
try {
field = cls.getDeclaredField(parameterized.getName());
} catch (NoSuchFieldException ex) {
cls = cls.getSuperclass();
continue;
}
break;
}
assert field != null;
ExtendedParameter extendedParameter = field.getAnnotation(ExtendedParameter.class);
if (extendedParameter != null) {
return extendedParameter.argumentNames();
}
return new String[0];
}
Aggregations