Skip to content

Commit

Permalink
Restore private cleanupBooleanExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Oct 27, 2024
1 parent ee9fc7b commit 923b38e
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ public J visitBlock(J.Block block, ExecutionContext ctx) {
return bl;
}

@SuppressWarnings("unchecked")
private static <E extends Expression> E cleanupBooleanExpression(E expression, Cursor c, ExecutionContext ctx) {
E ex1 = (E) new UnnecessaryParenthesesVisitor<>().visitNonNull(expression, ctx, c.getParentOrThrow());
ex1 = (E) new SimplifyBooleanExpressionVisitor().visitNonNull(ex1, ctx, c.getParentTreeCursor());
if (expression == ex1 ||
J.Literal.isLiteralValue(ex1, Boolean.FALSE) ||
J.Literal.isLiteralValue(ex1, Boolean.TRUE)) {
return ex1;
}
// Run recursively until no further changes are needed
return cleanupBooleanExpression(ex1, c, ctx);
}

@Override
public J visitIf(J.If if_, ExecutionContext ctx) {
J.If if__ = (J.If) super.visitIf(if_, ctx);
Expand Down Expand Up @@ -131,17 +144,4 @@ public J visitIf(J.If if_, ExecutionContext ctx) {
}
}
}

@SuppressWarnings("unchecked")
static <E extends Expression> E cleanupBooleanExpression(E expression, Cursor c, ExecutionContext ctx) {
E ex1 = (E) new UnnecessaryParenthesesVisitor<>().visitNonNull(expression, ctx, c.getParentOrThrow());
ex1 = (E) new SimplifyBooleanExpressionVisitor().visitNonNull(ex1, ctx, c.getParentTreeCursor());
if (expression == ex1 ||
J.Literal.isLiteralValue(ex1, Boolean.FALSE) ||
J.Literal.isLiteralValue(ex1, Boolean.TRUE)) {
return ex1;
}
// Run recursively until no further changes are needed
return cleanupBooleanExpression(ex1, c, ctx);
}
}

0 comments on commit 923b38e

Please sign in to comment.