@Override public Type getType() { return f.getType(); }
final String suffix = ".hashCode(this." + f.getName() + "));"; switch (f.getType().getTypeName()) { case "byte": return prefix + "Byte" + suffix;
/** * Generates code for comparing the specified field in this and another * object. * * @param f the field * @return the comparing code */ protected String compare(Field f) { requireNonNull(f); final StringBuilder str = new StringBuilder(".filter(o -> "); if (isPrimitive(f.getType())) { str.append("(this.") .append(f.getName()) .append(" == o.") .append(f.getName()) .append(")"); } else { str.append("Objects.equals(this.") .append(f.getName()) .append(", o.") .append(f.getName()) .append(")"); } return str.append(")").toString(); }
/** * Copy constructor. * * @param prototype the prototype */ protected FieldImpl(Field prototype) { name = requireNonNull(prototype).getName(); type = prototype.getType(); imports = Copier.copy(prototype.getImports()); value = prototype.getValue().map(Copier::copy).orElse(null); javadoc = prototype.getJavadoc().map(Copier::copy).orElse(null); annotations = Copier.copy(prototype.getAnnotations()); modifiers = Copier.copy(prototype.getModifiers(), c -> c.copy(), EnumSet.noneOf(Modifier.class)); }
@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 public Optional<String> transform(Generator gen, Annotation model) { requireNonNulls(gen, model); return Optional.of( renderAnnotations(gen, model) + renderAnnotations(gen, model) + "@interface " + renderName(gen, model) + block( model.getFields().stream().map(f -> // Field javadoc (optional) renderJavadoc(gen, model) + // Field declaration gen.on(f.getType()) + " " + f.getName() + "()" + // Default value (optional) ifelse(gen.on(f.getValue()), v -> " default " + v, "") + ";" ).collect(joining(dnl())) ) ); } }
addType(f.getType(), types); findTypesIn(f, types); });
f.private_(); if (isCollection(f.getType())) { f.final_(); final ParameterizedType paramType = (ParameterizedType) f.getType(); .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")) ).public_(); if (isOptional(f.getType())) { final ParameterizedType paramType = (ParameterizedType) f.getType(); .add("return this;"); } else { set.add(Field.of(f.getName(), f.getType())) .add("this." + f.getName() + " = " + f.getName() + ";") .add("return this;"); final Method get = Method.of("get" + ucfirst(f.getName()), f.getType()) .set(Javadoc.of() .setText("Gets the " + f.getName() + " of this " + shortName(model.getName()) + ".")
@Override public Type getType() { return f.getType(); }
@Override public Type getType() { return f.getType(); }
final String suffix = ".hashCode(this." + f.getName() + "));"; switch (f.getType().getTypeName()) { case "byte": return prefix + "Byte" + suffix;
final String suffix = ".hashCode(this." + f.getName() + "));"; switch (f.getType().getTypeName()) { case "byte": return prefix + "Byte" + suffix;
/** * Generates code for comparing the specified field in this and another * object. * * @param f the field * @return the comparing code */ protected String compare(Field f) { requireNonNull(f); final StringBuilder str = new StringBuilder(".filter(o -> "); if (isPrimitive(f.getType())) { str.append("(this.") .append(f.getName()) .append(" == o.") .append(f.getName()) .append(")"); } else { str.append("Objects.equals(this.") .append(f.getName()) .append(", o.") .append(f.getName()) .append(")"); } return str.append(")").toString(); }
/** * Generates code for comparing the specified field in this and another * object. * * @param f the field * @return the comparing code */ protected String compare(Field f) { requireNonNull(f); final StringBuilder str = new StringBuilder(".filter(o -> "); if (isPrimitive(f.getType())) { str.append("(this.") .append(f.getName()) .append(" == o.") .append(f.getName()) .append(")"); } else { str.append("Objects.equals(this.") .append(f.getName()) .append(", o.") .append(f.getName()) .append(")"); } return str.append(")").toString(); }
/** * Copy constructor. * * @param prototype the prototype */ protected FieldImpl(Field prototype) { name = requireNonNull(prototype).getName(); type = prototype.getType(); value = prototype.getValue().map(Copier::copy).orElse(null); javadoc = prototype.getJavadoc().map(Copier::copy).orElse(null); annotations = Copier.copy(prototype.getAnnotations()); modifiers = Copier.copy(prototype.getModifiers(), c -> c.copy(), EnumSet.noneOf(Modifier.class)); }
/** * Copy constructor. * * @param prototype the prototype */ protected FieldImpl(Field prototype) { name = requireNonNull(prototype).getName(); type = prototype.getType(); imports = Copier.copy(prototype.getImports()); value = prototype.getValue().map(Copier::copy).orElse(null); javadoc = prototype.getJavadoc().map(Copier::copy).orElse(null); annotations = Copier.copy(prototype.getAnnotations()); modifiers = Copier.copy(prototype.getModifiers(), c -> c.copy(), EnumSet.noneOf(Modifier.class)); }
@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 public Optional<String> transform(Generator gen, Annotation model) { requireNonNulls(gen, model); return Optional.of( renderAnnotations(gen, model) + renderAnnotations(gen, model) + "@interface " + renderName(gen, model) + block( model.getFields().stream().map(f -> // Field javadoc (optional) renderJavadoc(gen, model) + // Field declaration gen.on(f.getType()) + " " + f.getName() + "()" + // Default value (optional) ifelse(gen.on(f.getValue()), v -> " default " + v, "") + ";" ).collect(joining(dnl())) ) ); } }
@Override public Optional<String> transform(Generator gen, Annotation model) { requireNonNulls(gen, model); return Optional.of( renderAnnotations(gen, model) + renderAnnotations(gen, model) + "@interface " + renderName(gen, model) + block( model.getFields().stream().map(f -> // Field javadoc (optional) renderJavadoc(gen, model) + // Field declaration gen.on(f.getType()) + " " + f.getName() + "()" + // Default value (optional) ifelse(gen.on(f.getValue()), v -> " default " + v, "") + ";" ).collect(joining(dnl())) ) ); } }
addType(f.getType(), types); findTypesIn(f, types); });