mirror of
https://github.com/github/codeql.git
synced 2026-04-29 02:35:15 +02:00
Java: Add Expr.isParenthesized, adjust VarAccess.toString, and fix tests.
This commit is contained in:
@@ -13,7 +13,10 @@ import java
|
||||
|
||||
predicate nontrivialLogicalOperator(BinaryExpr e) {
|
||||
e instanceof LogicExpr and
|
||||
not e.getParent().(Expr).getKind() = e.getKind()
|
||||
(
|
||||
not e.getParent().(Expr).getKind() = e.getKind() or
|
||||
e.isParenthesized()
|
||||
)
|
||||
}
|
||||
|
||||
Expr getSimpleParent(Expr e) {
|
||||
|
||||
@@ -95,6 +95,9 @@ class Expr extends ExprParent, @expr {
|
||||
or
|
||||
exists(LambdaExpr lam | lam.asMethod() = getEnclosingCallable() and lam.isInStaticContext())
|
||||
}
|
||||
|
||||
/** Holds if this expression is parenthesized. */
|
||||
predicate isParenthesized() { isParenthesized(this, _) }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1330,7 +1333,11 @@ class VarAccess extends Expr, @varaccess {
|
||||
|
||||
/** Gets a printable representation of this expression. */
|
||||
override string toString() {
|
||||
result = this.getQualifier().toString() + "." + this.getVariable().getName()
|
||||
exists(Expr q | q = this.getQualifier() |
|
||||
if q.isParenthesized()
|
||||
then result = "(...)." + this.getVariable().getName()
|
||||
else result = q.toString() + "." + this.getVariable().getName()
|
||||
)
|
||||
or
|
||||
not this.hasQualifier() and result = this.getVariable().getName()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user