override fun visitWhenExpression()

in core/src/main/java/com/facebook/ktfmt/format/KotlinInputAstVisitor.kt [1779:1826]


  override fun visitWhenExpression(expression: KtWhenExpression) {
    builder.sync(expression)
    builder.block(ZERO) {
      builder.token("when")
      expression.subjectExpression?.let { subjectExp ->
        builder.space()
        builder.block(ZERO) {
          builder.token("(")
          builder.block(if (isGoogleStyle) expressionBreakIndent else ZERO) { visit(subjectExp) }
          if (isGoogleStyle) {
            builder.breakOp(Doc.FillMode.UNIFIED, "", ZERO)
          }
        }
        builder.token(")")
      }
      builder.space()
      builder.token("{", Doc.Token.RealOrImaginary.REAL, blockIndent, Optional.of(blockIndent))

      expression.entries.forEach { whenEntry ->
        builder.block(blockIndent) {
          builder.forcedBreak()
          if (whenEntry.isElse) {
            builder.token("else")
          } else {
            builder.block(ZERO) {
              forEachCommaSeparated(whenEntry.conditions.asIterable()) { visit(it) }
              builder.guessToken(",")
            }
          }
          val whenExpression = whenEntry.expression
          builder.space()
          builder.token("->")
          if (whenExpression is KtBlockExpression) {
            builder.space()
            visit(whenExpression)
          } else {
            builder.block(expressionBreakIndent) {
              builder.breakOp(Doc.FillMode.INDEPENDENT, " ", ZERO)
              visit(whenExpression)
            }
          }
          builder.guessToken(";")
        }
        builder.forcedBreak()
      }
      builder.token("}")
    }
  }