Skip to content

Commit c816c8b

Browse files
cushonError Prone Team
authored and
Error Prone Team
committed
StatementSwitchToExpressionSwitch - remove // fall out comments in switches
PiperOrigin-RevId: 696930118
1 parent b5fa441 commit c816c8b

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

core/src/main/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitch.java

+1-1
Original file line numberDiff line numberDiff 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 =

core/src/test/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitchTest.java

+38
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)