Search in sources :

Example 1 with ValueBuilder

use of net.morimekta.providence.generator.format.java.utils.ValueBuilder in project providence by morimekta.

the class CommonMemberFormatter method appendFieldDefaultValues.

private void appendFieldDefaultValues(JMessage<?> message) throws GeneratorException {
    ValueBuilder values = new ValueBuilder(writer, helper);
    values.appendDefaultConstants(message.declaredOrderFields());
}
Also used : ValueBuilder(net.morimekta.providence.generator.format.java.utils.ValueBuilder)

Example 2 with ValueBuilder

use of net.morimekta.providence.generator.format.java.utils.ValueBuilder in project providence by morimekta.

the class JavaConstantsFormatter method appendProgramClass.

@Override
public void appendProgramClass(CProgram program) throws GeneratorException {
    ValueBuilder value = new ValueBuilder(writer, helper);
    if (program.getDocumentation() != null) {
        new BlockCommentBuilder(writer).comment(program.getDocumentation()).finish();
    }
    if (javaOptions.generated_annotation_version) {
        writer.formatln("@%s(\"%s %s\")", Generated.class.getName(), generatorOptions.generator_program_name, generatorOptions.program_version);
    } else {
        writer.formatln("@%s(\"%s\")", Generated.class.getName(), generatorOptions.generator_program_name);
    }
    writer.appendln("@SuppressWarnings(\"unused\")").formatln("public class %s {", helper.getConstantsClassName(program)).begin().formatln("private %s() {}", helper.getConstantsClassName(program));
    for (CField c : program.getConstants()) {
        writer.newline();
        try {
            String name = c.getName();
            writer.formatln("public static final %s %s;", helper.getValueType(c.getDescriptor()), name).appendln("static {").begin().formatln("%s = ", name).begin();
            value.appendTypedValue(c.getDefaultValue(), c.getDescriptor());
            writer.append(';').end().end().appendln('}');
        } catch (Exception e) {
            throw new GeneratorException("Unable to generate constant " + program.getProgramName() + "." + c.getName(), e);
        }
    }
    writer.end().appendln('}').newline();
}
Also used : ValueBuilder(net.morimekta.providence.generator.format.java.utils.ValueBuilder) Generated(javax.annotation.Generated) CField(net.morimekta.providence.reflect.contained.CField) BlockCommentBuilder(net.morimekta.providence.generator.format.java.utils.BlockCommentBuilder) GeneratorException(net.morimekta.providence.generator.GeneratorException) GeneratorException(net.morimekta.providence.generator.GeneratorException)

Aggregations

ValueBuilder (net.morimekta.providence.generator.format.java.utils.ValueBuilder)2 Generated (javax.annotation.Generated)1 GeneratorException (net.morimekta.providence.generator.GeneratorException)1 BlockCommentBuilder (net.morimekta.providence.generator.format.java.utils.BlockCommentBuilder)1 CField (net.morimekta.providence.reflect.contained.CField)1