google / google-java-format

Reformats Java source code to comply with Google Java Style.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IntelliJ : .stream is not in the new line even if set on intelliJ format settings

vpresecki opened this issue · comments

What steps will reproduce the issue?

  1. google-java-plugin enabled
  2. In settings-> Editor -> Code Style -> Java -> Chained method calls :
    wrap always
    wrap fist call
  3. Format some code with .stream() : example -> list.stream()....
    What is the expected result?

Every .stream() should be in new line (alone) -> example: list
.stream()

What happens instead?
.stream() is in the same line as list

If google-java-format is disabled, it will work as expected....

Google Java Format enforces a single style (well, two, with AOSP), which basically cannot be configured. None of the configuration under Settings-> Editor -> Code Style -> Java should have any effect. The plugin handles .stream() specially; see #341.

This makes absolutley no sense... this is enforced on IntelliJ but not on Eclipse?
It is the official google-java-format plugin used in two separate IDE-s and it formats code differently.

EDIT: To make it more clear... one part of our team is using Eclipse, other part is using IntelliJ... Both Eclipse users and IntelliJ users have google-java-format installed (we also tried by export/import settings and with just importing XML)... And .stream() is formatted differently

Can you share an example of the Java code that is formatted differently? Are you sure that both sets of developers have enabled the same version of google-java-format?

Sure.
Google java format in Eclipse:

    settingWrappers =
        settings
            .stream()
            .map(
                setting -> {
                  // wrap Campaign Extension Settings with related Extension Feed Items
                  CampaignExtensionSettingWrapper settingWrapper =
                      new CampaignExtensionSettingWrapper(setting);

Google java format in IntelliJ:

    settingWrappers =
        settings.stream()
            .map(
                setting -> {
                  // wrap Campaign Extension Settings with related Extension Feed Items
                  CampaignExtensionSettingWrapper settingWrapper =
                      new CampaignExtensionSettingWrapper(setting);

This happens everywhere with stream operation... in intelliJ .stream() will never be in new line, or in eclipse it will never be in one line.... Either way, seams like they are not formatting in the same way

The correct formatting with recent versions of the formatter is:

class T {
  {
    settingWrappers =
        settings.stream()
            .map(
                setting -> {
                  // wrap Campaign Extension Settings with related Extension Feed Items
                  CampaignExtensionSettingWrapper settingWrapper =
                      new CampaignExtensionSettingWrapper(setting);
                });
  }
}

There's some context about why .stream() isn't on a new line in the bug @Stephan202 linked to: #341

If you're seeing Eclipse produce a different formatting, either the google-java-format plugin isn't enabled, or it's using an old version of google-java-format that predates that change.