public PropretiesCmdParser(Object bean) { super(bean); try { Field f = this.getClass().getDeclaredField("popsFile"); Option o = f.getAnnotation(Option.class); addOption(Setters.create(f, this), o); } catch (NoSuchFieldException ignore) { } }
@SuppressWarnings("unchecked") private void parseAdditionalOptions(ClassParser classParser, Object bean, Set<Class<?>> visited) { // The top-level bean was already parsed by the superclass constructor, // so an empty visited set means we're parsing the top-level bean. if (!visited.isEmpty()) { classParser.parse(bean, this); // 'Parse' the class of the bean looking for annotations. } 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(user): nicer to do this lazily in parseArgument() Object fieldValue = f.getType().newInstance(); Setters.create(f, bean).addValue(fieldValue); parseAdditionalOptions(classParser, fieldValue, visited); } catch (Exception e) { throw Throwables.propagate(e); } } } }
@SuppressWarnings("unchecked") private void parseAdditionalOptions(ClassParser classParser, Object bean, Set<Class<?>> visited) { // The top-level bean was already parsed by the superclass constructor, // so an empty visited set means we're parsing the top-level bean. if (!visited.isEmpty()) { classParser.parse(bean, this); // 'Parse' the class of the bean looking for annotations. } 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(vlada): 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); } } } }