Search in sources :

Example 11 with BlockCommentBuilder

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();
}
Also used : BlockCommentBuilder(net.morimekta.providence.generator.format.java.utils.BlockCommentBuilder)

Example 12 with BlockCommentBuilder

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();
}
Also used : JField(net.morimekta.providence.generator.format.java.utils.JField) BlockCommentBuilder(net.morimekta.providence.generator.format.java.utils.BlockCommentBuilder)

Example 13 with BlockCommentBuilder

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();
}
Also used : BlockCommentBuilder(net.morimekta.providence.generator.format.java.utils.BlockCommentBuilder)

Example 14 with BlockCommentBuilder

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();
}
Also used : BlockCommentBuilder(net.morimekta.providence.generator.format.java.utils.BlockCommentBuilder)

Example 15 with BlockCommentBuilder

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();
}
Also used : BlockCommentBuilder(net.morimekta.providence.generator.format.java.utils.BlockCommentBuilder)

Aggregations

BlockCommentBuilder (net.morimekta.providence.generator.format.java.utils.BlockCommentBuilder)25 JField (net.morimekta.providence.generator.format.java.utils.JField)8 Generated (javax.annotation.Generated)3 GeneratorException (net.morimekta.providence.generator.GeneratorException)3 LinkedHashSet (java.util.LinkedHashSet)2 PContainer (net.morimekta.providence.descriptor.PContainer)2 JMessage (net.morimekta.providence.generator.format.java.utils.JMessage)2 JService (net.morimekta.providence.generator.format.java.utils.JService)2 JServiceMethod (net.morimekta.providence.generator.format.java.utils.JServiceMethod)2 CService (net.morimekta.providence.reflect.contained.CService)2 Config (com.hazelcast.config.Config)1 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)1 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)1 Portable (com.hazelcast.nio.serialization.Portable)1 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 List (java.util.List)1 Optional (java.util.Optional)1