private Method addNewSubMethod(List<Method> methods) { final Method m = Method.of(INIT_PART_METHOD_NAME + methods.size(), void.class).private_().static_() .add(Field.of(STRING_BUILDER_NAME, StringBuilder.class)); methods.add(m); m.add("Stream.of("); return m; }
/** * Creates a {@link Field} and adds it to this model. The field will be * given the default modifiers for this type, for an example, a * {@link Class} will be {@code public final}. * * @param name the name of the field * @param type the type of the field * @return a reference to this * * @since 2.5 */ default T field(final String name, Type type) { return add(Field.of(name, type).public_().final_()); }
public Field fieldFor(Column c) { return Field.of( getSupport().variableName(c), typeMappers.get(c).getJavaType(c) ); }
private Method generateApplyResultSet( TranslatorSupport<Table> support, File file, Supplier<Stream<? extends Column>> columnsSupplier) { return Method.of("apply", support.entityType()) .protected_() .add(SQLException.class) .add(Field.of("resultSet", ResultSet.class)) .add(Field.of(OFFSET_PARAMETER_NAME, int.class)) .add(generateApplyResultSetBody( this::readFromResultSet, support, file, columnsSupplier )); }
/** * Creates a public final static {@link Field} with the specified value and * adds it to this model. * * @param name the name of the field * @param type the type of the field * @param value the value of the field * @return a reference to this * * @since 2.5 */ default T constant(final String name, Type type, Value<?> value) { return add(Field.of(name, type) .public_().final_().static_() .set(value) ); }
.add(Field.of("injector", Injector.class)) .add("return injector.getOrThrow(" + getSupport().typeName(getSupport().projectOrThrow()) + "Application.class);");
.add(OVERRIDE); final Field metadataField = Field.of("METADATA", String.class) .private_().final_().static_();
).public_() .add(OVERRIDE) .add(Field.of("other", Object.class)) .add("return Optional.ofNullable(other)") .call(m -> {
.add(SimpleParameterizedType.create(Manager.class, getSupport().entityType())) .add( Field.of( "IDENTIFIER", SimpleParameterizedType.create(TableIdentifier.class, getSupport().entityType()) )) .add(Field.of("FIELDS", list(SimpleParameterizedType.create( com.speedment.runtime.field.Field.class, getSupport().entityType())
.add(Field.of(DATABASE_NAME, String.class) .private_().final_() ).add(Field.of(DATABASE_ORDINAL, int.class) .private_().final_() ); .add(Field.of(DATABASE_NAME, String.class)) .add("if (" + DATABASE_NAME + " == null) return null;") .add("switch (" + DATABASE_NAME + ") {"); .add(Field.of(DATABASE_ORDINAL, Integer.class)) .add("if (" + DATABASE_ORDINAL + " == null) return null;") .add("switch (" + DATABASE_ORDINAL + ") {"); .add(Field.of(DATABASE_NAME, String.class)) .add(Field.of(DATABASE_ORDINAL, int.class)) .add("this." + DATABASE_NAME + " = " + DATABASE_NAME + ";") .add("this." + DATABASE_ORDINAL + " = " + DATABASE_ORDINAL + ";") .add(Field.of("column", Column.class)) .add("return " + TypeMapper.Category.class.getSimpleName() + "." + TypeMapper.Category.ENUM.name() + ";") .add(Field.of("column", Column.class)) .add("return " + enumShortName + ".class;") .add(Field.of("column", Column.class)) .add(Field.of("clazz", classOf(WILDCARD))) .add(Field.of("value", wrapIfPrimitive(dbType)))
final Method createHelpers = Method.of(CREATE_HELPERS_METHOD_NAME, void.class) .add(withExecuteBefore(file)) .add(Field.of("projectComponent", ProjectComponent.class)) .add("final Project project = projectComponent.getProject();"); .add(Field.of("tableIdentifier", tableIdentifierType).private_().final_()) .public_() .add(OVERRIDE) .add(Field.of(OFFSET_PARAMETER_NAME, int.class)) .add("return rs -> apply(rs, offset);") ); clazz.add(Field.of(tmsName, tmsType).private_());
final Field param = Field.of(singular(f.getName()), paramType.getActualTypeArguments()[0]); final Method add = Method.of("add", self) .set(Javadoc.of() set.add(Field.of(f.getName(), paramType.getActualTypeArguments()[0])) .add("this." + f.getName() + " = Optional.of(" + f.getName() + ");") .add("return this;"); } else { set.add(Field.of(f.getName(), f.getType())) .add("this." + f.getName() + " = " + f.getName() + ";") .add("return this;");
public Constructor copyConstructor(Type type, CopyConstructorMode mode) { final TranslatorSupport<D> support = getSupport(); final Constructor constructor = Constructor.of().protected_() .add(Field.of(support.variableName(), type));
)) .add(getSupport().generatedManagerType()) .add(Field.of("tableIdentifier", SimpleParameterizedType.create(TableIdentifier.class, getSupport().entityType())).private_().final_()) .add(Constructor.of().protected_() .add("this.tableIdentifier = " + TableIdentifier.class.getSimpleName() + ".of("
private Method equalsMethod() { final String thatName = "that"; final String thatCastedName = thatName + getSupport().entityName(); final Method method = Method.of("equals", boolean.class) .public_() .add(OVERRIDE) .add(Field.of(thatName, Object.class)) .add("if (this == that) { return true; }") .add("if (!(" + thatName + " instanceof " + getSupport().entityName() + ")) { return false; }") .add("final " + getSupport().entityName() + " " + thatCastedName + " = (" + getSupport().entityName() + ")" + thatName + ";"); columns().forEachOrdered(c -> { final String getter = "get" + getSupport().typeName(c); final Type type = typeMappers.get(c).getJavaType(c); if (usesOptional(c) || !DefaultType.isPrimitive(type)) { method.add("if (!Objects.equals(this." + getter + "(), " + thatCastedName + "." + getter + "())) { return false; }"); } else { method.add("if (this." + getter + "() != " + thatCastedName + "." + getter + "()) { return false; }"); } }); method.add("return true;"); return method; }
.add(Field.of("columnId", String.class).private_().final_()) .add(Field.of("tableIdentifier", tableIdentifierType).private_().final_()) .add(SimpleParameterizedType.create(ColumnIdentifier.class, getSupport().entityType())) .add(Constructor.of() .add(Field.of("columnId", String.class)) .add("this.columnId\t = columnId;") .add("this.tableIdentifier\t = TableIdentifier.of(" + indent( .add(Field.of(getSupport().variableName(col), typeMappers.get(col).getJavaType(col))) .set(Javadoc.of( "Sets the " + getSupport().variableName(col) .add(DefaultJavadocTag.RETURN.setText("the foreign entity referenced")) .add(Field.of("foreignManager", SimpleParameterizedType.create( Manager.class, fuSupport.entityType() ))) intrf.add(Field.of(getSupport().namer().javaStaticFieldName(col.getJavaName()), ref.getType()) .final_() .set(Value.ofInvocation(
.public_() .add(DefaultAnnotationUsage.OVERRIDE) .add(Field.of("foreignManager", SimpleParameterizedType.create( Manager.class, fuSupport.entityType() )))
private Method addNewSubMethod(List<Method> methods) { final Method m = Method.of(INIT_PART_METHOD_NAME + methods.size(), void.class).private_().static_() .add(Field.of(STRING_BUILDER_NAME, StringBuilder.class)); methods.add(m); m.add("Stream.of("); return m; }
/** * Creates a {@link Field} and adds it to this model. The field will be * given the default modifiers for this type, for an example, a * {@link Class} will be {@code public final}. * * @param name the name of the field * @param type the type of the field * @return a reference to this * * @since 2.5 */ default T field(final String name, Type type) { return add(Field.of(name, type).public_().final_()); }
private Method generateApplyResultSet( TranslatorSupport<Table> support, File file, Supplier<Stream<? extends Column>> columnsSupplier) { return Method.of("apply", support.entityType()) .protected_() .add(SQLException.class) .add(Field.of("resultSet", ResultSet.class)) .add(Field.of(OFFSET_PARAMETER_NAME, int.class)) .add(generateApplyResultSetBody( this::readFromResultSet, support, file, columnsSupplier )); }