public void postVisit(ASTNode node) {
      // check that parent is && or ||
      if (!(node.getParent() instanceof InfixExpression)) return;

      // we want to add parenthesis around arithmetic operators and instanceof
      boolean needParenthesis = false;
      if (node instanceof InfixExpression) {
        InfixExpression expression = (InfixExpression) node;
        InfixExpression.Operator operator = expression.getOperator();

        InfixExpression parentExpression = (InfixExpression) node.getParent();
        InfixExpression.Operator parentOperator = parentExpression.getOperator();

        if (parentOperator == operator) return;

        needParenthesis =
            (operator == InfixExpression.Operator.LESS)
                || (operator == InfixExpression.Operator.GREATER)
                || (operator == InfixExpression.Operator.LESS_EQUALS)
                || (operator == InfixExpression.Operator.GREATER_EQUALS)
                || (operator == InfixExpression.Operator.EQUALS)
                || (operator == InfixExpression.Operator.NOT_EQUALS)
                || (operator == InfixExpression.Operator.CONDITIONAL_AND)
                || (operator == InfixExpression.Operator.CONDITIONAL_OR);
      }
      if (node instanceof InstanceofExpression) {
        needParenthesis = true;
      }
      if (!needParenthesis) {
        return;
      }
      fNodes.add(node);
    }
 private static int getExpressionPrecedence(Expression expression) {
   if (expression instanceof PostfixExpression || expression instanceof FunctionInvocation) {
     return 0;
   }
   if (expression instanceof PrefixExpression) {
     return 1;
   }
   if (expression instanceof ClassInstanceCreation) {
     return 2;
   }
   if (expression instanceof InfixExpression) {
     InfixExpression infixExpression = (InfixExpression) expression;
     InfixExpression.Operator operator = infixExpression.getOperator();
     return getInfixOperatorPrecedence(operator);
   }
   if (expression instanceof InstanceofExpression) {
     return 6;
   }
   if (expression instanceof ConditionalExpression) {
     return 13;
   }
   if (expression instanceof Assignment) {
     return 14;
   }
   return -1;
 }
 /*
  * @see ASTVisitor#visit(InfixExpression)
  */
 public boolean visit(InfixExpression node) {
   node.getLeftOperand().accept(this);
   this.fBuffer.append(' '); // for cases like x= i - -1; or x= i++ + ++i;
   this.fBuffer.append(node.getOperator().toString());
   this.fBuffer.append(' ');
   node.getRightOperand().accept(this);
   final List extendedOperands = node.extendedOperands();
   if (extendedOperands.size() != 0) {
     this.fBuffer.append(' ');
     for (Iterator it = extendedOperands.iterator(); it.hasNext(); ) {
       this.fBuffer.append(node.getOperator().toString()).append(' ');
       Expression e = (Expression) it.next();
       e.accept(this);
     }
   }
   return false;
 }
 public void postVisit(ASTNode node) {
   if (!(node instanceof ParenthesizedExpression)) {
     return;
   }
   ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) node;
   Expression expression = parenthesizedExpression.getExpression();
   while (expression instanceof ParenthesizedExpression) {
     expression = ((ParenthesizedExpression) expression).getExpression();
   }
   // if this is part of another expression, check for this and parent precedences
   if (parenthesizedExpression.getParent() instanceof Expression) {
     Expression parentExpression = (Expression) parenthesizedExpression.getParent();
     int expressionPrecedence = getExpressionPrecedence(expression);
     int parentPrecedence = getExpressionPrecedence(parentExpression);
     if ((expressionPrecedence > parentPrecedence)
         && !(parenthesizedExpression.getParent() instanceof ParenthesizedExpression)) {
       return;
     }
     // check for case when precedences for expression and parent are same
     if ((expressionPrecedence == parentPrecedence)
         && (parentExpression instanceof InfixExpression)) {
       // we have expr infix (expr infix expr) removing the parenthesis is equal to (expr infix
       // expr) infix expr
       InfixExpression parentInfix = (InfixExpression) parentExpression;
       Operator parentOperator = parentInfix.getOperator();
       if (parentInfix.getLeftOperand() == parenthesizedExpression) {
         fNodes.add(node);
       } else if (isAssoziative(parentOperator)) {
         if (parentOperator == InfixExpression.Operator.PLUS) {
           if (isStringExpression(parentInfix.getLeftOperand())
               || isStringExpression(parentInfix.getRightOperand())) {
             return;
           }
           for (Iterator J = parentInfix.extendedOperands().iterator(); J.hasNext(); ) {
             Expression operand = (Expression) J.next();
             if (isStringExpression(operand)) {
               return;
             }
           }
         }
         fNodes.add(node);
       }
       return;
     } else if (expressionPrecedence == parentPrecedence
         && parentExpression instanceof ConditionalExpression) {
       if (((ConditionalExpression) parentExpression).getElseExpression()
           != parenthesizedExpression) return;
     }
   }
   fNodes.add(node);
 }