jhipster / prettier-java

Prettier Java Plugin
http://www.jhipster.tech/prettier-java/
Apache License 2.0
1.08k stars 103 forks source link

fix: separate binary expression from pattern #606

Closed jtkiesel closed 10 months ago

jtkiesel commented 1 year ago

What changed with this PR:

Rather than treating the optional binary expression following a pattern as part of the pattern itself, treat the entire expression as a binary expression, of which the pattern is a part, so that the usual binary expression formatting applies.

Example

Input

class Example {

  public boolean test(final Object obj) {
    return obj instanceof final Integer x && (x == 5 || x == 6 || x == 7 || x == 8 || x == 9 || x == 10 || x == 11);
  }
}

Output

class Example {

  public boolean test(final Object obj) {
    return (
      obj instanceof final Integer x &&
      (x == 5 || x == 6 || x == 7 || x == 8 || x == 9 || x == 10 || x == 11)
    );
  }
}

Relative issues or prs:

Closes #605

jtkiesel commented 11 months ago

611 solves the issue described in #605 also, while simultaneously supporting the now-official "when" style of guards. Assuming that PR is merged, we can close this one.