Skip to content

Convert switch expressions with colon to arrows #799

@timtebeek

Description

@timtebeek

Describe the situation before applying the recipe

class A {
    void doFormat(String str) {
        String formatted = switch (str) {
            case "foo": yield "Foo";
            case "bar": yield "Bar";
            case null, default: yield "unknown";
        };
    }
}

Describe the situation after applying the recipe

class A {
    void doFormat(String str) {
        String formatted = switch (str) {
            case "foo" -> "Foo";
            case "bar" -> "Bar";
            case null, default -> "Other";
        };
    }
}

Have you considered any alternatives or workarounds?

Did not want to make this part of other recipes: it can stand alone for smaller complexity and isolated value.

Any additional context

Ideally we start this off minimally: only where all cases directly contain yield. That way we have something quickly and can chain in this recipe visitor as a doAfterVisit for SwitchCaseAssignmentsToSwitchExpression.

Metadata

Metadata

Assignees

Labels

recipeRecipe requested

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions