Search in sources :

Example 1 with CAnnotatedDescriptor

use of net.morimekta.providence.reflect.contained.CAnnotatedDescriptor in project providence by morimekta.

the class BaseMessageFormatter method appendMessageClass.

public void appendMessageClass(PMessageDescriptor<?, ?> descriptor) throws GeneratorException {
    @SuppressWarnings("unchecked") JMessage<?> message = new JMessage(descriptor, helper);
    BlockCommentBuilder classComment = null;
    if (message.descriptor() instanceof CAnnotatedDescriptor) {
        CAnnotatedDescriptor annotatedDescriptor = (CAnnotatedDescriptor) message.descriptor();
        if (annotatedDescriptor.getDocumentation() != null) {
            classComment = new BlockCommentBuilder(writer);
            classComment.comment(annotatedDescriptor.getDocumentation());
        }
        String deprecatedReason = annotatedDescriptor.getAnnotationValue(ThriftAnnotation.DEPRECATED);
        if (deprecatedReason != null && deprecatedReason.trim().length() > 0) {
            if (classComment == null) {
                classComment = new BlockCommentBuilder(writer);
            } else {
                classComment.newline();
            }
            classComment.deprecated_(deprecatedReason);
        }
    }
    if (classComment != null) {
        classComment.finish();
    }
    formatters.forEach(f -> f.appendClassAnnotations(message));
    writer.formatln("%s %sclass %s", makeProtected ? "protected" : "public", inner ? "static " : "", getClassName(message)).begin().begin();
    appendClassExtends(message);
    writer.end();
    Set<String> impl = new LinkedHashSet<>();
    formatters.forEach(f -> impl.addAll(f.getExtraImplements(message)));
    if (impl.size() > 0) {
        writer.formatln("    implements ").begin("               ");
        boolean first = true;
        for (String i : impl) {
            if (first) {
                first = false;
            } else {
                writer.append(',').appendln();
            }
            writer.append(i);
        }
        writer.end();
    }
    writer.append(" {");
    formatters.forEach(f -> f.appendConstants(message));
    formatters.forEach(f -> f.appendFields(message));
    formatters.forEach(f -> f.appendConstructors(message));
    formatters.forEach(f -> f.appendMethods(message));
    formatters.forEach(f -> f.appendExtraProperties(message));
    writer.end().appendln('}');
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CAnnotatedDescriptor(net.morimekta.providence.reflect.contained.CAnnotatedDescriptor) JMessage(net.morimekta.providence.generator.format.java.utils.JMessage) BlockCommentBuilder(net.morimekta.providence.generator.format.java.utils.BlockCommentBuilder)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)1 BlockCommentBuilder (net.morimekta.providence.generator.format.java.utils.BlockCommentBuilder)1 JMessage (net.morimekta.providence.generator.format.java.utils.JMessage)1 CAnnotatedDescriptor (net.morimekta.providence.reflect.contained.CAnnotatedDescriptor)1