Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support pattern matching in switch statements #511

Conversation

clementdessoude
Copy link
Contributor

What changed with this PR:

Supports pattern matching in switch rules.

Still needs a few unit tests to check everything is ok.

Example

// Input
class T {
    static String formatterPatternSwitch(Object o) {
        return switch (o) {
            case

                Integer i ->


                String.format("int %d", i);
                    case Long l    -> String.format("long %d", l);
            case Double d  -> String.format("double %f", d);
            case String s  -> String.format("String %s", s);
            case TOTO  -> String.format("TOTO %s", o);
            case null -> String.format("Null !");
            case default -> String.format("Default !");
                    default        -> o.toString();
        };
    }
}

// Output
static String formatterPatternSwitch(Object o) {
    return switch (o) {
      case Integer i -> String.format("int %d", i);
      case Long l -> String.format("long %d", l);
      case Double d -> String.format("double %f", d);
      case String s -> String.format("String %s", s);
      case TOTO -> String.format("TOTO %s", o);
      case null -> String.format("Null !");
      case default -> String.format("Default !");
      default -> o.toString();
    };
  }

Relative issues or prs:

Closes #510

@clementdessoude clementdessoude force-pushed the feat/510-support-pattern-matching-for-switch branch from 94a9a93 to c35dc8f Compare October 16, 2021 08:24
@clementdessoude clementdessoude force-pushed the feat/510-support-pattern-matching-for-switch branch from c35dc8f to 7657121 Compare October 16, 2021 08:25
@clementdessoude clementdessoude merged commit 2f7efa4 into jhipster:main Oct 16, 2021
@clementdessoude clementdessoude deleted the feat/510-support-pattern-matching-for-switch branch October 16, 2021 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support preview feature: Pattern Matching for switch
1 participant