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

Java 14 switch expressions with many values are badly formatted #540

Closed
abrudin opened this issue Oct 31, 2020 · 0 comments
Closed

Java 14 switch expressions with many values are badly formatted #540

abrudin opened this issue Oct 31, 2020 · 0 comments

Comments

@abrudin
Copy link

abrudin commented Oct 31, 2020

When having many values covered by the same case, google-java-format does a terrible job formatting the code. Example:

public class GoogleJavaFormatFail {
  public String myMethod(final TestEnum testEnum) {
    return switch (testEnum) {
      case SOME_RATHER_LONG_NAME_1, SOME_RATHER_LONG_NAME_2, SOME_RATHER_LONG_NAME_3, SOME_RATHER_LONG_NAME_4, SOME_RATHER_LONG_NAME_5, SOME_RATHER_LONG_NAME_6, SOME_RATHER_LONG_NAME_7 -> "less than"
                                                                                                                                                                                                + " number"
                                                                                                                                                                                                + " 7";
      case SOME_RATHER_LONG_NAME_8 -> "number 8";
    };
  }

  public enum TestEnum {
    SOME_RATHER_LONG_NAME_1,
    SOME_RATHER_LONG_NAME_2,
    SOME_RATHER_LONG_NAME_3,
    SOME_RATHER_LONG_NAME_4,
    SOME_RATHER_LONG_NAME_5,
    SOME_RATHER_LONG_NAME_6,
    SOME_RATHER_LONG_NAME_7,
    SOME_RATHER_LONG_NAME_8
  }
}

This is a little sad, as the new switch statements are awesome for compile time type safety (make sure no case is missed).

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 a pull request may close this issue.

1 participant