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

fix(printer): properly break and indent lambda with comments #604

Merged
merged 1 commit into from
Feb 15, 2024

Conversation

jtkiesel
Copy link
Contributor

@jtkiesel jtkiesel commented Sep 6, 2023

What changed with this PR:

Lambda expressions with leading/trailing comments are now broken and indented properly. Also, lambda expressions in general are formatted more similarly to Prettier JavaScript.

Example

Input

class Example {

  void example() {
    System.out.println(
      List.of(1, 2, 3).stream().map(
        // a very long comment which explains the beatifullness of multiplication by 2
        // yes this is very important
        v -> v * 2
      ).collect(Collectors.summingInt(v -> v))
    );
  }

  void example() {
    System.out.println(
      List.of(1, 2, 3).stream().map(
        v -> v * 2
        // a very long comment which explains the beatifullness of multiplication by 2
        // yes this is very important
      ).collect(Collectors.summingInt(v -> v))
    );
  }
}

Output

class Example {

  void example() {
    System.out.println(
      List.of(1, 2, 3)
        .stream()
        .map(
          // a very long comment which explains the beatifullness of multiplication by 2
          // yes this is very important
          v -> v * 2
        )
        .collect(Collectors.summingInt(v -> v))
    );
  }

  void example() {
    System.out.println(
      List.of(1, 2, 3)
        .stream()
        .map(
          v -> v * 2
          // a very long comment which explains the beatifullness of multiplication by 2
          // yes this is very important
        )
        .collect(Collectors.summingInt(v -> v))
    );
  }
}

Relative issues or prs:

Closes #581

@jtkiesel jtkiesel force-pushed the fix/lambda-with-comments branch 3 times, most recently from 9070129 to 5ceccde Compare February 14, 2024 02:39
@jtkiesel jtkiesel force-pushed the fix/lambda-with-comments branch from 5ceccde to e95f469 Compare February 14, 2024 02:41
@jtkiesel
Copy link
Contributor Author

@clementdessoude This one should now be ready for review as well, if/when you have the time.

@clementdessoude clementdessoude merged commit 6457cc5 into jhipster:main Feb 15, 2024
6 checks passed
@jtkiesel jtkiesel deleted the fix/lambda-with-comments branch April 11, 2024 06:06
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.

Comments in parenthesis code block are wrapped on a single line
2 participants