public Constructor copyConstructor(Type type, CopyConstructorMode mode) { final TranslatorSupport<D> support = getSupport(); final Constructor constructor = Constructor.of().protected_() .add(Field.of(support.variableName(), type)); constructor.add( "this." + support.variableName(c) + " = " + support.variableName() + constructor.add( support.variableName() + "." + GETTER_METHOD_PREFIX + support.typeName(c) ); } else { constructor.add( SETTER_METHOD_PREFIX + support.typeName(c) + "(" + support.variableName()
@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())); } }) ) ); } }
/** * Copy constructor. * * @param prototype the prototype */ private ConstructorImpl(final Constructor prototype) { javadoc = requireNonNull(prototype).getJavadoc().map(Copier::copy).orElse(null); imports = Copier.copy(prototype.getImports()); annotations = Copier.copy(prototype.getAnnotations()); generics = Copier.copy(prototype.getGenerics()); params = Copier.copy(prototype.getFields()); code = Copier.copy(prototype.getCode(), c -> c); modifiers = Copier.copy(prototype.getModifiers(), Modifier::copy, EnumSet.noneOf(Modifier.class)); exceptions = new LinkedHashSet<>(prototype.getExceptions()); }
/** * Copy constructor. * * @param prototype the prototype */ protected ConstructorImpl(final Constructor prototype) { javadoc = requireNonNull(prototype).getJavadoc().map(Copier::copy).orElse(null); annotations = Copier.copy(prototype.getAnnotations()); params = Copier.copy(prototype.getFields()); code = Copier.copy(prototype.getCode(), c -> c); modifiers = Copier.copy(prototype.getModifiers(), c -> c.copy(), EnumSet.noneOf(Modifier.class)); exceptions = new LinkedHashSet<>(prototype.getExceptions()); }
.abstract_() .add(getSupport().entityType()) .add(Constructor.of().protected_())
@SuppressWarnings("unchecked") final HasConstructors<?> casted = (HasConstructors<?>) model; casted.getConstructors().forEach(c -> c.call(new AlignTabs<>()));
@Override public Optional<String> transform(Generator gen, Constructor model) { requireNonNulls(gen, model); return Optional.of( ifelse(gen.on(model.getJavadoc()), s -> s + nl(), "") + gen.onEach(model.getModifiers()).collect(joinIfNotEmpty(" ", "", " ")) + renderName(gen, model) .orElseThrow(() -> new UnsupportedOperationException( "Could not find a nameable parent of constructor." )) + gen.onEach(model.getFields()).collect( Collectors.joining( fieldSeparator(model), (model.getFields().size() > 3) ? "(" + nl() + tab() + tab() : "(", ")" ) ) + " " + gen.onEach(model.getExceptions()).collect(joinIfNotEmpty(", ", "throws ", " ")) + block( model.getCode().stream().collect( Collectors.joining(nl()) ) ) ); }
.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( "getDbmsId(), ", "getSchemaId(), ",
.abstract_() .add(getSupport().entityType()) .add(Constructor.of().protected_())
@SuppressWarnings("unchecked") final HasConstructors<?> casted = (HasConstructors<?>) model; casted.getConstructors().forEach(c -> c.call(new AlignTabs<>()));
.add("return injector.getOrThrow(" + getSupport().typeName(getSupport().projectOrThrow()) + "Application.class);"); final Constructor constr = Constructor.of().protected_(); constr.add(constructorBody.toString());
/** * Copy constructor. * * @param prototype the prototype */ private ConstructorImpl(final Constructor prototype) { javadoc = requireNonNull(prototype).getJavadoc().map(Copier::copy).orElse(null); imports = Copier.copy(prototype.getImports()); annotations = Copier.copy(prototype.getAnnotations()); generics = Copier.copy(prototype.getGenerics()); params = Copier.copy(prototype.getFields()); code = Copier.copy(prototype.getCode(), c -> c); modifiers = Copier.copy(prototype.getModifiers(), Modifier::copy, EnumSet.noneOf(Modifier.class)); exceptions = new LinkedHashSet<>(prototype.getExceptions()); }
.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( "getDbmsId(), ", "getSchemaId(), ",
@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())); } }) ) ); } }
@SuppressWarnings("unchecked") final HasConstructors<?> casted = (HasConstructors<?>) model; casted.getConstructors().forEach(c -> c.call(new AlignTabs<>()));