Search in sources :

Example 1 with Parameterized

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;
    }
}
Also used : Parameterized(com.beust.jcommander.Parameterized) JCommander(com.beust.jcommander.JCommander) ParameterException(com.beust.jcommander.ParameterException) Option(com.googlecode.jslint4java.Option) ParameterDescription(com.beust.jcommander.ParameterDescription)

Example 2 with Parameterized

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];
}
Also used : Field(java.lang.reflect.Field) Parameterized(com.beust.jcommander.Parameterized) Nonnull(javax.annotation.Nonnull)

Aggregations

Parameterized (com.beust.jcommander.Parameterized)2 JCommander (com.beust.jcommander.JCommander)1 ParameterDescription (com.beust.jcommander.ParameterDescription)1 ParameterException (com.beust.jcommander.ParameterException)1 Option (com.googlecode.jslint4java.Option)1 Field (java.lang.reflect.Field)1 Nonnull (javax.annotation.Nonnull)1