unexpected code reformat for XML pattern matching

Hi All,

I have some code look like this:

import scala.xml.XML

object Test {
  def main(args: Array[String]): Unit = {
    val xmlString = <xml>
      <VeryLongTagName>someName</VeryLongTagName>
    </xml>
    for (node <- xmlString.child) {
      node match {
        case <VeryLongTagName>{varName}</VeryLongTagName> => println(varName)
        case _ => println("otherwise")
      }
    }
  }
}

Output:
someName

After applying 'Code Reformat', the pattern is split into three lines like this:

import scala.xml.XML

object Test {
  def main(args: Array[String]): Unit = {
    val xmlString = <xml>
      <VeryLongTagName>someName</VeryLongTagName>
    </xml>
    for (node <- xmlString.child) {
      node match {
        case <VeryLongTagName>
          {varName}
          </VeryLongTagName> => println(varName)
        case _ => println("otherwise")
      }
    }
  }
}

Output:
otherwise
otherwise
otherwise


The reformat is problematic because it broke the code, i.e. the pattern doesn't work as expected any more.

Does anyone have a similar experience? any idea how to fix this?

My setup:
IDEA community version 13.1.5
OS: Fedora 3.15.8-200.fc20.x86_64

Thanks,
-Xiao

1 comment
Comment actions Permalink

It can be fixed by

"Settings -> Code Style -> Scala -> Wrapping and braces -> XML formatting -> keep xml formatting."

Hope it helps.

0

Please sign in to leave a comment.