Skip to content

Conversation

@jtkiesel
Copy link
Contributor

@jtkiesel jtkiesel commented Dec 1, 2025

What changed with this PR:

Empty switch/case, try/catch/finally, and if/else blocks are now broken, to align more closely with Prettier TypeScript's behavior. One notable difference is that a single try statement can have multiple catch blocks in Java. For simplicity, I decided that if there are multiple catch blocks, all of them will break (even the last one).

Example

Input

void ifStatements() {
  if (a) {}
  if (a) {} else {}
  if (a) {} else if (b) {} else {}
}

void switchStatements() {
  switch (a) {}
  switch (a) {
    case 1: {}
    default: {}
  }
  switch (a) {
    case 1: {} {}
    default: {} {}
  }
  switch (a) {
    case 1 -> {}
    default -> {}
  }
}

void tryStatements() {
  try {} catch (Exception e) {}
  try (var a = new A()) {} catch (Exception e) {}
  try {} finally {}
  try (var a = new A()) {} finally {}
  try {} catch (Exception e) {} finally {}
  try (var a = new A()) {} catch (Exception e) {} finally {}
  try {} catch (Exception e) {} catch (Exception e) {}
  try (var a = new A()) {} catch (Exception e) {} catch (Exception e) {}
  try {} catch (Exception e) {} catch (Exception e) {} finally {}
  try (var a = new A()) {} catch (Exception e) {} catch (Exception e) {} finally {}
}

Output

void ifStatements() {
  if (a) {
  }
  if (a) {
  } else {
  }
  if (a) {
  } else if (b) {
  } else {
  }
}

void switchStatements() {
  switch (a) {
  }
  switch (a) {
    case 1: {
    }
    default: {
    }
  }
  switch (a) {
    case 1:
      {
      }
      {
      }
    default:
      {
      }
      {
      }
  }
  switch (a) {
    case 1 -> {
    }
    default -> {
    }
  }
}

void tryStatements() {
  try {
  } catch (Exception e) {}
  try (var a = new A()) {
  } catch (Exception e) {}
  try {
  } finally {
  }
  try (var a = new A()) {
  } finally {
  }
  try {
  } catch (Exception e) {
  } finally {
  }
  try (var a = new A()) {
  } catch (Exception e) {
  } finally {
  }
  try {
  } catch (Exception e) {
  } catch (Exception e) {
  }
  try (var a = new A()) {
  } catch (Exception e) {
  } catch (Exception e) {
  }
  try {
  } catch (Exception e) {
  } catch (Exception e) {
  } finally {
  }
  try (var a = new A()) {
  } catch (Exception e) {
  } catch (Exception e) {
  } finally {
  }
}

Relative issues or prs:

Closes #789

@jtkiesel jtkiesel force-pushed the fix/break-some-empty-blocks branch from 247e362 to b7926d3 Compare December 15, 2025 07:27
@jtkiesel jtkiesel merged commit 92a2223 into jhipster:main Dec 16, 2025
6 checks passed
@jtkiesel jtkiesel deleted the fix/break-some-empty-blocks branch December 16, 2025 02:18
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.

Ugly formatting with empty try block

1 participant