Skip to content

feat: improve throws breaking - #591

Merged
jtkiesel merged 1 commit into
jhipster:mainfrom
jtkiesel:fix/improve-throws-formatting
Oct 14, 2026
Merged

jtkiesel merged 1 commit into
jhipster:mainfrom
jtkiesel:fix/improve-throws-formatting

Conversation

@jtkiesel

@jtkiesel jtkiesel commented Jul 29, 2023 •

Copy link
Copy Markdown
Contributor

What changed with this PR:

Constructors/methods with throws clauses with multiple exception types may now break on their comma-separated list of exception types, and the left curly brace of the body is broken onto its own line when the throws clause is broken in order to separate the exception classes from the body (since they will be at the same indentation).

The formatting decisions here are strongly inspired by and aligned with the way the implements clause is printed on Prettier TypeScript (and Java) classes, as they are syntactically similar.

Example

Input

class Example {

  Example(String arg1, String arg2)
    throws RuntimeException, RuntimeException, RuntimeException, RuntimeException {
    throw new RuntimeException();
  }

  Example(
    String arg1,
    String arg2,
    String arg3,
    String arg4,
    String arg5,
    String arg6
  ) throws RuntimeException, RuntimeException, RuntimeException {
    throw new RuntimeException();
  }

  Example(
    String arg1,
    String arg2,
    String arg3,
    String arg4,
    String arg5,
    String arg6
  )
    throws RuntimeException, RuntimeException, RuntimeException, RuntimeException {
    throw new RuntimeException();
  }

  void example1(String arg1, String arg2)
    throws RuntimeException, RuntimeException, RuntimeException, RuntimeException {
    throw new RuntimeException();
  }

  void example2(
    String arg1,
    String arg2,
    String arg3,
    String arg4,
    String arg5,
    String arg6
  ) throws RuntimeException, RuntimeException, RuntimeException {
    throw new RuntimeException();
  }

  void example3(
    String arg1,
    String arg2,
    String arg3,
    String arg4,
    String arg5,
    String arg6
  )
    throws RuntimeException, RuntimeException, RuntimeException, RuntimeException {
    throw new RuntimeException();
  }
}

Output

class Example {

  Example(String arg1, String arg2)
    throws
      RuntimeException,
      RuntimeException,
      RuntimeException,
      RuntimeException
  {
    throw new RuntimeException();
  }

  Example(
    String arg1,
    String arg2,
    String arg3,
    String arg4,
    String arg5,
    String arg6
  ) throws RuntimeException, RuntimeException, RuntimeException {
    throw new RuntimeException();
  }

  Example(
    String arg1,
    String arg2,
    String arg3,
    String arg4,
    String arg5,
    String arg6
  )
    throws
      RuntimeException,
      RuntimeException,
      RuntimeException,
      RuntimeException
  {
    throw new RuntimeException();
  }

  void example1(String arg1, String arg2)
    throws
      RuntimeException,
      RuntimeException,
      RuntimeException,
      RuntimeException
  {
    throw new RuntimeException();
  }

  void example2(
    String arg1,
    String arg2,
    String arg3,
    String arg4,
    String arg5,
    String arg6
  ) throws RuntimeException, RuntimeException, RuntimeException {
    throw new RuntimeException();
  }

  void example3(
    String arg1,
    String arg2,
    String arg3,
    String arg4,
    String arg5,
    String arg6
  )
    throws
      RuntimeException,
      RuntimeException,
      RuntimeException,
      RuntimeException
  {
    throw new RuntimeException();
  }
}

Relative issues or prs:

Closes #429

@DanielFran DanielFran added $100 https://www.jhipster.tech/bug-bounties/ $$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ labels Aug 12, 2023
@jtkiesel
jtkiesel force-pushed the fix/improve-throws-formatting branch 3 times, most recently from e46ab97 to ea90004 Compare January 16, 2024 05:43
@jtkiesel
jtkiesel force-pushed the fix/improve-throws-formatting branch from ea90004 to e379f32 Compare February 10, 2024 23:46
@jtkiesel

Copy link
Copy Markdown
Contributor Author

@clementdessoude I'm curious what your thoughts are on the formatting decisions I made here. Could you take a look, whenever you have the time?

Comment thread packages/prettier-plugin-java/src/printers/classes.ts Outdated
@jtkiesel
jtkiesel force-pushed the fix/improve-throws-formatting branch from e379f32 to 8ec1626 Compare April 10, 2024 06:36
@jtkiesel
jtkiesel force-pushed the fix/improve-throws-formatting branch from 8ec1626 to feb3575 Compare October 13, 2026 07:03
@jtkiesel jtkiesel changed the title fix: improve throws formatting fix: improve throws breaking Oct 13, 2026
@jtkiesel
jtkiesel force-pushed the fix/improve-throws-formatting branch from feb3575 to 6249ec0 Compare October 13, 2026 07:04
@jtkiesel jtkiesel changed the title fix: improve throws breaking feat: improve throws breaking Oct 13, 2026
@jtkiesel
jtkiesel force-pushed the fix/improve-throws-formatting branch from 6249ec0 to 16af6f7 Compare October 13, 2026 08:00
@jtkiesel
jtkiesel force-pushed the fix/improve-throws-formatting branch from 16af6f7 to 4878fd3 Compare October 14, 2026 04:50
@jtkiesel
jtkiesel merged commit b97786b into jhipster:main Oct 14, 2026
6 checks passed
@jtkiesel
jtkiesel deleted the fix/improve-throws-formatting branch October 14, 2026 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

$$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ $100 https://www.jhipster.tech/bug-bounties/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Continuation Indent

3 participants