@Override protected Class makeCodeGenModel(File file) { return newBuilder(file, getClassOrInterfaceName()) .forEveryProject((clazz, project) -> clazz.public_().final_() .setSupertype(generatedImplType()) .add(applicationType()) ).build(); }
/** * Copy constructor. * * @param prototype the prototype */ protected ClassImpl(Class prototype) { super (prototype); this.superType = prototype.getSupertype().orElse(null); this.constructors = Copier.copy(prototype.getConstructors()); }
@Override public void accept(Class aClass) { aClass.add(Constructor.newPublic() .call(constr -> aClass.getFields().stream() .filter(f -> f.getModifiers().contains(FINAL)) .map(Field::copy) .peek(f -> f.getModifiers().clear()) .forEachOrdered(f -> { constr.add(f).imports(Objects.class, "requireNonNull"); if (isPrimitive(f.getType())) { constr.add(format("this.%1$s = %1$s;", f.getName())); } else { constr.add(format("this.%1$s = requireNonNull(%1$s);", f.getName())); } }) ) ); } }
@Override protected String renderSupertype(Generator gen, Class model) { requireNonNull(gen); requireNonNull(model); return model.getSupertype().map(supertype -> { final StringBuilder result = new StringBuilder(); if (!model.getInterfaces().isEmpty()) { result.append(nl()); } return result.append(EXTENDS_STRING) .append(gen.on(supertype).orElse("")) .append(" ") .toString(); }).orElse(""); }
if (model.getGenerics().isEmpty()) { self = SimpleType.create(file, model); } else { self = SimpleParameterizedType.create( file, model, model.getGenerics().stream() .map(Generic::asType) .toArray(Type[]::new) requireNonNull(model).getFields().forEach(f -> { f.private_(); final Method add = Method.of("add", self) .set(Javadoc.of() .setText("Adds the specified " + lcfirst(shortName(param.getType().getTypeName())) + " to this " + shortName(model.getName()) + ".") .add(JavadocTag.of("param", param.getName(), "the new value")) .add(JavadocTag.of("return", "a reference to this object")) model.add(add); .setText("Sets the " + f.getName() + " of this " + shortName(model.getName()) + ".") .add(JavadocTag.of("param", f.getName(), "the new value")) .add(JavadocTag.of("return", "a reference to this object")) model.add(set); .setText("Gets the " + f.getName() + " of this " + shortName(model.getName()) + ".") .add(JavadocTag.of("return", "the " + f.getName())) ).public_()
clazz.public_().abstract_() .setSupertype( SimpleParameterizedType.create( AbstractApplicationBuilder.class, .add(constr) .add(build); }).build();
@Override protected Class makeCodeGenModel(File file) { return newBuilder(file, getClassOrInterfaceName()) .forEveryProject((clazz, project) -> { clazz.public_() .setSupertype(AbstractSpeedment.class) .add(generatedType()); }).build(); }
clazz.public_().abstract_() .add( SimpleParameterizedType.create( SqlAdapter.class, .add(Constructor.of().protected_() .add("this.tableIdentifier = " + TableIdentifier.class.getSimpleName() + ".of(" .add(Field.of("tableIdentifier", tableIdentifierType).private_().final_()) .add(generateApplyResultSet(getSupport(), file, table::columns)) .add(generateCreateEntity(file)) .add( Method.of("identifier", tableIdentifierType) .public_() .add( Method.of("entityMapper", SimpleParameterizedType.create(SqlFunction.class, ResultSet.class, getSupport().entityType())) .public_() .add( Method.of("entityMapper", SimpleParameterizedType.create(SqlFunction.class, ResultSet.class, getSupport().entityType())) .public_() .call(() -> { if (clazz.getMethods().stream() .map(Method::getName)
clazz.public_() .abstract_() .add(getSupport().entityType()) .add(Constructor.of().protected_()) .add(fieldFor(col).private_()) .add(Method.of(GETTER_METHOD_PREFIX + getSupport().typeName(col), retType) .public_().add(OVERRIDE) .add("return " + getter + ";")); .add(Method.of(SETTER_METHOD_PREFIX + getSupport().typeName(col), getSupport().entityType()) .public_() .add(OVERRIDE) final String getterName = optionalGetterName(typeMappers, col).orElse(""); clazz.add(Method.of(FINDER_METHOD_PREFIX + getSupport().typeName(col), col.isNullable() ? DefaultType.optional(fuSupport.entityType()) .add(toStringMethod(file)) .add(equalsMethod()) .add(hashCodeMethod(file))
@Override protected String renderConstructors(Generator gen, Class model) { requireNonNull(gen); requireNonNull(model); return gen.onEach(model.getConstructors()) .collect(joining(dnl())); } }
@Override protected String renderSupertype(Generator gen, Class model) { requireNonNull(gen); requireNonNull(model); if (model.getSupertype().isPresent()) { return EXTENDS_STRING + gen.on(model.getSupertype().get()).orElse("") + " "; } else { return ""; } }
if (model.getGenerics().isEmpty()) { self = SimpleType.create(file, model); } else { self = SimpleParameterizedType.create( file, model, model.getGenerics().stream() .map(Generic::asType) .toArray(Type[]::new) requireNonNull(model).getFields().forEach(f -> { f.private_(); final Method add = Method.of("add", self) .set(Javadoc.of() .setText("Adds the specified " + lcfirst(shortName(param.getType().getTypeName())) + " to this " + shortName(model.getName()) + ".") .add(JavadocTag.of("param", param.getName(), "the new value")) .add(JavadocTag.of("return", "a reference to this object")) model.add(add); .setText("Sets the " + f.getName() + " of this " + shortName(model.getName()) + ".") .add(JavadocTag.of("param", f.getName(), "the new value")) .add(JavadocTag.of("return", "a reference to this object")) model.add(set); .setText("Gets the " + f.getName() + " of this " + shortName(model.getName()) + ".") .add(JavadocTag.of("return", "the " + f.getName())) ).public_()
.public_() .abstract_() .setSupertype(SimpleParameterizedType.create( table.isView() ? AbstractViewManager.class getSupport().entityType() )) .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(" + Stream.of(getSupport().dbmsOrThrow().getId(), getSupport().schemaOrThrow().getId(), getSupport().tableOrThrow().getId()) + ");") .add(Method.of("getTableIdentifier", SimpleParameterizedType.create(TableIdentifier.class, getSupport().entityType())) .public_().add(OVERRIDE) .add("return tableIdentifier;") .add( Method.of(FIELDS_METHOD, DefaultType.stream( .add(generateFields(getSupport(), file, PRIMARY_KEYS_FIELDS_METHOD, () -> table.primaryKeyColumns() .sorted(comparing(PrimaryKeyColumn::getOrdinalPosition))
clazz.public_() .setSupertype(AbstractApplicationMetadata.class) .add(metadataField) .add(initializer) .add(getMetadata);
clazz.public_().abstract_() .add( SimpleParameterizedType.create( SqlAdapter.class, .add(Constructor.of().protected_() .add("this.tableIdentifier = " + TableIdentifier.class.getSimpleName() + ".of(" .add(Field.of("tableIdentifier", tableIdentifierType).private_().final_()) .add(generateApplyResultSet(getSupport(), file, table::columns)) .add(generateCreateEntity(file)) .add( Method.of("identifier", tableIdentifierType) .public_() .add( Method.of("entityMapper", SimpleParameterizedType.create(SqlFunction.class, ResultSet.class, getSupport().entityType())) .public_() .add( Method.of("entityMapper", SimpleParameterizedType.create(SqlFunction.class, ResultSet.class, getSupport().entityType())) .public_() .call(() -> { if (clazz.getMethods().stream() .map(Method::getName)
clazz.public_() .abstract_() .add(getSupport().entityType()) .add(Constructor.of().protected_()) .add(fieldFor(col).private_()) .add(Method.of(GETTER_METHOD_PREFIX + getSupport().typeName(col), retType) .public_().add(OVERRIDE) .add("return " + getter + ";")); .add(Method.of(SETTER_METHOD_PREFIX + getSupport().typeName(col), getSupport().entityType()) .public_() .add(OVERRIDE) final String getterName = optionalGetterName(typeMappers, col).orElse(""); clazz.add(Method.of(FINDER_METHOD_PREFIX + getSupport().typeName(col), col.isNullable() ? DefaultType.optional(fuSupport.entityType()) .add(toStringMethod(file)) .add(equalsMethod()) .add(hashCodeMethod(file))
@Override protected String renderSupertype(Generator gen, Class model) { requireNonNull(gen); requireNonNull(model); return model.getSupertype().map(supertype -> { final StringBuilder result = new StringBuilder(); if (!model.getInterfaces().isEmpty()) { result.append(nl()); } return result.append(EXTENDS_STRING) .append(gen.on(supertype).orElse("")) .append(" ") .toString(); }).orElse(""); }
@Override protected String renderConstructors(Generator gen, Class model) { requireNonNull(gen); requireNonNull(model); return gen.onEach(model.getConstructors()) .collect(joining(dnl())); } }
if (model.getGenerics().isEmpty()) { self = SimpleType.create(file, model); } else { self = SimpleParameterizedType.create( file, model, model.getGenerics().stream() .map(Generic::asType) .toArray(Type[]::new) requireNonNull(model).getFields().forEach(f -> { f.private_(); final Method add = Method.of("add", self) .set(Javadoc.of() .setText("Adds the specified " + lcfirst(shortName(param.getType().getTypeName())) + " to this " + shortName(model.getName()) + ".") .add(JavadocTag.of("param", param.getName(), "the new value")) .add(JavadocTag.of("return", "a reference to this object")) model.add(add); .setText("Sets the " + f.getName() + " of this " + shortName(model.getName()) + ".") .add(JavadocTag.of("param", f.getName(), "the new value")) .add(JavadocTag.of("return", "a reference to this object")) model.add(set); .setText("Gets the " + f.getName() + " of this " + shortName(model.getName()) + ".") .add(JavadocTag.of("return", "the " + f.getName())) ).public_()
@Override protected Class makeCodeGenModel(File file) { return newBuilder(file, getSupport().entityImplName()).build() .public_().final_() .add(getSupport().entityType()) .setSupertype(getSupport().generatedEntityImplType()); }