Skip to content

Commit

Permalink
StatementSwitchToExpressionSwitch: to improve readability, for direct…
Browse files Browse the repository at this point in the history
… conversions where the case expression has an enclosing brace, place a newline immediately after the opening brace

PiperOrigin-RevId: 646478013
  • Loading branch information
java-team-github-bot authored and Error Prone Team committed Jun 25, 2024
1 parent 5277c90 commit a2b0ff6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ private static SuggestedFix convertDirectlyToExpressionSwitch(
|| trimmedTransformedBlockSource.equals("break;")) {
replacementCodeBuilder.append("{}");
} else {
replacementCodeBuilder.append("{").append(transformedBlockSource).append("\n}");
replacementCodeBuilder.append("{\n").append(transformedBlockSource).append("\n}");
}
} else {
// Transformed block has code
Expand All @@ -585,7 +585,7 @@ private static SuggestedFix convertDirectlyToExpressionSwitch(
replacementCodeBuilder.append(transformedBlockSource);
} else {
// Use braces on the rhs
replacementCodeBuilder.append("{").append(transformedBlockSource).append("\n}");
replacementCodeBuilder.append("{\n").append(transformedBlockSource).append("\n}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public void switchByEnum_removesRedundantBreak_error() {
" ",
" public void foo(Side side) { ",
" switch(side) {",
" case OBVERSE -> { /* left comment */",
" case OBVERSE -> {",
" /* left comment */",
" /* and there is more: */",
" // to end of line",
" // Explanatory comment",
Expand Down

0 comments on commit a2b0ff6

Please sign in to comment.