Search in sources :

Example 1 with IllegalAnnotationError

use of org.kohsuke.args4j.IllegalAnnotationError in project buck by facebook.

the class AdditionalOptionsCmdLineParser method parseAdditionalOptions.

@SuppressWarnings("unchecked")
private void parseAdditionalOptions(ClassParser classParser, Object bean, Set<Class<?>> visited) {
    // so an empty visited set means we're parsing the top-level bean.
    if (!visited.isEmpty()) {
        // 'Parse' the class of the bean looking for annotations.
        classParser.parse(bean, this);
    }
    Class<?> beanClass = bean.getClass();
    if (visited.contains(beanClass)) {
        throw new IllegalAnnotationError(beanClass.getCanonicalName() + " used more than once.");
    } else {
        visited.add(beanClass);
    }
    for (Field f : beanClass.getDeclaredFields()) {
        if (f.isAnnotationPresent(AdditionalOptions.class)) {
            try {
                // TODO(mrkane27): nicer to do this lazily in parseArgument()
                Object fieldValue = f.getType().newInstance();
                Setters.create(f, bean).addValue(fieldValue);
                parseAdditionalOptions(classParser, fieldValue, visited);
            } catch (CmdLineException | IllegalAccessException | InstantiationException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) IllegalAnnotationError(org.kohsuke.args4j.IllegalAnnotationError) CmdLineException(org.kohsuke.args4j.CmdLineException)

Aggregations

Field (java.lang.reflect.Field)1 CmdLineException (org.kohsuke.args4j.CmdLineException)1 IllegalAnnotationError (org.kohsuke.args4j.IllegalAnnotationError)1