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);
}
}
}
}
Aggregations