Assign Return Value To New Variable for switch expressions
- Dominant language
- Java
- Stars
- 3.1k
- Forks
- 935
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 17
Description
### Description
The hint Assign Return Value To New Variable is available for most expressions, but not for switch expressions.
### Use case/motivation
Example:
```java
enum FooBar { FOO, BAR };
FooBar fooBar = FooBar.FOO;
switch (fooBar) { case FOO -> 10; case BAR -> 20; };
```
The hint should be available on the *switch* line and result in:
```java
int [name] = switch (fooBar) { case FOO -> 10; case BAR -> 20; };
```
For comparison, it is available on:
```java
fooBar == FooBar.FOO ? 10 : fooBar == FooBar.BAR ? 20 : -1;
```
The usefulness should hopefully be obvious.
### Related issues
_No response_
### Are you willing to submit a pull request?
No
Contributor guide
Research direction
Start by locating the implementation of the “Assign Return Value To New Variable” hint and the existing handling for other expressions. Trace how the hint determines the expression type, then verify that applying it to a switch expression produces the declaration shown in the issue and preserves the switch result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100