File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed
main/java/com/google/errorprone/bugpatterns
test/java/com/google/errorprone/bugpatterns Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -95,7 +95,7 @@ public final class StatementSwitchToExpressionSwitch extends BugChecker
9595 ImmutableSet .of (THROW , EXPRESSION_STATEMENT );
9696 private static final ImmutableSet <Kind > KINDS_RETURN_OR_THROW = ImmutableSet .of (THROW , RETURN );
9797 private static final Pattern FALL_THROUGH_PATTERN =
98- Pattern .compile ("\\ bfalls?.?through\\ b" , Pattern .CASE_INSENSITIVE );
98+ Pattern .compile ("\\ bfalls?.?( through|out) \\ b" , Pattern .CASE_INSENSITIVE );
9999 // Default (negative) result for assignment switch conversion analysis. Note that the value is
100100 // immutable.
101101 private static final AssignmentSwitchAnalysisResult DEFAULT_ASSIGNMENT_SWITCH_ANALYSIS_RESULT =
Original file line number Diff line number Diff line change @@ -4705,4 +4705,42 @@ String f(int x) {
47054705 "-XepOpt:StatementSwitchToExpressionSwitch:EnableReturnSwitchConversion=true" )
47064706 .doTest (BugCheckerRefactoringTestHelper .TestMode .TEXT_MATCH );
47074707 }
4708+
4709+ @ Test
4710+ public void fallOutComment () {
4711+ refactoringHelper
4712+ .addInputLines (
4713+ "Test.java" ,
4714+ """
4715+ public class Test {
4716+ String f(int x) {
4717+ switch (x) {
4718+ case 0:
4719+ return "ZERO";
4720+ default: // fall out
4721+ }
4722+ return "";
4723+ }
4724+ }
4725+ """ )
4726+ .addOutputLines (
4727+ "Test.java" ,
4728+ """
4729+ public class Test {
4730+ String f(int x) {
4731+ switch (x) {
4732+ case 0 -> {
4733+ return "ZERO";
4734+ }
4735+ default -> {}
4736+ }
4737+ return "";
4738+ }
4739+ }
4740+ """ )
4741+ .setArgs (
4742+ "-XepOpt:StatementSwitchToExpressionSwitch:EnableDirectConversion=true" ,
4743+ "-XepOpt:StatementSwitchToExpressionSwitch:EnableReturnSwitchConversion=true" )
4744+ .doTest (BugCheckerRefactoringTestHelper .TestMode .TEXT_MATCH );
4745+ }
47084746}
You can’t perform that action at this time.
0 commit comments