Skip to content

Commit 4960305

Browse files
authored
Merge pull request github#13025 from cklin/java-location-tostring-bindingset
Java: Add pragma[only_bind_out] to Top::toString() calls
2 parents ededd46 + d968cee commit 4960305

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Exception extends Element, @exception {
2626
/** Holds if this exception has the specified `name`. */
2727
override predicate hasName(string name) { this.getType().hasName(name) }
2828

29-
override string toString() { result = this.getType().toString() }
29+
override string toString() { result = pragma[only_bind_out](this.getType()).toString() }
3030

3131
override string getAPrimaryQlClass() { result = "Exception" }
3232
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,9 @@ class TypeLiteral extends Expr, @typeliteral {
16441644
Type getReferencedType() { result = this.getTypeName().getType() }
16451645

16461646
/** Gets a printable representation of this expression. */
1647-
override string toString() { result = this.getTypeName().toString() + ".class" }
1647+
override string toString() {
1648+
result = pragma[only_bind_out](this.getTypeName()).toString() + ".class"
1649+
}
16481650

16491651
override string getAPrimaryQlClass() { result = "TypeLiteral" }
16501652
}
@@ -1752,7 +1754,7 @@ class VarAccess extends Expr, @varaccess {
17521754
exists(Expr q | q = this.getQualifier() |
17531755
if q.isParenthesized()
17541756
then result = "(...)." + this.getVariable().getName()
1755-
else result = q.toString() + "." + this.getVariable().getName()
1757+
else result = pragma[only_bind_out](q).toString() + "." + this.getVariable().getName()
17561758
)
17571759
or
17581760
not this.hasQualifier() and result = this.getVariable().getName()

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ class ImportType extends Import {
2727
/** Gets the imported type. */
2828
ClassOrInterface getImportedType() { imports(this, result, _, _) }
2929

30-
override string toString() { result = "import " + this.getImportedType().toString() }
30+
override string toString() {
31+
result = "import " + pragma[only_bind_out](this.getImportedType()).toString()
32+
}
3133

3234
override string getAPrimaryQlClass() { result = "ImportType" }
3335
}
@@ -49,7 +51,9 @@ class ImportOnDemandFromType extends Import {
4951
/** Gets an imported type. */
5052
NestedType getAnImport() { result.getEnclosingType() = this.getTypeHoldingImport() }
5153

52-
override string toString() { result = "import " + this.getTypeHoldingImport().toString() + ".*" }
54+
override string toString() {
55+
result = "import " + pragma[only_bind_out](this.getTypeHoldingImport()).toString() + ".*"
56+
}
5357

5458
override string getAPrimaryQlClass() { result = "ImportOnDemandFromType" }
5559
}
@@ -71,7 +75,7 @@ class ImportOnDemandFromPackage extends Import {
7175

7276
/** Gets a printable representation of this import declaration. */
7377
override string toString() {
74-
result = "import " + this.getPackageHoldingImport().toString() + ".*"
78+
result = "import " + pragma[only_bind_out](this.getPackageHoldingImport()).toString() + ".*"
7579
}
7680

7781
override string getAPrimaryQlClass() { result = "ImportOnDemandFromPackage" }
@@ -100,7 +104,7 @@ class ImportStaticOnDemand extends Import {
100104

101105
/** Gets a printable representation of this import declaration. */
102106
override string toString() {
103-
result = "import static " + this.getTypeHoldingImport().toString() + ".*"
107+
result = "import static " + pragma[only_bind_out](this.getTypeHoldingImport()).toString() + ".*"
104108
}
105109

106110
override string getAPrimaryQlClass() { result = "ImportStaticOnDemand" }
@@ -141,7 +145,9 @@ class ImportStaticTypeMember extends Import {
141145

142146
/** Gets a printable representation of this import declaration. */
143147
override string toString() {
144-
result = "import static " + this.getTypeHoldingImport().toString() + "." + this.getName()
148+
result =
149+
"import static " + pragma[only_bind_out](this.getTypeHoldingImport()).toString() + "." +
150+
this.getName()
145151
}
146152

147153
override string getAPrimaryQlClass() { result = "ImportStaticTypeMember" }

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,9 @@ class AnonymousClass extends NestedClass {
804804
// Include super.toString, i.e. the name given in the database, because for Kotlin anonymous
805805
// classes we can get specialisations of anonymous generic types, and this will supply the
806806
// trailing type arguments.
807-
result = "new " + this.getClassInstanceExpr().getTypeName() + "(...) { ... }" + super.toString()
807+
result =
808+
"new " + pragma[only_bind_out](this.getClassInstanceExpr().getTypeName()).toString() +
809+
"(...) { ... }" + super.toString()
808810
}
809811

810812
/**

0 commit comments

Comments
 (0)