GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Java 14 switch expressions with many values are badly formatted · Issue #540 · google/google-java-format

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

New issue
Copy link
New issue
Copy link
Closed
Closed
Java 14 switch expressions with many values are badly formatted#540
Copy link

Description

@abrudin
abrudin
opened on Oct 31, 2020
Issue body actions

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).

Reacted by Marc Löhe, Anthony Vanelverdinghe, Johan Magnusson, Igor Skokov and Filipe Sousa

Activity

  1. copybara-service
    closed this as completedin 72672b0on Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.