Skip to content

Commit e1c1ac2

Browse files
markhbradyError Prone Team
authored andcommitted
[RefactorSwitch] flip flag to enable simplification of switches
PiperOrigin-RevId: 899771743
1 parent e6d13c5 commit e1c1ac2

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,7 +1901,7 @@ ValidateCommonParams withSubject(Optional<ExpressionTree> subject) {
19011901
* This record is an intermediate representation of a single `x instanceof Y` or `x instanceof Y
19021902
* y` expression.
19031903
*/
1904-
record InstanceOfIr(
1904+
private record InstanceOfIr(
19051905
// In the example above, the expression would be `y`.
19061906
Optional<ExpressionTree> expression,
19071907
// In the example above, the variable tree would be `Y y`.
@@ -1919,7 +1919,7 @@ record InstanceOfIr(
19191919
* being synthesized. Its scope is roughly equivalent to a `CaseTree` in Java's AST, although does
19201920
* not cover all of the same functionality.
19211921
*/
1922-
record CaseIr(
1922+
private record CaseIr(
19231923
boolean hasCaseNull,
19241924
boolean hasDefault,
19251925
// The pattern, if any
@@ -1950,14 +1950,15 @@ record CaseIr(
19501950
* Container for the subject (of an if predicate) and a (non-empty) list of expressions that can
19511951
* match that subject in the given case.
19521952
*/
1953-
record SubjectAndCaseExpressions(ExpressionTree subject, List<ExpressionTree> expressions) {
1953+
private record SubjectAndCaseExpressions(
1954+
ExpressionTree subject, List<ExpressionTree> expressions) {
19541955
SubjectAndCaseExpressions {
19551956
checkArgument(!expressions.isEmpty());
19561957
}
19571958
}
19581959

19591960
/** This record represents the current state of the analysis of an if-chain. */
1960-
record IfChainAnalysisState(
1961+
private record IfChainAnalysisState(
19611962
// The expression to be switched on (if known)
19621963
Optional<ExpressionTree> subjectOptional,
19631964
// Depth of the if statement being analyzed (relative to the start of the if-chain)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public final class RefactorSwitch extends BugChecker
106106
RefactorSwitch(ErrorProneFlags flags) {
107107
enableAssignmentSwitch = flags.getBoolean("RefactorSwitch:EnableAssignmentSwitch").orElse(true);
108108
enableReturnSwitch = flags.getBoolean("RefactorSwitch:EnableReturnSwitch").orElse(true);
109-
enableSimplifySwitch = flags.getBoolean("RefactorSwitch:EnableSimplifySwitch").orElse(false);
109+
enableSimplifySwitch = flags.getBoolean("RefactorSwitch:EnableSimplifySwitch").orElse(true);
110110
}
111111

112112
@Override

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,7 @@ private static NullDefaultKind analyzeCaseForNullAndDefault(CaseTree caseTree) {
18211821
* @param symbolsToHoist Bidirectional map from symbols to hoist to the top of the switch
18221822
* statement to their declaration trees
18231823
*/
1824-
record AnalysisResult(
1824+
private record AnalysisResult(
18251825
boolean canConvertDirectlyToExpressionSwitch,
18261826
boolean canConvertToReturnSwitch,
18271827
boolean canRemoveDefault,
@@ -1839,7 +1839,7 @@ record AnalysisResult(
18391839
* @param assignmentSourceCodeOptional Java source code of the assignment switch's operator, e.g.
18401840
* "+="
18411841
*/
1842-
record AssignmentSwitchAnalysisResult(
1842+
private record AssignmentSwitchAnalysisResult(
18431843
boolean canConvertToAssignmentSwitch,
18441844
Optional<VariableTree> precedingVariableDeclaration,
18451845
Optional<ExpressionTree> assignmentTargetOptional,
@@ -1853,7 +1853,7 @@ record AssignmentSwitchAnalysisResult(
18531853
* @param assignmentExpressionKindOptional Kind of the first assignment seen, if any
18541854
* @param assignmentTreeOptional ExpressionTree of the first assignment seen, if any
18551855
*/
1856-
record AssignmentSwitchAnalysisState(
1856+
private record AssignmentSwitchAnalysisState(
18571857
CaseQualifications assignmentSwitchCaseQualifications,
18581858
Optional<ExpressionTree> assignmentTargetOptional,
18591859
Optional<Tree.Kind> assignmentExpressionKindOptional,

0 commit comments

Comments
 (0)