eclipse-jdt / eclipse-jdt/eclipse.jdt.core
Formatting incorrect when using Inline Refactoring on method within switch expression
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 47
Description
Steps to reproduce:
Create a project based on the given sample source file. You'll need at least Java 14 to use the switch expression syntax :
Main.java
```
package org.example;
public class Main {
public static String format (String... input) {
return "";
}
public static void main(String[] args) {
int value = 0;
String message = switch (value) {
case 0 -> format("");
default -> "";
};
}
}
```
- Select the only `format` reference in `main()`
- `Refactor -> Inline` using whichever method you prefer (eg. `Refactor` menu item, or context menu)
- Select `Preview` or `Ok`
The changed code looks as below :
```
package org.example;
public class Main {
public static String format (String... input) {
return "";
}
public static void main(String[] args) {
int value = 0;
String message = switch (value) {
case 0 -> {
String[] input = { "" };
yield "";
}
default -> "";
};
}
}
```
The call `format("");` is replaced with the block
```
{
String[] input = { "" };
yield "";
}
```
But the block is not formatted correctly.
Contributor guide
Assessment
This issue has not been assessed yet.