Skip to content

Commit

Permalink
StatementSwitchToExpressionSwitch - remove // fall out comments in …
Browse files Browse the repository at this point in the history
…switches

PiperOrigin-RevId: 696930118
  • Loading branch information
cushon authored and Error Prone Team committed Nov 15, 2024
1 parent b5fa441 commit c816c8b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,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 @@ -4705,4 +4705,42 @@ String f(int x) {
"-XepOpt:StatementSwitchToExpressionSwitch:EnableReturnSwitchConversion=true")
.doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);
}

@Test
public void fallOutComment() {
refactoringHelper
.addInputLines(
"Test.java",
"""
public class Test {
String f(int x) {
switch (x) {
case 0:
return "ZERO";
default: // fall out
}
return "";
}
}
""")
.addOutputLines(
"Test.java",
"""
public class Test {
String f(int x) {
switch (x) {
case 0 -> {
return "ZERO";
}
default -> {}
}
return "";
}
}
""")
.setArgs(
"-XepOpt:StatementSwitchToExpressionSwitch:EnableDirectConversion=true",
"-XepOpt:StatementSwitchToExpressionSwitch:EnableReturnSwitchConversion=true")
.doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);
}
}

0 comments on commit c816c8b

Please sign in to comment.