Java: Update 2 queries.

This commit is contained in:
Anders Schack-Mulligen
2020-01-24 13:42:59 +01:00
parent 4bd332ddca
commit f8805ebb24
2 changed files with 17 additions and 4 deletions

View File

@@ -12,8 +12,9 @@
import java
from MulExpr e
from MulExpr e, RemExpr lhs
where
e.getLeftOperand() instanceof RemExpr and
e.getLeftOperand() = lhs and
not lhs.isParenthesized() and
e.getRightOperand().getType().hasName("int")
select e, "Result of a remainder operation multiplied by an integer."

View File

@@ -120,12 +120,24 @@ predicate endOfBinaryLhs(BinaryExpr expr, int line, int col) {
)
}
/** Compute the number of parenthesis characters next to the operator. */
int getParensNextToOp(BinaryExpr expr) {
exists(Expr left, Expr right, int pleft, int pright |
left = expr.getLeftOperand() and
right = expr.getRightOperand() and
(if left.isParenthesized() then isParenthesized(left, pleft) else pleft = 0) and
(if right.isParenthesized() then isParenthesized(right, pright) else pright = 0) and
result = pleft + pright
)
}
/** Compute whitespace around the operator. */
int operatorWS(BinaryExpr expr) {
exists(int line, int lcol, int rcol |
exists(int line, int lcol, int rcol, int parens |
endOfBinaryLhs(expr, line, lcol) and
startOfBinaryRhs(expr, line, rcol) and
result = rcol - lcol + 1 - expr.getOp().length()
parens = getParensNextToOp(expr) and
result = rcol - lcol + 1 - expr.getOp().length() - parens
)
}