Skip to content

Commit 54c356b

Browse files
committed
Bring back code in ExprFormatter
This code was accidentally removed during a code cleanup.
1 parent e16a6bc commit 54c356b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

scalariform/src/main/scala/scalariform/formatter/ExprFormatter.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,24 @@ trait ExprFormatter { self: HasFormattingPreferences with AnnotationFormatter wi
448448
formatResult ++= format(body)(bodyFormatterState)
449449

450450
// TODO: Simplified version of elseClause formatting
451+
for (CatchClause(catchToken, catchBlockOrExpr) catchClauseOption) {
452+
if (formattingPreferences(CompactControlReadability) && bodyIsABlock && containsNewline(body))
453+
formatResult = formatResult.before(catchToken, formatterState.currentIndentLevelInstruction)
454+
else if (hiddenPredecessors(catchToken).containsNewline && !(bodyIsABlock && containsNewline(body)))
455+
formatResult = formatResult.before(catchToken, formatterState.currentIndentLevelInstruction)
456+
457+
catchBlockOrExpr match {
458+
case Left(catchBlock)
459+
formatResult = formatResult.before(catchBlock.firstToken, CompactEnsuringGap)
460+
formatResult ++= format(catchBlock)
461+
case Right(catchExpr)
462+
val indentCatchExpr = hiddenPredecessors(catchExpr.firstToken).containsNewline
463+
val instruction = if (indentCatchExpr) formatterState.nextIndentLevelInstruction else CompactEnsuringGap
464+
formatResult = formatResult.before(catchExpr.firstToken, instruction)
465+
val catchExprFormatterState = if (indentCatchExpr) formatterState.indent else formatterState
466+
formatResult ++= format(catchExpr)(catchExprFormatterState)
467+
}
468+
}
451469

452470
// TODO: See elseClause formatting
453471
for ((finallyToken, finallyBody) finallyClauseOption) {

0 commit comments

Comments
 (0)