private void addCriteriaMethods(TopLevelClass topLevelClass, int newMethodsStart) {
        if (!generateCriteriaMethods) return;
        InnerClass criteria = null;
        for (InnerClass c : topLevelClass.getInnerClasses()) {
            if (c.getType().getShortName().equals("Criteria")) criteria = c;
        }
        if (criteria == null) return;
        boolean owner = false;
        for (Field f : criteria.getFields()) if (ExampleMethodsChainPlugin.OWNER.equals(f.getName())) owner = true;
        if (!owner) return;

        for (ListIterator<Method> methods = topLevelClass.getMethods().listIterator(newMethodsStart); methods.hasNext(); ) {
            Method base = methods.next();
            if (base.getVisibility() != PUBLIC || base.isStatic() || base.isConstructor()) continue;
            Method m = method(PUBLIC, base.getReturnType(), base.getName());
            StringBuilder sb = new StringBuilder();
            sb.append("return ").append(ExampleMethodsChainPlugin.OWNER).append(".").append(base.getName()).append("(");
            for (ListIterator<Parameter> params = base.getParameters().listIterator(); params.hasNext(); ) {
                if (params.hasPrevious()) sb.append(", ");
                Parameter p = params.next();
                m.addParameter(new Parameter(p.getType(), p.getName()));
                sb.append(p.getName());
            }
            sb.append(");");
            m.addBodyLine(sb.toString());
            criteria.addMethod(m);
        }
    }
예제 #2
0
  /**
   * 添加给Example类序列化的方法
   *
   * @param topLevelClass
   * @param introspectedTable
   * @return
   */
  @Override
  public boolean modelExampleClassGenerated(
      TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    makeSerializable(topLevelClass, introspectedTable);
    for (InnerClass innerClass : topLevelClass.getInnerClasses()) {
      makeSerializable(innerClass);
    }

    return true;
  }