Skip to content

Commit

Permalink
Don't force empty blocks to be single line
Browse files Browse the repository at this point in the history
  • Loading branch information
mdr committed Sep 9, 2010
1 parent 3fa2f85 commit 578ceed
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -4,6 +4,7 @@
* Bug fixes for if/for/while inside paren expressions
* Handle Scala parsing exceptions in command-line tool
* Parse and format a sequence of XML nodes correctly
* No longer force empty blocks to be single line (class A {})

0.0.4 (17/July/10)
* Add Maven/Tycho build
Expand Down
Expand Up @@ -426,23 +426,25 @@ trait ExprFormatter { self: HasFormattingPreferences with AnnotationFormatter wi
formatResult ++= format(caseClauses)(newFormatterState)

case Right(statSeq) {
if (!singleLineBlock && statSeq.firstTokenOption.isDefined) {
statSeq.firstStatOpt match {
case Some(Expr(List(AnonymousFunctionStart(params, _), subStatSeq))) {
formatResult = formatResult.before(statSeq.firstToken, CompactEnsuringGap)
for (firstToken subStatSeq.firstTokenOption)
formatResult = formatResult.before(firstToken, newFormatterState.nextIndentLevelInstruction)
formatResult ++= format(params)
formatResult ++= format(subStatSeq)(newFormatterState.indent)
}
case _ {
val instruction =
if (statSeq.selfReferenceOpt.isDefined)
CompactEnsuringGap
else
newFormatterState.nextIndentLevelInstruction
formatResult = formatResult.before(statSeq.firstToken, instruction)
formatResult ++= format(statSeq)(newFormatterState.indent)
if (!singleLineBlock) {
if (statSeq.firstTokenOption.isDefined) {
statSeq.firstStatOpt match {
case Some(Expr(List(AnonymousFunctionStart(params, _), subStatSeq))) {
formatResult = formatResult.before(statSeq.firstToken, CompactEnsuringGap)
for (firstToken subStatSeq.firstTokenOption)
formatResult = formatResult.before(firstToken, newFormatterState.nextIndentLevelInstruction)
formatResult ++= format(params)
formatResult ++= format(subStatSeq)(newFormatterState.indent)
}
case _ {
val instruction =
if (statSeq.selfReferenceOpt.isDefined)
CompactEnsuringGap
else
newFormatterState.nextIndentLevelInstruction
formatResult = formatResult.before(statSeq.firstToken, instruction)
formatResult ++= format(statSeq)(newFormatterState.indent)
}
}
}
formatResult = formatResult.before(rbrace, newFormatterState.currentIndentLevelInstruction)
Expand Down
Expand Up @@ -97,4 +97,16 @@ class BlockExprFormatterTest extends AbstractExpressionFormatterTest {
| false
|}"""

"""{
|}""" ==>
"""{
|}"""

"""{
|
|}""" ==>
"""{
|
|}"""

}
Expand Up @@ -142,7 +142,8 @@ class IfExprFormatterTest extends AbstractExpressionFormatterTest {

"""if (true){
|}""" ==>
"""if (true) {}"""
"""if (true) {
|}"""

"if (true){;}" ==> "if (true) { ; }"

Expand Down
Expand Up @@ -459,6 +459,13 @@ class TemplateFormatterTest extends AbstractFormatterTest {
"private [a] case class B" ==> "private[a] case class B"
"private [a] object B" ==> "private[a] object B"

"""class A {
|
|}""" ==>
"""class A {
|
|}"""

// format: ON

override val debug = false
Expand Down
Expand Up @@ -57,7 +57,8 @@ class TryExprFormatterTest extends AbstractExpressionFormatterTest {
|} catch { case e => }finally
|{
|println("foo") }""" ==>
"""try {} catch { case e => }
"""try {
|} catch { case e => }
|finally {
| println("foo")
|}"""
Expand Down

0 comments on commit 578ceed

Please sign in to comment.