How to auto enumerate cases when writing pattern match?

For example, I have follow list of case class definitions.

trait A
case class B extends A
case class C extends A
case class D extends A

When I write pattern match on A,

def foo(x: A) = x match {
  case B => ???
  case C => ???
  case D => ???
}

Is there any way to auto fill those case statements "case B, C, D"??? I remember it is possible when develop in Java to handle enumerations.
Btw, I am running Intellij 12 on Mac.

4 comments
Comment actions Permalink

It's good idea. Thank you! I created the issue: http://youtrack.jetbrains.com/issue/SCL-6550

Best regards,
Alexander Podkhalyuzin.

0
Comment actions Permalink

The issue state is still 'open'...

0
Comment actions Permalink

And it's probably going to stay that way... Jetbrains is more interested in Kotlin than Scala these days :-(

0
Comment actions Permalink

Hi @Fernado Jimenez,

They actually implemented this a few years ago. You can find out how to use it here:

https://www.jetbrains.com/help/idea/edit-scala-code.html#ce0afed0

Basically if you pick "case (exhaustive)", it will enumerate all cases automatically for you.

0

Please sign in to leave a comment.