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());
}
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();
}
Aggregations