ctx.replaceMe(elseExpr);
}
} else if (thenExpr instanceof JBooleanLiteral) {
if (((JBooleanLiteral) thenExpr).getValue()) {
// e.g. (cond ? true : else) -> cond || else
JBinaryOperation binOp = new JBinaryOperation(program,
x.getSourceInfo(), x.getType(), JBinaryOperator.OR, condExpr,
elseExpr);
ctx.replaceMe(binOp);
} else {
// e.g. (cond ? false : else) -> !cond && else
JPrefixOperation notCondExpr = new JPrefixOperation(program,
condExpr.getSourceInfo(), JUnaryOperator.NOT, condExpr);
JBinaryOperation binOp = new JBinaryOperation(program,
x.getSourceInfo(), x.getType(), JBinaryOperator.AND, notCondExpr,
elseExpr);
ctx.replaceMe(binOp);
}
} else if (elseExpr instanceof JBooleanLiteral) {
if (((JBooleanLiteral) elseExpr).getValue()) {
// e.g. (cond ? then : true) -> !cond || then
JPrefixOperation notCondExpr = new JPrefixOperation(program,
condExpr.getSourceInfo(), JUnaryOperator.NOT, condExpr);
JBinaryOperation binOp = new JBinaryOperation(program,
x.getSourceInfo(), x.getType(), JBinaryOperator.OR, notCondExpr,
thenExpr);
ctx.replaceMe(binOp);
} else {
// e.g. (cond ? then : false) -> cond && then
JBinaryOperation binOp = new JBinaryOperation(program,
x.getSourceInfo(), x.getType(), JBinaryOperator.AND, condExpr,
thenExpr);
ctx.replaceMe(binOp);
}
} else {