All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.jbock.writing.CodeBlocks Maven / Gradle / Ivy

There is a newer version: 5.18
Show newest version
package net.jbock.writing;

import io.jbock.javapoet.CodeBlock;

import java.util.List;

final class CodeBlocks {

    static CodeBlock joinByNewline(List code) {
        boolean indent = false;
        CodeBlock.Builder result = CodeBlock.builder();
        for (int i = 0; i < code.size(); i++) {
            if (i == 0) {
                result.add(code.get(i));
            } else if (i == 1) {
                result.add("\n").indent().add(code.get(i));
                indent = true;
            } else {
                result.add("\n").add(code.get(i));
            }
        }
        if (indent) {
            result.unindent();
        }
        return result.build();
    }

    static CodeBlock joinByComma(List code) {
        CodeBlock.Builder args = CodeBlock.builder();
        for (int i = 0; i < code.size(); i++) {
            if (i != 0) {
                args.add(",$W");
            }
            args.add(code.get(i));
        }
        return args.build();
    }

    private CodeBlocks() {
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy