private boolean shouldProtect ( Expression operand , OperandPosition operandPosition ) { if ( operand instanceof Operation ) { Operation operation = ( Operation ) operand ; return operation . precedence ( ) < this . precedence ( ) || ( operation . precedence ( ) == this . precedence ( ) && operandPosition . shouldParenthesize ( operation . associativity ( ) ) ) ; } else if ( operand instanceof Leaf ) { // JsExprs have precedence info, but not associativity. So at least check the precedence. JsExpr expr = ( ( Leaf ) operand ) . value ( ) ; return expr . getPrecedence ( ) < this . precedence ( ) ; } else { return false ; } }
An operand needs to be protected with parens if