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

Skip to content

Commit d6ec230

Browse files
tamasvajkigfoo
authored andcommitted
Recognize qualified this access of outer class instance
1 parent 3bfc93d commit d6ec230

4 files changed

Lines changed: 42 additions & 5 deletions

File tree

java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,19 +413,31 @@ class KotlinFileExtractor(val logger: FileLogger, val tw: FileTrapWriter, val fi
413413
@Suppress("UNCHECKED_CAST")
414414
val parentId: Label<out DbMethod> = useDeclarationParent(vp.parent) as Label<out DbMethod>
415415
var idx = vp.index
416-
if (isQualifiedThis(vp)) {
416+
if (isQualifiedThisFunction(vp)) {
417417
idx = -2
418418
}
419419
val label = "@\"params;{$parentId};$idx\""
420420
return label
421421
}
422422

423-
private fun isQualifiedThis(vp: IrValueParameter) : Boolean {
423+
private fun isQualifiedThis(vp: IrValueParameter): Boolean {
424+
return isQualifiedThisFunction(vp) ||
425+
isQualifiedThisClass(vp)
426+
}
427+
428+
private fun isQualifiedThisFunction(vp: IrValueParameter): Boolean {
429+
val parent = vp.parent
430+
return vp.index == -1 &&
431+
parent is IrFunction &&
432+
parent.dispatchReceiverParameter == vp &&
433+
parent.extensionReceiverParameter != null
434+
}
435+
436+
private fun isQualifiedThisClass(vp: IrValueParameter): Boolean {
424437
val parent = vp.parent
425438
return vp.index == -1 &&
426-
parent is IrFunction &&
427-
parent.dispatchReceiverParameter == vp &&
428-
parent.extensionReceiverParameter != null
439+
parent is IrClass &&
440+
parent.thisReceiver == vp
429441
}
430442

431443
fun useValueParameter(vp: IrValueParameter): Label<out DbParam> {

java/ql/test/kotlin/library-tests/variables/variableAccesses.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ instAcc
88
| variables.kt:28:9:28:12 | this |
99
| variables.kt:31:9:31:15 | this |
1010
| variables.kt:32:9:32:15 | this |
11+
| variables.kt:41:13:41:16 | this |
12+
| variables.kt:42:13:42:19 | this |
1113
instAccQualifier

java/ql/test/kotlin/library-tests/variables/variables.expected

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,15 @@
2424
| variables.kt:20:5:22:5 | <this> | variables.kt:16:1:34:1 | C2 | file://:0:0:0:0 | <none> |
2525
| variables.kt:23:5:33:5 | <this> | variables.kt:16:1:34:1 | C2 | file://:0:0:0:0 | <none> |
2626
| variables.kt:23:9:23:10 | <this> | variables.kt:12:1:15:1 | C1 | file://:0:0:0:0 | <none> |
27+
| variables.kt:36:1:45:1 | <this> | file://:0:0:0:0 | Any | file://:0:0:0:0 | <none> |
28+
| variables.kt:36:1:45:1 | <this> | file://:0:0:0:0 | Any | file://:0:0:0:0 | <none> |
29+
| variables.kt:36:1:45:1 | <this> | file://:0:0:0:0 | Any | file://:0:0:0:0 | <none> |
30+
| variables.kt:36:1:45:1 | other | file://:0:0:0:0 | Any | file://:0:0:0:0 | <none> |
31+
| variables.kt:37:5:37:15 | <this> | variables.kt:36:1:45:1 | C3 | file://:0:0:0:0 | <none> |
32+
| variables.kt:38:5:44:5 | <this> | file://:0:0:0:0 | Any | file://:0:0:0:0 | <none> |
33+
| variables.kt:38:5:44:5 | <this> | file://:0:0:0:0 | Any | file://:0:0:0:0 | <none> |
34+
| variables.kt:38:5:44:5 | <this> | file://:0:0:0:0 | Any | file://:0:0:0:0 | <none> |
35+
| variables.kt:38:5:44:5 | <this> | variables.kt:36:1:45:1 | C3 | file://:0:0:0:0 | <none> |
36+
| variables.kt:38:11:44:5 | other | file://:0:0:0:0 | Any | file://:0:0:0:0 | <none> |
37+
| variables.kt:39:9:39:19 | <this> | variables.kt:38:5:44:5 | C4 | file://:0:0:0:0 | <none> |
38+
| variables.kt:40:9:43:9 | <this> | variables.kt:38:5:44:5 | C4 | file://:0:0:0:0 | <none> |

java/ql/test/kotlin/library-tests/variables/variables.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,15 @@ class C2 (val o:C1) {
3131
this@C2.f1() // dispatchReceiverParameter
3232
this@C2.f3() // dispatchReceiverParameter
3333
}
34+
}
35+
36+
class C3 {
37+
fun f0() {}
38+
inner class C4 {
39+
fun f0() {}
40+
fun f1() {
41+
this.f0()
42+
this@C3.f0()
43+
}
44+
}
3445
}

0 commit comments

Comments
 (0)