@@ -120,20 +120,33 @@ predicate endOfBinaryLhs(BinaryExpr expr, int line, int col) {
120120 )
121121}
122122
123+ /** Compute the number of parenthesis characters next to the operator. */
124+ int getParensNextToOp ( BinaryExpr expr ) {
125+ exists ( Expr left , Expr right , int pleft , int pright |
126+ left = expr .getLeftOperand ( ) and
127+ right = expr .getRightOperand ( ) and
128+ ( if left .isParenthesized ( ) then isParenthesized ( left , pleft ) else pleft = 0 ) and
129+ ( if right .isParenthesized ( ) then isParenthesized ( right , pright ) else pright = 0 ) and
130+ result = pleft + pright
131+ )
132+ }
133+
123134/** Compute whitespace around the operator. */
124135int operatorWS ( BinaryExpr expr ) {
125- exists ( int line , int lcol , int rcol |
136+ exists ( int line , int lcol , int rcol , int parens |
126137 endOfBinaryLhs ( expr , line , lcol ) and
127138 startOfBinaryRhs ( expr , line , rcol ) and
128- result = rcol - lcol + 1 - expr .getOp ( ) .length ( )
139+ parens = getParensNextToOp ( expr ) and
140+ result = rcol - lcol + 1 - expr .getOp ( ) .length ( ) - parens
129141 )
130142}
131143
132144/** Find nested binary expressions where the programmer may have made a precedence mistake. */
133145predicate interestingNesting ( BinaryExpr inner , BinaryExpr outer ) {
134146 inner = outer .getAChildExpr ( ) and
135147 not inner instanceof AssocNestedExpr and
136- not inner instanceof HarmlessNestedExpr
148+ not inner instanceof HarmlessNestedExpr and
149+ not inner .isParenthesized ( )
137150}
138151
139152from BinaryExpr inner , BinaryExpr outer , int wsouter , int wsinner
0 commit comments