in core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt [1856:1899]
override fun visitIfExpression(expression: KtIfExpression) {
builder.sync(expression)
builder.block(ZERO) {
builder.block(ZERO) {
builder.token("if")
builder.space()
builder.token("(")
builder.block(if (isGoogleStyle) expressionBreakIndent else ZERO) {
visit(expression.condition)
}
if (isGoogleStyle) {
builder.breakOp(Doc.FillMode.UNIFIED, "", ZERO)
}
}
builder.token(")")
if (expression.then is KtBlockExpression) {
builder.space()
builder.block(ZERO) { visit(expression.then) }
} else {
builder.breakOp(Doc.FillMode.INDEPENDENT, " ", expressionBreakIndent)
builder.block(expressionBreakIndent) { visit(expression.then) }
}
if (expression.elseKeyword != null) {
if (expression.then is KtBlockExpression) {
builder.space()
} else {
builder.breakOp(Doc.FillMode.UNIFIED, " ", ZERO)
}
builder.block(ZERO) {
builder.token("else")
if (expression.`else` is KtBlockExpression || expression.`else` is KtIfExpression) {
builder.space()
builder.block(ZERO) { visit(expression.`else`) }
} else {
builder.breakOp(Doc.FillMode.INDEPENDENT, " ", expressionBreakIndent)
builder.block(expressionBreakIndent) { visit(expression.`else`) }
}
}
}
}
}