use of net.morimekta.providence.generator.format.java.utils.BlockCommentBuilder in project providence by morimekta.
the class BuilderCommonMemberFormatter method appendInitCause.
private void appendInitCause(JMessage<?> message) {
new BlockCommentBuilder(writer).comment("Initializes the cause of the " + message.descriptor().getQualifiedName()).newline().param_("cause", "The cause").return_("Builder instance").finish();
writer.appendln(JAnnotation.NON_NULL);
writer.appendln("public _Builder initCause(Throwable cause) {").appendln(" this.cause = cause;").appendln(" return this;").appendln("}").newline();
}
use of net.morimekta.providence.generator.format.java.utils.BlockCommentBuilder in project providence by morimekta.
the class BuilderCommonMemberFormatter method appendMutateConstructor.
private void appendMutateConstructor(JMessage<?> message) {
BlockCommentBuilder comment = new BlockCommentBuilder(writer);
comment.comment("Make a mutating builder off a base " + message.descriptor().getQualifiedName() + ".").newline().param_("base", "The base " + message.descriptor().getName()).finish();
writer.formatln("public _Builder(%s base) {", message.instanceType()).begin().appendln("this();").newline();
if (message.isUnion()) {
writer.formatln("%s = base.%s;", UNION_FIELD, UNION_FIELD).newline();
}
for (JField field : message.declaredOrderFields()) {
boolean checkPresence = message.isUnion() ? field.container() : !field.alwaysPresent();
if (checkPresence) {
writer.formatln("if (base.%s()) {", field.presence()).begin();
}
if (!message.isUnion()) {
writer.formatln("optionals.set(%d);", field.index());
}
if (field.type() != PType.VOID) {
writer.formatln("%s = base.%s;", field.member(), field.member());
}
if (checkPresence) {
writer.end().appendln('}');
}
}
writer.end().appendln('}').newline();
}
use of net.morimekta.providence.generator.format.java.utils.BlockCommentBuilder in project providence by morimekta.
the class BuilderCommonMemberFormatter method appendIsUnionModified.
private void appendIsUnionModified(JMessage message) {
BlockCommentBuilder comment = new BlockCommentBuilder(writer);
comment.comment("Checks if " + message.descriptor().getName() + " has been modified since the _Builder " + "was created.");
comment.newline().return_(String.format(Locale.US, "True if %s has been modified.", message.descriptor().getName())).finish();
writer.formatln("public boolean %s() {", "isUnionModified").begin();
writer.appendln("return modified;");
writer.end().appendln('}').newline();
}
use of net.morimekta.providence.generator.format.java.utils.BlockCommentBuilder in project providence by morimekta.
the class BuilderCommonMemberFormatter method appendIsModified.
private void appendIsModified(JMessage message, JField field) {
BlockCommentBuilder comment = new BlockCommentBuilder(writer);
if (field.hasComment()) {
comment.comment(field.comment());
} else {
comment.comment("Checks if " + field.name() + " has been modified since the _Builder was created.");
}
comment.newline().return_(String.format(Locale.US, "True if %s has been modified.", field.name())).finish();
writer.formatln("public boolean %s() {", field.isModified()).begin();
writer.formatln("return modified.get(%d);", field.index());
writer.end().appendln('}').newline();
}
use of net.morimekta.providence.generator.format.java.utils.BlockCommentBuilder in project providence by morimekta.
the class BuilderCommonMemberFormatter method appendGetter.
private void appendGetter(JField field) {
if (field.isVoid()) {
return;
}
BlockCommentBuilder comment = new BlockCommentBuilder(writer);
if (field.hasComment()) {
comment.comment(field.comment());
} else {
comment.comment("Gets the value of the contained " + field.name() + ".");
}
comment.newline().return_("The field value");
if (JAnnotation.isDeprecated(field)) {
String reason = field.field().getAnnotationValue(ThriftAnnotation.DEPRECATED);
if (reason != null && reason.trim().length() > 0) {
comment.deprecated_(reason);
}
}
comment.finish();
if (JAnnotation.isDeprecated(field)) {
writer.appendln(JAnnotation.DEPRECATED);
}
// Builder getters are *always* get*, never is* (e.g. for bool)
writer.formatln("public %s %s() {", field.valueType(), camelCase("get", field.name())).begin();
if ((field.isPrimitiveJavaValue() || field.field().hasDefaultValue()) && !field.alwaysPresent()) {
writer.formatln("return %s() ? %s : %s;", field.isSet(), field.member(), field.kDefault());
} else {
writer.formatln("return %s;", field.member());
}
writer.end().appendln('}').newline();
}
Aggregations