@Override
 public boolean visit(IfStatement node) {
   visitAndExtract(node.getExpression(), node);
   node.getThenStatement().accept(this);
   Statement elseStmt = node.getElseStatement();
   if (elseStmt != null) {
     elseStmt.accept(this);
   }
   return false;
 }
예제 #2
0
 @Override
 public void endVisit(IfStatement node) {
   Expression expr = node.getExpression();
   Boolean value = getKnownValue(expr);
   if (value != null) {
     Statement sideEffects = getSideEffects(expr);
     if (sideEffects != null) {
       TreeUtil.insertBefore(node, sideEffects);
     }
     if (value) {
       node.replaceWith(TreeUtil.remove(node.getThenStatement()));
     } else if (node.getElseStatement() != null) {
       node.replaceWith(TreeUtil.remove(node.getElseStatement()));
     } else {
       node.remove();
     }
   }
 }