[clang] [clang-format] Handle Java switch expressions (PR #91112)

Emilia Kond via cfe-commits cfe-commits at lists.llvm.org
Mon May 6 02:32:02 PDT 2024


https://github.com/rymiel approved this pull request.

Also works well for pattern matching
```java
switch (obj) {
  case String s when !s.isEmpty() -> 0;
  default                         -> 1;
}
```
and upcoming destructuring
```java
switch (n) {
  case IntExpr(int i)              -> i;
  case NegExpr(Expr n)             -> -1 * eval(n);
  case AddExpr(Expr lhs, Expr rhs) -> eval(lhs) + eval(rhs);
  case MulExpr(Expr lhs, Expr rhs) -> eval(lhs) * eval(rhs);
  default                          -> throw new IllegalStateException();
};
```

https://github.com/llvm/llvm-project/pull/91112


More information about the cfe-commits mailing list