Skip to content

Commit

Permalink
Remove // fall out comments, which are sometimes used to document a…
Browse files Browse the repository at this point in the history
…n empty `default:` statement group

PiperOrigin-RevId: 658827224
  • Loading branch information
cushon authored and Error Prone Team committed Aug 2, 2024
1 parent ac7ebf5 commit 474554a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public final class StatementSwitchToExpressionSwitch extends BugChecker
ImmutableSet.of(THROW, EXPRESSION_STATEMENT);
private static final ImmutableSet<Kind> KINDS_RETURN_OR_THROW = ImmutableSet.of(THROW, RETURN);
private static final Pattern FALL_THROUGH_PATTERN =
Pattern.compile("\\bfalls?.?through\\b", Pattern.CASE_INSENSITIVE);
Pattern.compile("\\bfalls?.?(through|out)\\b", Pattern.CASE_INSENSITIVE);
// Default (negative) result for assignment switch conversion analysis. Note that the value is
// immutable.
private static final AssignmentSwitchAnalysisResult DEFAULT_ASSIGNMENT_SWITCH_ANALYSIS_RESULT =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3657,4 +3657,36 @@ public void unnecessaryBreaks() {
.setArgs("-XepOpt:StatementSwitchToExpressionSwitch:EnableDirectConversion=true")
.doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);
}

@Test
public void fallOutComment() {
assumeTrue(RuntimeVersion.isAtLeast14());
refactoringHelper
.addInputLines(
"Test.java",
"public class Test {",
" void f(int x) {",
" switch (x) {",
" case 0:",
" System.err.println(\"ZERO\");",
" break;",
" default:",
" // fall out",
" }",
" }",
"}")
.addOutputLines(
"Test.java",
"public class Test {",
" void f(int x) {",
" switch (x) {",
" case 0 -> System.err.println(\"ZERO\");",
" default -> {}",
" }",
" }",
"}")
.setArgs(
ImmutableList.of("-XepOpt:StatementSwitchToExpressionSwitch:EnableDirectConversion"))
.doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);
}
}

0 comments on commit 474554a

Please sign in to comment.