code: public static boolean hasSideEffect(Expression expr) {
      VariableElement var = TreeUtil.getVariableElement(expr);
      if (var != null && ElementUtil.isVolatile(var)) {
        return true;
      }
      switch (expr.getKind()) {
        case BOOLEAN_LITERAL:
        case CHARACTER_LITERAL:
        case NULL_LITERAL:
        case NUMBER_LITERAL:
        case QUALIFIED_NAME:
        case SIMPLE_NAME:
        case STRING_LITERAL:
        case SUPER_FIELD_ACCESS:
        case THIS_EXPRESSION:
          return false;
        case CAST_EXPRESSION:
          return hasSideEffect(((CastExpression) expr).getExpression());
        case CONDITIONAL_EXPRESSION:
          {
            ConditionalExpression condExpr = (ConditionalExpression) expr;
            return hasSideEffect(condExpr.getExpression())
                || hasSideEffect(condExpr.getThenExpression())
                || hasSideEffect(condExpr.getElseExpression());
          }
        case FIELD_ACCESS:
          return hasSideEffect(((FieldAccess) expr).getExpression());
        case INFIX_EXPRESSION:
          for (Expression operand : ((InfixExpression) expr).getOperands()) {
            if (hasSideEffect(operand)) {
              return true;
            }
          }
          return false;
        case PARENTHESIZED_EXPRESSION:
          return hasSideEffect(((ParenthesizedExpression) expr).getExpression());
        case PREFIX_EXPRESSION:
          {
            PrefixExpression preExpr = (PrefixExpression) expr;
            PrefixExpression.Operator op = preExpr.getOperator();
            return op == PrefixExpression.Operator.INCREMENT
                || op == PrefixExpression.Operator.DECREMENT
                || hasSideEffect(preExpr.getOperand());
          }
        default:
          return true;
      }
    }
docs: Reterns whether the expression might have any side effects. If true, it
  would be unsafe to prune the given node from the tree.