|
|
@ -9,14 +9,15 @@ public final class TernaryTransformer extends Transformer { |
|
|
|
public void transform(CompilationUnit unit) { |
|
|
|
public void transform(CompilationUnit unit) { |
|
|
|
unit.findAll(ConditionalExpr.class).forEach(expr -> { |
|
|
|
unit.findAll(ConditionalExpr.class).forEach(expr -> { |
|
|
|
var condition = expr.getCondition(); |
|
|
|
var condition = expr.getCondition(); |
|
|
|
if (!ExprUtils.isNot(condition)) { |
|
|
|
var notCondition = ExprUtils.not(condition); |
|
|
|
|
|
|
|
if (ExprUtils.countNots(notCondition) >= ExprUtils.countNots(condition)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var thenExpr = expr.getThenExpr(); |
|
|
|
var thenExpr = expr.getThenExpr(); |
|
|
|
var elseExpr = expr.getElseExpr(); |
|
|
|
var elseExpr = expr.getElseExpr(); |
|
|
|
|
|
|
|
|
|
|
|
expr.setCondition(ExprUtils.not(condition)); |
|
|
|
expr.setCondition(notCondition); |
|
|
|
expr.setThenExpr(elseExpr.clone()); |
|
|
|
expr.setThenExpr(elseExpr.clone()); |
|
|
|
expr.setElseExpr(thenExpr.clone()); |
|
|
|
expr.setElseExpr(thenExpr.clone()); |
|
|
|
}); |
|
|
|
}); |
|
|
|