javapoet-dsl / com.mostlycertain.javapoetdsl / CodeBuilder / ifDecl

ifDecl

fun ifDecl(conditionFormat: String, vararg conditionArgs: Any, block: CodeFunc): IfFlow

Render an if-else condition.

The "else" and "else if" are declared by chaining calls to the returned IfFlow.

Example: ifDecl("var == %L", variableName) { s("return A") }.elseIfDecl("var == null") { s("return B") }.elseDecl { s("return C") }

    // -- Result --
    // if (var == otherVar) {
    //   return A;
    // } else if (var == null) {
    //   return B;
    // } else {
    //   return C;
    // }
fun ifDecl(condition: CodeExpression, block: CodeFunc): IfFlow