mattmoore
05/12/2020, 1:42 AMKtWhenCondition and why it is a collection, but only seemed to have one item - running the Kotlin grammar through antlr, the parser will create multiple KtWhenCondition nodes if you use the comma as discussed earlier: when { y > 0, y < 10 -> //... } . However, while antlr parses this syntax, the compiler throws a deprecation warning and suggests using the conjunction/disjunction style with && and || which will not be picked up as multiple KtWhenCondition nodes. It all gets put into the first condition instead. It may be necessary, if using the comma style, to suppress that warning as well. My guess would be that JetBrains may eventually change that node structure at some point, and make the conditions a single node, instead of a collection of nodes. If so, that's something maybe to keep in mind for future compatibility.
Given a when expression:
when {
y > 0, y < 10 -> println(y)
}
KtWhenExpression = top level when node when { ... }
KtWhenEntry = y > 0, y < 10 -> println(y)
KtWhenCondition = collection with two items: y > 0 and y < 10
With conjunction instead:
when {
y > 0 && y < 10 -> println(y)
}
KtWhenExpression > when { ... }
KtWhenEntry > y > 0, y < 10 -> println(y)
KtWhenCondition > collection with single item: y > 0 && y < 10
Anyhow, that was confusing to me initially until I ran antlr on it.