Skip to content

Assign Return Value To New Variable for switch expressions #9162

@nmatt

Description

@nmatt

Description

The hint Assign Return Value To New Variable is available for most expressions, but not for switch expressions.

Use case/motivation

Example:

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:

int [name] = switch (fooBar) { case FOO -> 10; case BAR -> 20; };

For comparison, it is available on:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Java[ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)kind:featureA feature requestneeds:triageRequires attention from one of the committers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions