From 474554a79ae02f6f1482b2e3da78e88c11db37ff Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Fri, 2 Aug 2024 10:16:59 -0700 Subject: [PATCH] Remove `// fall out` comments, which are sometimes used to document an empty `default:` statement group PiperOrigin-RevId: 658827224 --- .../StatementSwitchToExpressionSwitch.java | 2 +- ...StatementSwitchToExpressionSwitchTest.java | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitch.java b/core/src/main/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitch.java index 39b5b7585d0..824600c1015 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitch.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitch.java @@ -94,7 +94,7 @@ public final class StatementSwitchToExpressionSwitch extends BugChecker ImmutableSet.of(THROW, EXPRESSION_STATEMENT); private static final ImmutableSet 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 = diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitchTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitchTest.java index be63a77f336..0ea13ecd6a1 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitchTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitchTest.java @@ -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); + } }