Java 类org.kohsuke.args4j.spi.Setters 实例源码

项目:spletne-seje    文件:PropretiesCmdParser.java   
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) {
    }
}
项目:buck-cutom    文件:CmdLineParserAdditionalOptions.java   
@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);
      }
    }
  }
}
项目:buck    文件:AdditionalOptionsCmdLineParser.java   
@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);
      }
    }
  }
}