Example #1
0
  public void generateQuery(Feed feed) {
    try {
      JClass transformedType = getTransformedType(feed);
      if (transformedType == null) {
        return;
      }

      JDefinedClass cls =
          pkg._class(JMod.PUBLIC | JMod.FINAL, String.format("%sQuery", feed.getName()));
      cls._extends(parent.narrow(transformedType));

      if (feed.getTitle() != null) {
        cls.javadoc().add(String.format("<p>%s</p>", feed.getTitle()));
      }

      addResourcePath(cls, feed);
      addResultTypeMethod(model, cls, transformedType);
      addConstructor(cls);
      JDefinedClass bldrCls = addBuilderCls(feed, cls);

      cls.method(JMod.PUBLIC | JMod.STATIC | JMod.FINAL, bldrCls, "builder")
          .body()
          ._return(JExpr._new(bldrCls));

      JMethod cpyMthd = cls.method(JMod.PROTECTED | JMod.FINAL, cls, "copy");
      JVar cpyParam = cpyMthd.param(immutableMap.narrow(String.class, Object.class), "params");
      cpyMthd.body()._return(JExpr._new(cls).arg(cpyParam));

    } catch (Exception e) {
      throw new IllegalStateException(e);
    }
  }
Example #2
0
  private JDefinedClass getMixinEnum(Feed feed) throws JClassAlreadyExistsException {
    String enumName = camel(feed.getName(), true) + "Mixin";
    if (pkg.isDefined(enumName)) {
      return pkg._getClass(enumName);
    }
    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);
    return valueEnum;
  }
Example #3
0
 private JClass getTransformedType(Feed feed) {
   Class<?> cls = null;
   String name = feed.getName();
   if (name.equals("Versions")) {
     cls = Version.class;
     return model.ref(cls);
   }
   if (name.equals("Groups")) {
     cls = GroupBody.class;
     return model.ref(cls);
   }
   cls = tryLoadClass(MODEL_PKG + name);
   if (cls == null) { // attempt in possible naive singular.
     cls = tryLoadClass(MODEL_PKG + name.substring(0, name.length() - 1));
   }
   if (cls == null) {
     cls = Object.class;
   }
   return model.ref(cls);
 }