Parameters and local variables: add isAnonymous predicate

This commit is contained in:
Chris Smowton
2024-03-13 16:52:06 +00:00
parent 7377cbb46e
commit 33b807f3bb
2 changed files with 13 additions and 1 deletions

View File

@@ -1691,6 +1691,9 @@ class LocalVariableDeclExpr extends Expr, @localvariabledeclexpr {
/** Gets the name of the variable declared by this local variable declaration expression. */
string getName() { result = this.getVariable().getName() }
/** Holds if this is an anonymous local variable, `_` */
predicate isAnonymous() { this.getName() = "" }
/**
* Gets the switch statement or expression whose pattern declares this identifier, if any.
*/
@@ -1763,7 +1766,9 @@ class LocalVariableDeclExpr extends Expr, @localvariabledeclexpr {
}
/** Gets a printable representation of this expression. */
override string toString() { result = this.getName() }
override string toString() {
if this.getName() = "" then result = "<anonymous local variable>" else result = this.getName()
}
override string getAPrimaryQlClass() { result = "LocalVariableDeclExpr" }
}

View File

@@ -117,4 +117,11 @@ class Parameter extends Element, @param, LocalScopeVariable {
}
override string getAPrimaryQlClass() { result = "Parameter" }
override string toString() {
if this.getName() = "" then result = "<anonymous parameter>" else result = super.toString()
}
/** Holds if this is an anonymous parameter, `_` */
predicate isAnonymous() { this.getName() = "" }
}