Пример #1
0
  private void addWithersFor(Filter filter, JDefinedClass bldrCls, JVar paramBuilder)
      throws ClassNotFoundException, JClassAlreadyExistsException {
    JDefinedClass cls = (JDefinedClass) bldrCls.parentContainer();

    JFieldVar field =
        cls.field(privateStaticFinal, String.class, sanitize(filter.getName().toUpperCase()));
    field.init(JExpr.lit(filter.getName()));

    JClass paramType = mapType(filter);
    if (Boolean.TRUE.equals(filter.isMultipleValues())) {
      JMethod iterableWither = addIterableWither(filter, bldrCls, paramBuilder, field, paramType);
      addVarArgsWither(filter, iterableWither, bldrCls, paramType);
    } else {
      addWither(filter, bldrCls, paramBuilder, field, paramType);
    }
  }
Пример #2
0
  private JClass getParamTypeEnum(Filter filter) throws JClassAlreadyExistsException {
    String enumName = camel(filter.getName(), true) + "Option";
    if (pkg.isDefined(enumName)) {
      return pkg._getClass(enumName);
    }
    List<Option> options = filter.getOption();
    if (options.size() == 1) {
      /*turn into '*Only' method?*/
    }
    if (options.size() == 2) {
      if (ImmutableSet.of("true", "false")
          .equals(
              ImmutableSet.of(
                  options.get(0).getValue().toLowerCase(),
                  options.get(1).getValue().toLowerCase()))) {
        return model.ref(Boolean.class);
      }
    }

    JDefinedClass valueEnum = pkg._enum(enumName);

    JFieldVar valField = valueEnum.field(JMod.PRIVATE | JMod.FINAL, String.class, "value");
    JMethod ctor = valueEnum.constructor(JMod.PRIVATE);
    JVar param = ctor.param(String.class, "val");
    ctor.body().assign(valField, param);

    JMethod toString = valueEnum.method(JMod.PUBLIC, String.class, "toString");
    toString.annotate(Override.class);
    toString.body()._return(valField);

    for (Option option : options) {
      String optionName = option.getValue().toUpperCase().replace(' ', '_');
      JEnumConstant optionCst = valueEnum.enumConstant(optionName);
      optionCst.arg(JExpr.lit(option.getValue().replace(' ', '+')));
    }
    return valueEnum;
  }
Пример #3
0
 private JMethod createWitherMethod(Filter filter, JDefinedClass bldrCls) {
   String filterMethodName = "with" + camel(sanitize(filter.getName()), true);
   return bldrCls.method(JMod.PUBLIC, bldrCls, filterMethodName);
 }
Пример #4
0
 private JVar addParam(Filter filter, JMethod method, JType paramType) {
   return method.param(paramType, camel(sanitize(filter.getName()), false));
 }