Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 33b807f

Browse files
committed
Parameters and local variables: add isAnonymous predicate
1 parent 7377cbb commit 33b807f

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

java/ql/lib/semmle/code/java/Expr.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,9 @@ class LocalVariableDeclExpr extends Expr, @localvariabledeclexpr {
16911691
/** Gets the name of the variable declared by this local variable declaration expression. */
16921692
string getName() { result = this.getVariable().getName() }
16931693

1694+
/** Holds if this is an anonymous local variable, `_` */
1695+
predicate isAnonymous() { this.getName() = "" }
1696+
16941697
/**
16951698
* Gets the switch statement or expression whose pattern declares this identifier, if any.
16961699
*/
@@ -1763,7 +1766,9 @@ class LocalVariableDeclExpr extends Expr, @localvariabledeclexpr {
17631766
}
17641767

17651768
/** Gets a printable representation of this expression. */
1766-
override string toString() { result = this.getName() }
1769+
override string toString() {
1770+
if this.getName() = "" then result = "<anonymous local variable>" else result = this.getName()
1771+
}
17671772

17681773
override string getAPrimaryQlClass() { result = "LocalVariableDeclExpr" }
17691774
}

java/ql/lib/semmle/code/java/Variable.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,11 @@ class Parameter extends Element, @param, LocalScopeVariable {
117117
}
118118

119119
override string getAPrimaryQlClass() { result = "Parameter" }
120+
121+
override string toString() {
122+
if this.getName() = "" then result = "<anonymous parameter>" else result = super.toString()
123+
}
124+
125+
/** Holds if this is an anonymous parameter, `_` */
126+
predicate isAnonymous() { this.getName() = "" }
120127
}

0 commit comments

Comments
 (0)