コード例 #1
0
  public Constructor copyConstructor(Type type, CopyConstructorMode mode) {
    final Constructor constructor =
        Constructor.of().public_().add(Field.of(variableName(), type).final_());

    columns()
        .forEachOrdered(
            c -> {
              switch (mode) {
                case FIELD:
                  {
                    constructor.add(
                        "this."
                            + variableName(c)
                            + " = "
                            + variableName()
                            + "."
                            + GETTER_METHOD_PREFIX
                            + typeName(c)
                            + "();");
                    break;
                  }
                case SETTER:
                case BUILDER:
                  {
                    final String setterPrefix =
                        (mode == SETTER) ? SETTER_METHOD_PREFIX : BUILDER_METHOD_PREFIX;

                    if (c.isNullable()) {
                      constructor.add(
                          variableName()
                              + "."
                              + GETTER_METHOD_PREFIX
                              + typeName(c)
                              + "().ifPresent(this::"
                              + setterPrefix
                              + typeName(c)
                              + ");");
                    } else {
                      constructor.add(
                          setterPrefix
                              + typeName(c)
                              + "("
                              + variableName()
                              + ".get"
                              + typeName(c)
                              + "());");
                    }
                    break;
                  }
              }
            });

    return constructor;
  }
コード例 #2
0
 public Field fieldFor(Column c) {
   return Field.of(variableName(c), Type.of(c.getMapping()));
 }