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

Wrap multiple values in switch expression case #558

Closed
wants to merge 2 commits into from

Conversation

fawind
Copy link
Contributor

@fawind fawind commented Jan 6, 2021

Closes #540

  • Wrap multiple values covered in a switch expression case if they exceed the max line length.
    switch (e) {
    -  case SOME_RATHER_LONG_NAME_1, SOME_RATHER_LONG_NAME_2, SOME_RATHER_LONG_NAME_3 -> {}
    +  case SOME_RATHER_LONG_NAME_1,
    +    SOME_RATHER_LONG_NAME_2,
    +    SOME_RATHER_LONG_NAME_3 -> {}
    }
  • Also collapse empty case blocks in switch expressions.
     switch (e) {
    -  case CASE_A -> {
    -  }
    +  case CASE_A -> {}
     }

@google-cla google-cla bot added the cla: yes label Jan 6, 2021
@fawind fawind changed the title Wrap multiple values in switch expressions case Wrap multiple values in switch expression case Jan 6, 2021
@abrudin
Copy link

abrudin commented Apr 16, 2021

Was it ever clear why this PR failed the Java 16 check? The logs have expired, is it possible to retrigger the checks for this PR?

@fawind
Copy link
Contributor Author

fawind commented Apr 17, 2021

The failing JDK 16 and now 17 check seems to be unrelated to this change. I believe it's a general problem with the formatter as e.g. the same tests fail on master for the JDK 17 check (ref). I don't think it's in the scope of this PR to fix them.

@cushon, mind taking a look when you have a spare minute? Thanks!

@cushon
Copy link
Collaborator

cushon commented Apr 17, 2021

Thanks for the fix!

I don't think it's in the scope of this PR to fix them.

Agreed: the tests aren't passing on JDK 17 at head yet. That configuration is marked as 'experimental' and won't block merging, but the UI makes it look like a failure.

Also I realized we're not breaking after the -> in expression switches with expression bodies either, but that doesn't need to happen in this change:

return switch (e) {
  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 ->
      fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff();
  case SOME_RATHER_LONG_NAME_8 ->
      fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff();
};

copybara-service bot pushed a commit that referenced this pull request Feb 4, 2022
Since the last plugin update was almost half a year ago, I thought it would be prudent to update it and resolve most of the issues regarding updating the plugin.

It took around half an hour once I managed to correctly set up the module due to the gradle plugin version 1.2.1 + intellij version 2020.3 requiring java 11 to develop.

All of the included annotation changes were requested by IntelliJ to add since the overrides added them as well.

The change of `<? extends TextRange>` to `<TextRange>` was to resolve the syntax errors introduced by a change removing the wildcard requirement.

NotificationGroup was deprecated and moved into the plugin xml file as per the SDK docs
The same was required for `StdFileTypes.JAVA` being deprecated with the fix being `JavaFileType.INSTANCE` + changing the depend module to add that fix.

I had to change the project SDK to JDK 11 on my end to have the gradle build work.

I also tested the plugin with 1.12 and 1.10 on some test files such as from #653 and #654. Would be good to have some double checking though because I've had issues trying to get the test file reformatted in #558 working. Probably because it's locked behind an experimental flag?

Fixes #688

COPYBARA_INTEGRATE_REVIEW=#688 from ze:idea-1.12.0 53f216c
PiperOrigin-RevId: 426491735
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Java 14 switch expressions with many values are badly formatted
3 participants