Skip to content

Commit 081085e

Browse files
committed
Java: Make implicit this receivers explicit
1 parent 733a000 commit 081085e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+309
-292
lines changed

java/ql/lib/definitions.qll

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,33 @@ import IDEContextual
1717
*/
1818
private class LocationOverridingMethodAccess extends MethodAccess {
1919
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
20-
exists(MemberRefExpr e | e.getReferencedCallable() = getMethod() |
20+
exists(MemberRefExpr e | e.getReferencedCallable() = this.getMethod() |
2121
exists(int elRef, int ecRef | e.hasLocationInfo(path, _, _, elRef, ecRef) |
2222
sl = elRef and
23-
sc = ecRef - getMethod().getName().length() + 1 and
23+
sc = ecRef - this.getMethod().getName().length() + 1 and
2424
el = elRef and
2525
ec = ecRef
2626
)
2727
)
2828
or
29-
not exists(MemberRefExpr e | e.getReferencedCallable() = getMethod()) and
29+
not exists(MemberRefExpr e | e.getReferencedCallable() = this.getMethod()) and
3030
exists(int slSuper, int scSuper, int elSuper, int ecSuper |
3131
super.hasLocationInfo(path, slSuper, scSuper, elSuper, ecSuper)
3232
|
3333
(
34-
if exists(getTypeArgument(_))
34+
if exists(this.getTypeArgument(_))
3535
then
3636
exists(Location locTypeArg |
37-
locTypeArg = getTypeArgument(count(getTypeArgument(_)) - 1).getLocation()
37+
locTypeArg = this.getTypeArgument(count(this.getTypeArgument(_)) - 1).getLocation()
3838
|
3939
sl = locTypeArg.getEndLine() and
4040
sc = locTypeArg.getEndColumn() + 2
4141
)
4242
else (
43-
if exists(getQualifier())
43+
if exists(this.getQualifier())
4444
then
4545
// Note: this needs to be the original (full) location of the qualifier, not the modified one.
46-
exists(Location locQual | locQual = getQualifier().getLocation() |
46+
exists(Location locQual | locQual = this.getQualifier().getLocation() |
4747
sl = locQual.getEndLine() and
4848
sc = locQual.getEndColumn() + 2
4949
)
@@ -54,10 +54,10 @@ private class LocationOverridingMethodAccess extends MethodAccess {
5454
)
5555
) and
5656
(
57-
if getNumArgument() > 0
57+
if this.getNumArgument() > 0
5858
then
5959
// Note: this needs to be the original (full) location of the first argument, not the modified one.
60-
exists(Location locArg | locArg = getArgument(0).getLocation() |
60+
exists(Location locArg | locArg = this.getArgument(0).getLocation() |
6161
el = locArg.getStartLine() and
6262
ec = locArg.getStartColumn() - 2
6363
)
@@ -80,10 +80,10 @@ private class LocationOverridingTypeAccess extends TypeAccess {
8080
super.hasLocationInfo(path, slSuper, scSuper, elSuper, ecSuper)
8181
|
8282
(
83-
if exists(getQualifier())
83+
if exists(this.getQualifier())
8484
then
8585
// Note: this needs to be the original (full) location of the qualifier, not the modified one.
86-
exists(Location locQual | locQual = getQualifier().getLocation() |
86+
exists(Location locQual | locQual = this.getQualifier().getLocation() |
8787
sl = locQual.getEndLine() and
8888
sc = locQual.getEndColumn() + 2
8989
)
@@ -93,10 +93,10 @@ private class LocationOverridingTypeAccess extends TypeAccess {
9393
)
9494
) and
9595
(
96-
if exists(getTypeArgument(_))
96+
if exists(this.getTypeArgument(_))
9797
then
9898
// Note: this needs to be the original (full) location of the first type argument, not the modified one.
99-
exists(Location locArg | locArg = getTypeArgument(0).getLocation() |
99+
exists(Location locArg | locArg = this.getTypeArgument(0).getLocation() |
100100
el = locArg.getStartLine() and
101101
ec = locArg.getStartColumn() - 2
102102
)
@@ -117,7 +117,7 @@ private class LocationOverridingFieldAccess extends FieldAccess {
117117
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
118118
super.hasLocationInfo(path, _, _, el, ec) and
119119
sl = el and
120-
sc = ec - getField().getName().length() + 1
120+
sc = ec - this.getField().getName().length() + 1
121121
}
122122
}
123123

@@ -131,7 +131,7 @@ private class LocationOverridingImportType extends ImportType {
131131
el = elSuper and
132132
ec = ecSuper - 1 and
133133
sl = el and
134-
sc = ecSuper - getImportedType().getName().length()
134+
sc = ecSuper - this.getImportedType().getName().length()
135135
)
136136
}
137137
}
@@ -146,7 +146,7 @@ private class LocationOverridingImportStaticTypeMember extends ImportStaticTypeM
146146
el = elSuper and
147147
ec = ecSuper - 1 and
148148
sl = el and
149-
sc = ecSuper - getName().length()
149+
sc = ecSuper - this.getName().length()
150150
)
151151
}
152152
}

java/ql/lib/semmle/code/configfiles/ConfigFiles.qll

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ abstract class ConfigLocatable extends @configLocatable {
1111
Location getLocation() { configLocations(this, result) }
1212

1313
/** Gets the file associated with this element. */
14-
File getFile() { result = getLocation().getFile() }
14+
File getFile() { result = this.getLocation().getFile() }
1515

1616
/** Gets a textual representation of this element. */
1717
abstract string toString();
@@ -33,19 +33,21 @@ class ConfigPair extends @config, ConfigLocatable {
3333
* it exists and the empty string if it doesn't.
3434
*/
3535
string getEffectiveName() {
36-
if exists(getNameElement()) then result = getNameElement().getName() else result = ""
36+
if exists(this.getNameElement()) then result = this.getNameElement().getName() else result = ""
3737
}
3838

3939
/**
4040
* Gets the string value of the value of this `ConfigPair` if
4141
* it exists and the empty string if it doesn't.
4242
*/
4343
string getEffectiveValue() {
44-
if exists(getValueElement()) then result = getValueElement().getValue() else result = ""
44+
if exists(this.getValueElement())
45+
then result = this.getValueElement().getValue()
46+
else result = ""
4547
}
4648

4749
/** Gets a printable representation of this `ConfigPair`. */
48-
override string toString() { result = getEffectiveName() + "=" + getEffectiveValue() }
50+
override string toString() { result = this.getEffectiveName() + "=" + this.getEffectiveValue() }
4951
}
5052

5153
/** The name element of a `ConfigPair`. */
@@ -54,7 +56,7 @@ class ConfigName extends @configName, ConfigLocatable {
5456
string getName() { configNames(this, _, result) }
5557

5658
/** Gets a printable representation of this `ConfigName`. */
57-
override string toString() { result = getName() }
59+
override string toString() { result = this.getName() }
5860
}
5961

6062
/** The value element of a `ConfigPair`. */
@@ -63,10 +65,10 @@ class ConfigValue extends @configValue, ConfigLocatable {
6365
string getValue() { configValues(this, _, result) }
6466

6567
/** Gets a printable representation of this `ConfigValue`. */
66-
override string toString() { result = getValue() }
68+
override string toString() { result = this.getValue() }
6769
}
6870

6971
/** A Java property is a name-value pair in a `.properties` file. */
7072
class JavaProperty extends ConfigPair {
71-
JavaProperty() { getFile().getExtension() = "properties" }
73+
JavaProperty() { this.getFile().getExtension() = "properties" }
7274
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Compilation extends @compilation {
3131
}
3232

3333
/** Gets a file compiled during this invocation. */
34-
File getAFileCompiled() { result = getFileCompiled(_) }
34+
File getAFileCompiled() { result = this.getFileCompiled(_) }
3535

3636
/** Gets the `i`th file compiled during this invocation. */
3737
File getFileCompiled(int i) { compilation_compiling_files(this, i, result) }
@@ -76,7 +76,7 @@ class Compilation extends @compilation {
7676
/**
7777
* Gets an argument passed to the extractor on this invocation.
7878
*/
79-
string getAnArgument() { result = getArgument(_) }
79+
string getAnArgument() { result = this.getArgument(_) }
8080

8181
/**
8282
* Gets the `i`th argument passed to the extractor on this invocation.
@@ -86,7 +86,7 @@ class Compilation extends @compilation {
8686
/**
8787
* Gets an expanded argument passed to the extractor on this invocation.
8888
*/
89-
string getAnExpandedArgument() { result = getExpandedArgument(_) }
89+
string getAnExpandedArgument() { result = this.getExpandedArgument(_) }
9090

9191
/**
9292
* Gets the `i`th expanded argument passed to the extractor on this invocation.

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ class RequiresDirective extends Directive, @requires {
7373

7474
override string toString() {
7575
exists(string transitive, string static |
76-
(if isTransitive() then transitive = "transitive " else transitive = "") and
77-
(if isStatic() then static = "static " else static = "")
76+
(if this.isTransitive() then transitive = "transitive " else transitive = "") and
77+
(if this.isStatic() then static = "static " else static = "")
7878
|
79-
result = "requires " + transitive + static + getTargetModule() + ";"
79+
result = "requires " + transitive + static + this.getTargetModule() + ";"
8080
)
8181
}
8282
}
@@ -111,11 +111,11 @@ class ExportsDirective extends Directive, @exports {
111111

112112
override string toString() {
113113
exists(string toClause |
114-
if isQualified()
115-
then toClause = (" to " + concat(getATargetModule().getName(), ", "))
114+
if this.isQualified()
115+
then toClause = (" to " + concat(this.getATargetModule().getName(), ", "))
116116
else toClause = ""
117117
|
118-
result = "exports " + getExportedPackage() + toClause + ";"
118+
result = "exports " + this.getExportedPackage() + toClause + ";"
119119
)
120120
}
121121
}
@@ -150,11 +150,11 @@ class OpensDirective extends Directive, @opens {
150150

151151
override string toString() {
152152
exists(string toClause |
153-
if isQualified()
154-
then toClause = (" to " + concat(getATargetModule().getName(), ", "))
153+
if this.isQualified()
154+
then toClause = (" to " + concat(this.getATargetModule().getName(), ", "))
155155
else toClause = ""
156156
|
157-
result = "opens " + getOpenedPackage() + toClause + ";"
157+
result = "opens " + this.getOpenedPackage() + toClause + ";"
158158
)
159159
}
160160
}
@@ -170,7 +170,7 @@ class UsesDirective extends Directive, @uses {
170170
*/
171171
string getServiceInterfaceName() { uses(this, result) }
172172

173-
override string toString() { result = "uses " + getServiceInterfaceName() + ";" }
173+
override string toString() { result = "uses " + this.getServiceInterfaceName() + ";" }
174174
}
175175

176176
/**
@@ -191,7 +191,7 @@ class ProvidesDirective extends Directive, @provides {
191191

192192
override string toString() {
193193
result =
194-
"provides " + getServiceInterfaceName() + " with " +
195-
concat(getServiceImplementationName(), ", ") + ";"
194+
"provides " + this.getServiceInterfaceName() + " with " +
195+
concat(this.getServiceImplementationName(), ", ") + ";"
196196
}
197197
}

java/ql/lib/semmle/code/java/controlflow/unreachableblocks/ExcludeDebuggingProfilingLogging.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ class ExcludeDebuggingProfilingLogging extends ExcludedConstantField {
2323
"log"
2424
]
2525
|
26-
getName().regexpMatch(".*(?i)" + validFieldName + ".*")
26+
this.getName().regexpMatch(".*(?i)" + validFieldName + ".*")
2727
) and
2828
// Boolean type
2929
(
30-
getType().hasName("boolean") or
31-
getType().(BoxedType).hasQualifiedName("java.lang", "Boolean")
30+
this.getType().hasName("boolean") or
31+
this.getType().(BoxedType).hasQualifiedName("java.lang", "Boolean")
3232
)
3333
}
3434
}

java/ql/lib/semmle/code/java/dataflow/InstanceAccess.qll

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -132,28 +132,28 @@ class InstanceAccessExt extends TInstanceAccessExt {
132132
result = enc.getQualifier().toString() + "(" + enc.getType() + ")enclosing"
133133
)
134134
or
135-
isOwnInstanceAccess() and result = "this"
135+
this.isOwnInstanceAccess() and result = "this"
136136
}
137137

138138
private string ppKind() {
139-
isExplicit(_) and result = " <" + getAssociatedExprOrStmt().toString() + ">"
139+
this.isExplicit(_) and result = " <" + this.getAssociatedExprOrStmt().toString() + ">"
140140
or
141-
isImplicitFieldQualifier(_) and result = " <.field>"
141+
this.isImplicitFieldQualifier(_) and result = " <.field>"
142142
or
143-
isImplicitMethodQualifier(_) and result = " <.method>"
143+
this.isImplicitMethodQualifier(_) and result = " <.method>"
144144
or
145-
isImplicitThisConstructorArgument(_) and result = " <constr(this)>"
145+
this.isImplicitThisConstructorArgument(_) and result = " <constr(this)>"
146146
or
147-
isImplicitEnclosingInstanceCapture(_) and result = " <.new>"
147+
this.isImplicitEnclosingInstanceCapture(_) and result = " <.new>"
148148
or
149-
isImplicitEnclosingInstanceQualifier(_) and result = "."
149+
this.isImplicitEnclosingInstanceQualifier(_) and result = "."
150150
}
151151

152152
/** Gets a textual representation of this element. */
153-
string toString() { result = ppBase() + ppKind() }
153+
string toString() { result = this.ppBase() + this.ppKind() }
154154

155155
/** Gets the source location for this element. */
156-
Location getLocation() { result = getAssociatedExprOrStmt().getLocation() }
156+
Location getLocation() { result = this.getAssociatedExprOrStmt().getLocation() }
157157

158158
private ExprParent getAssociatedExprOrStmt() {
159159
this = TExplicitInstanceAccess(result) or
@@ -166,8 +166,8 @@ class InstanceAccessExt extends TInstanceAccessExt {
166166

167167
/** Gets the callable in which this instance access occurs. */
168168
Callable getEnclosingCallable() {
169-
result = getAssociatedExprOrStmt().(Expr).getEnclosingCallable() or
170-
result = getAssociatedExprOrStmt().(Stmt).getEnclosingCallable()
169+
result = this.getAssociatedExprOrStmt().(Expr).getEnclosingCallable() or
170+
result = this.getAssociatedExprOrStmt().(Stmt).getEnclosingCallable()
171171
}
172172

173173
/** Holds if this is the explicit instance access `ia`. */
@@ -206,7 +206,7 @@ class InstanceAccessExt extends TInstanceAccessExt {
206206
}
207207

208208
/** Holds if this is an access to an object's own instance. */
209-
predicate isOwnInstanceAccess() { not isEnclosingInstanceAccess(_) }
209+
predicate isOwnInstanceAccess() { not this.isEnclosingInstanceAccess(_) }
210210

211211
/** Holds if this is an access to an enclosing instance. */
212212
predicate isEnclosingInstanceAccess(RefType t) {
@@ -221,14 +221,14 @@ class InstanceAccessExt extends TInstanceAccessExt {
221221

222222
/** Gets the type of this instance access. */
223223
RefType getType() {
224-
isEnclosingInstanceAccess(result)
224+
this.isEnclosingInstanceAccess(result)
225225
or
226-
isOwnInstanceAccess() and result = getEnclosingCallable().getDeclaringType()
226+
this.isOwnInstanceAccess() and result = this.getEnclosingCallable().getDeclaringType()
227227
}
228228

229229
/** Gets the control flow node associated with this instance access. */
230230
ControlFlowNode getCfgNode() {
231-
exists(ExprParent e | e = getAssociatedExprOrStmt() |
231+
exists(ExprParent e | e = this.getAssociatedExprOrStmt() |
232232
e instanceof Call and result = e
233233
or
234234
e instanceof InstanceAccess and result = e
@@ -244,14 +244,14 @@ class InstanceAccessExt extends TInstanceAccessExt {
244244
* An access to an object's own instance.
245245
*/
246246
class OwnInstanceAccess extends InstanceAccessExt {
247-
OwnInstanceAccess() { isOwnInstanceAccess() }
247+
OwnInstanceAccess() { this.isOwnInstanceAccess() }
248248
}
249249

250250
/**
251251
* An access to an enclosing instance.
252252
*/
253253
class EnclosingInstanceAccess extends InstanceAccessExt {
254-
EnclosingInstanceAccess() { isEnclosingInstanceAccess(_) }
254+
EnclosingInstanceAccess() { this.isEnclosingInstanceAccess(_) }
255255

256256
/** Gets the implicit qualifier of this in the desugared representation. */
257257
InstanceAccessExt getQualifier() {

java/ql/lib/semmle/code/java/dataflow/RangeAnalysis.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class CondReason extends Reason, TCondReason {
292292
/** Gets the condition that is the reason for the bound. */
293293
Guard getCond() { this = TCondReason(result) }
294294

295-
override string toString() { result = getCond().toString() }
295+
override string toString() { result = this.getCond().toString() }
296296
}
297297

298298
/**
@@ -362,7 +362,7 @@ private predicate safeCast(Type fromtyp, Type totyp) {
362362
*/
363363
private class RangeAnalysisSafeCastingExpr extends CastingExpr {
364364
RangeAnalysisSafeCastingExpr() {
365-
safeCast(getExpr().getType(), getType()) or
365+
safeCast(this.getExpr().getType(), this.getType()) or
366366
this instanceof ImplicitCastExpr or
367367
this instanceof ImplicitNotNullExpr or
368368
this instanceof ImplicitCoercionToUnitExpr
@@ -388,14 +388,14 @@ private predicate typeBound(Type typ, int lowerbound, int upperbound) {
388388
private class NarrowingCastingExpr extends CastingExpr {
389389
NarrowingCastingExpr() {
390390
not this instanceof RangeAnalysisSafeCastingExpr and
391-
typeBound(getType(), _, _)
391+
typeBound(this.getType(), _, _)
392392
}
393393

394394
/** Gets the lower bound of the resulting type. */
395-
int getLowerBound() { typeBound(getType(), result, _) }
395+
int getLowerBound() { typeBound(this.getType(), result, _) }
396396

397397
/** Gets the upper bound of the resulting type. */
398-
int getUpperBound() { typeBound(getType(), _, result) }
398+
int getUpperBound() { typeBound(this.getType(), _, result) }
399399
}
400400

401401
/** Holds if `e >= 1` as determined by sign analysis. */

0 commit comments

Comments
 (0)