/** * Creates an {@link Import} using the default implementation and adds it to * this model. * * @param type the dependency to add * @return a reference to this * * @since 2.5 */ default T imports(final Type type) { return add(Import.of(type)); }
@Override public Optional<String> transform(Generator gen, Import model) { requireNonNulls(gen, model); final String name = stripGenerics(model.getType().getTypeName()) .replace('$', '.'); if (!model.getModifiers().isEmpty() || shouldImport(gen, model.getType())) { return Optional.of( "import " + gen.onEach(model.getModifiers()).collect(joinIfNotEmpty(" ", "", " ")) + name + model.getStaticMember().map(str -> "." + str).orElse("") + ";" ).filter(x -> { gen.getDependencyMgr().load(name); return true; }); } else { return Optional.empty(); } }
/** * Creates a static {@link Import} using the default implementation and adds * it to this model. * * @param type the dependency to add * @param method name of the static member method * @return a reference to this * * @since 2.5 */ default T imports(final Type type, String method) { return add(Import.of(type).static_().setStaticMember(method)); }
/** * Copy constructor. * * @param prototype the prototype */ protected ImportImpl(Import prototype) { type = prototype.getType(); modifiers = Copier.copy(prototype.getModifiers(), c -> c.copy(), EnumSet.noneOf(Modifier.class)); }
/** * Adds the specified {@link Import} to this model. * * @param dep the new child * @return a reference to this */ @SuppressWarnings("unchecked") default T add(final Import dep) { getImports().add(dep.setParent(this)); return (T) this; }
/** * Copy constructor. * * @param prototype the prototype */ protected ImportImpl(Import prototype) { type = prototype.getType(); modifiers = Copier.copy(prototype.getModifiers(), c -> c.copy(), EnumSet.noneOf(Modifier.class)); }
/** * Adds the specified {@link Import} to this model. * * @param dep the new child * @return a reference to this */ @SuppressWarnings("unchecked") default T add(final Import dep) { getImports().add(dep.setParent(this)); return (T) this; }
/** * Adds explicit imports for all {@link Type} references mentioned in the * specified {@link File}. * * @param file the file to add imports in */ @Override public void accept(File file) { findTypesIn(requireNonNull(file)).forEach( (s, t) -> file.add(Import.of(t)) ); }
private AnnotationUsage withExecuteBefore(File file) { file.add(Import.of(State.class).static_().setStaticMember("RESOLVED")); return AnnotationUsage.of(ExecuteBefore.class).set(Value.ofReference("RESOLVED")); }
@Override public Optional<String> transform(Generator gen, Import model) { requireNonNulls(gen, model); final String name = stripGenerics(model.getType().getTypeName()) .replace('$', '.'); if (!model.getModifiers().isEmpty() || shouldImport(gen, model.getType())) { return Optional.of( "import " + gen.onEach(model.getModifiers()).collect(joinIfNotEmpty(" ", "", " ")) + name + model.getStaticMember().map(str -> "." + str).orElse("") + ";" ).filter(x -> { gen.getDependencyMgr().load(name); return true; }); } else { return Optional.empty(); } }
/** * Copy constructor. * * @param prototype the prototype */ protected ImportImpl(Import prototype) { type = prototype.getType(); modifiers = Copier.copy(prototype.getModifiers(), c -> c.copy(), EnumSet.noneOf(Modifier.class)); }
public static String[] generateFieldsBody( TranslatorSupport<Table> support, File file, Supplier<Stream<? extends Column>> columnsSupplier) { file.add(Import.of(Stream.class)); // If there are no matching columns: if (columnsSupplier.get().noneMatch($ -> true)) { return new String[]{"return Stream.empty();"}; } else { final List<String> rows = new LinkedList<>(); rows.add("return Stream.of("); rows.add(indent(columnsSupplier.get() .filter(HasEnabled::isEnabled) .map(Column::getJavaName) .map(support.namer()::javaStaticFieldName) .map(field -> support.typeName() + "." + field) .collect(joining("," + nl())) )); rows.add(");"); return rows.toArray(new String[rows.size()]); } }
file.add(Import.of(ResultSetUtil.class).static_().setStaticMember("*")); file.add(Import.of(SimpleType.create(c.getDatabaseType()))); sb.append("(").append(shortName(c.getDatabaseType())).append(") "); } else { if (isCastingRequired(c, getterName)) { file.add(Import.of(SimpleType.create(c.getDatabaseType()))); sb.append("(").append(shortName(c.getDatabaseType())).append(") ");
@Override public Optional<String> transform(Generator gen, Import model) { requireNonNulls(gen, model); final String name = stripGenerics(model.getType().getTypeName()) .replace('$', '.'); if (!model.getModifiers().isEmpty() || shouldImport(gen, model.getType())) { return Optional.of( "import " + gen.onEach(model.getModifiers()).collect(joinIfNotEmpty(" ", "", " ")) + name + model.getStaticMember().map(str -> "." + str).orElse("") + ";" ).filter(x -> { gen.getDependencyMgr().load(name); return true; }); } else { return Optional.empty(); } }
/** * Adds an {@link DefaultJavadocTag#SEE}-tag that references the specified * Java type. * * @param type the type to reference in the {@code see}-tag * @return a reference to this */ default T see(final Type type) { return add(DefaultJavadocTag.SEE.setValue("{@link " + Formatting.shortName(type.getTypeName()) + "}")) .add(Import.of(type)); }
.forEveryTable((intf, table) -> { file.add(Import.of(getSupport().entityType())); file.add(Import.of(Collections.class).setStaticMember("unmodifiableList").static_()); file.add(Import.of(Arrays.class).setStaticMember("asList").static_());
public static String[] generateApplyResultSetBody( ReadFromResultSet readFromResultSet, TranslatorSupport<Table> support, File file, Supplier<Stream<? extends Column>> columnsSupplier) { file.add(Import.of(SQLException.class)); final List<String> rows = new LinkedList<>(); rows.add("return createEntity()"); final Stream.Builder<String> streamBuilder = Stream.builder(); final AtomicInteger position = new AtomicInteger(1); columnsSupplier.get() .filter(HasEnabled::isEnabled) .forEachOrdered(c -> streamBuilder.add(indent(".set" + support.namer().javaTypeName(c.getJavaName()) + "(\t " + readFromResultSet.readFromResultSet(file, c, position) + ")")) ); streamBuilder.add(indent(";")); streamBuilder.build().forEachOrdered(rows::add); return rows.toArray(new String[rows.size()]); }
/** * Creates a static {@link Import} using the default implementation and adds * it to this model. * * @param type the dependency to add * @param method name of the static member method * @return a reference to this * * @since 2.5 */ default T imports(final Type type, String method) { return add(Import.of(type).static_().setStaticMember(method)); }
private Method hashCodeMethod(File file) { final Method method = Method.of("hashCode", int.class) .public_() .add(OVERRIDE) .add("int hash = 7;"); columns().forEachOrdered(c -> { final StringBuilder str = new StringBuilder(); str.append("hash = 31 * hash + "); final Type type = typeMappers.get(c).getJavaType(c); if (!usesOptional(c) && DefaultType.isPrimitive(type)) { str.append(DefaultType.wrapperFor(type).getSimpleName()); } else { str.append("Objects"); } str.append(".hashCode("); if (usesOptional(c)) { file.add(Import.of(OptionalUtil.class)); str.append("OptionalUtil.unwrap("); } str.append("get").append(getSupport().typeName(c)).append("()"); if (usesOptional(c)) str.append(')'); str.append(");"); method.add(str.toString()); }); method.add("return hash;"); return method; }