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

Skip to content

Commit 90ca47a

Browse files
tamasvajkigfoo
authored andcommitted
Extract local delegated property reference
1 parent 47d8eb4 commit 90ca47a

3 files changed

Lines changed: 181 additions & 6 deletions

File tree

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.ir.declarations.*
1818
import org.jetbrains.kotlin.ir.expressions.*
1919
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
2020
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
21+
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
2122
import org.jetbrains.kotlin.ir.symbols.IrSymbol
2223
import org.jetbrains.kotlin.ir.types.*
2324
import org.jetbrains.kotlin.ir.util.*
@@ -2550,7 +2551,10 @@ open class KotlinFileExtractor(
25502551
extractTypeAccessRecursive(e.classType, locId, id, 0, callable, exprParent.enclosingStmt)
25512552
}
25522553
is IrPropertyReference -> {
2553-
extractPropertyReference(e, parent, callable)
2554+
extractPropertyReference("property reference", e, e.getter, e.setter, parent, callable)
2555+
}
2556+
is IrLocalDelegatedPropertyReference -> {
2557+
extractPropertyReference("local delegated property reference", e, e.getter, e.setter, parent, callable)
25542558
}
25552559
else -> {
25562560
logger.errorElement("Unrecognised IrExpression: " + e.javaClass, e)
@@ -2769,11 +2773,14 @@ open class KotlinFileExtractor(
27692773
}
27702774

27712775
private fun extractPropertyReference(
2772-
propertyReferenceExpr: IrPropertyReference,
2776+
exprKind: String,
2777+
propertyReferenceExpr: IrCallableReference<out IrSymbol>,
2778+
getter: IrSimpleFunctionSymbol?,
2779+
setter: IrSimpleFunctionSymbol?,
27732780
parent: StmtExprParent,
27742781
callable: Label<out DbCallable>
27752782
) {
2776-
with("property reference", propertyReferenceExpr) {
2783+
with(exprKind, propertyReferenceExpr) {
27772784
/*
27782785
* Extract generated class:
27792786
* ```
@@ -2796,9 +2803,6 @@ open class KotlinFileExtractor(
27962803
* - no receiver vs dispatchReceiver vs extensionReceiver
27972804
**/
27982805

2799-
val getter = propertyReferenceExpr.getter
2800-
val setter = propertyReferenceExpr.setter
2801-
28022806
if (getter == null && setter == null) {
28032807
logger.errorElement("Expected to find getter or setter for property reference.", propertyReferenceExpr)
28042808
return

java/ql/test/kotlin/library-tests/exprs/PrintAst.expected

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ delegatedProperties.kt:
4040
# 6| -1: [TypeAccess] LazyKt
4141
# 6| 0: [VarAccess] prop1$delegate
4242
# 0| 1: [NullLiteral] null
43+
# 6| 2: [PropertyRefExpr] ...::...
44+
# 6| -4: [AnonymousClass] new KProperty0<Integer>(...) { ... }
45+
# 6| 1: [Constructor]
46+
# 6| 5: [BlockStmt] { ... }
47+
# 6| 0: [SuperConstructorInvocationStmt] super(...)
48+
# 6| 1: [Method] get
49+
# 6| 5: [BlockStmt] { ... }
50+
# 6| 0: [ReturnStmt] return ...
51+
# 6| 0: [MethodAccess] <get-prop1>(...)
52+
# 6| -3: [TypeAccess] KProperty0<Integer>
53+
# 6| 0: [TypeAccess] Integer
4354
# 10| 1: [ExprStmt] <Expr>;
4455
# 10| 0: [MethodAccess] println(...)
4556
# 10| -1: [TypeAccess] ConsoleKt
@@ -84,6 +95,24 @@ delegatedProperties.kt:
8495
# 19| 0: [MethodAccess] getValue(...)
8596
# 19| -1: [VarAccess] varResource1$delegate
8697
# 0| 0: [NullLiteral] null
98+
# 19| 1: [PropertyRefExpr] ...::...
99+
# 19| -4: [AnonymousClass] new KMutableProperty0<Integer>(...) { ... }
100+
# 19| 1: [Constructor]
101+
# 19| 5: [BlockStmt] { ... }
102+
# 19| 0: [SuperConstructorInvocationStmt] super(...)
103+
# 19| 1: [Method] get
104+
# 19| 5: [BlockStmt] { ... }
105+
# 19| 0: [ReturnStmt] return ...
106+
# 19| 0: [MethodAccess] <get-varResource1>(...)
107+
# 19| 1: [Method] set
108+
#-----| 4: (Parameters)
109+
# 19| 0: [Parameter] a0
110+
# 19| 5: [BlockStmt] { ... }
111+
# 19| 0: [ReturnStmt] return ...
112+
# 19| 0: [MethodAccess] <set-varResource1>(...)
113+
# 19| 0: [VarAccess] a0
114+
# 19| -3: [TypeAccess] KMutableProperty0<Integer>
115+
# 19| 0: [TypeAccess] Integer
87116
# 19| 2: [LocalTypeDeclStmt] class ...
88117
# 19| 0: [LocalClass]
89118
# 19| 1: [Constructor]
@@ -97,6 +126,24 @@ delegatedProperties.kt:
97126
# 19| 0: [MethodAccess] setValue(...)
98127
# 19| -1: [VarAccess] varResource1$delegate
99128
# 0| 0: [NullLiteral] null
129+
# 19| 1: [PropertyRefExpr] ...::...
130+
# 19| -4: [AnonymousClass] new KMutableProperty0<Integer>(...) { ... }
131+
# 19| 1: [Constructor]
132+
# 19| 5: [BlockStmt] { ... }
133+
# 19| 0: [SuperConstructorInvocationStmt] super(...)
134+
# 19| 1: [Method] get
135+
# 19| 5: [BlockStmt] { ... }
136+
# 19| 0: [ReturnStmt] return ...
137+
# 19| 0: [MethodAccess] <get-varResource1>(...)
138+
# 19| 1: [Method] set
139+
#-----| 4: (Parameters)
140+
# 19| 0: [Parameter] a0
141+
# 19| 5: [BlockStmt] { ... }
142+
# 19| 0: [ReturnStmt] return ...
143+
# 19| 0: [MethodAccess] <set-varResource1>(...)
144+
# 19| 0: [VarAccess] a0
145+
# 19| -3: [TypeAccess] KMutableProperty0<Integer>
146+
# 19| 0: [TypeAccess] Integer
100147
# 19| 2: [VarAccess] value
101148
# 20| 1: [ExprStmt] <Expr>;
102149
# 20| 0: [MethodAccess] println(...)
@@ -127,6 +174,17 @@ delegatedProperties.kt:
127174
# 23| -1: [TypeAccess] MapAccessorsKt
128175
# 23| 0: [VarAccess] name$delegate
129176
# 0| 1: [NullLiteral] null
177+
# 23| 2: [PropertyRefExpr] ...::...
178+
# 23| -4: [AnonymousClass] new KProperty0<String>(...) { ... }
179+
# 23| 1: [Constructor]
180+
# 23| 5: [BlockStmt] { ... }
181+
# 23| 0: [SuperConstructorInvocationStmt] super(...)
182+
# 23| 1: [Method] get
183+
# 23| 5: [BlockStmt] { ... }
184+
# 23| 0: [ReturnStmt] return ...
185+
# 23| 0: [MethodAccess] <get-name>(...)
186+
# 23| -3: [TypeAccess] KProperty0<String>
187+
# 23| 0: [TypeAccess] String
130188
# 25| 4: [LocalTypeDeclStmt] class ...
131189
# 25| 0: [LocalClass]
132190
# 25| 1: [Constructor]
@@ -201,6 +259,17 @@ delegatedProperties.kt:
201259
# 33| 0: [MethodAccess] getValue(...)
202260
# 33| -1: [VarAccess] readOnly$delegate
203261
# 0| 0: [NullLiteral] null
262+
# 33| 1: [PropertyRefExpr] ...::...
263+
# 33| -4: [AnonymousClass] new KProperty0<Integer>(...) { ... }
264+
# 33| 1: [Constructor]
265+
# 33| 5: [BlockStmt] { ... }
266+
# 33| 0: [SuperConstructorInvocationStmt] super(...)
267+
# 33| 1: [Method] get
268+
# 33| 5: [BlockStmt] { ... }
269+
# 33| 0: [ReturnStmt] return ...
270+
# 33| 0: [MethodAccess] <get-readOnly>(...)
271+
# 33| -3: [TypeAccess] KProperty0<Integer>
272+
# 33| 0: [TypeAccess] Integer
204273
# 34| 6: [BlockStmt] { ... }
205274
# 34| 0: [LocalVariableDeclStmt] var ...;
206275
# 34| 1: [LocalVariableDeclExpr] readWrite$delegate
@@ -218,6 +287,24 @@ delegatedProperties.kt:
218287
# 34| 0: [MethodAccess] getValue(...)
219288
# 34| -1: [VarAccess] readWrite$delegate
220289
# 0| 0: [NullLiteral] null
290+
# 34| 1: [PropertyRefExpr] ...::...
291+
# 34| -4: [AnonymousClass] new KMutableProperty0<Integer>(...) { ... }
292+
# 34| 1: [Constructor]
293+
# 34| 5: [BlockStmt] { ... }
294+
# 34| 0: [SuperConstructorInvocationStmt] super(...)
295+
# 34| 1: [Method] get
296+
# 34| 5: [BlockStmt] { ... }
297+
# 34| 0: [ReturnStmt] return ...
298+
# 34| 0: [MethodAccess] <get-readWrite>(...)
299+
# 34| 1: [Method] set
300+
#-----| 4: (Parameters)
301+
# 34| 0: [Parameter] a0
302+
# 34| 5: [BlockStmt] { ... }
303+
# 34| 0: [ReturnStmt] return ...
304+
# 34| 0: [MethodAccess] <set-readWrite>(...)
305+
# 34| 0: [VarAccess] a0
306+
# 34| -3: [TypeAccess] KMutableProperty0<Integer>
307+
# 34| 0: [TypeAccess] Integer
221308
# 34| 2: [LocalTypeDeclStmt] class ...
222309
# 34| 0: [LocalClass]
223310
# 34| 1: [Constructor]
@@ -231,6 +318,24 @@ delegatedProperties.kt:
231318
# 34| 0: [MethodAccess] setValue(...)
232319
# 34| -1: [VarAccess] readWrite$delegate
233320
# 0| 0: [NullLiteral] null
321+
# 34| 1: [PropertyRefExpr] ...::...
322+
# 34| -4: [AnonymousClass] new KMutableProperty0<Integer>(...) { ... }
323+
# 34| 1: [Constructor]
324+
# 34| 5: [BlockStmt] { ... }
325+
# 34| 0: [SuperConstructorInvocationStmt] super(...)
326+
# 34| 1: [Method] get
327+
# 34| 5: [BlockStmt] { ... }
328+
# 34| 0: [ReturnStmt] return ...
329+
# 34| 0: [MethodAccess] <get-readWrite>(...)
330+
# 34| 1: [Method] set
331+
#-----| 4: (Parameters)
332+
# 34| 0: [Parameter] a0
333+
# 34| 5: [BlockStmt] { ... }
334+
# 34| 0: [ReturnStmt] return ...
335+
# 34| 0: [MethodAccess] <set-readWrite>(...)
336+
# 34| 0: [VarAccess] a0
337+
# 34| -3: [TypeAccess] KMutableProperty0<Integer>
338+
# 34| 0: [TypeAccess] Integer
234339
# 34| 2: [VarAccess] value
235340
# 36| 7: [ExprStmt] <Expr>;
236341
# 36| 0: [MethodAccess] println(...)
@@ -248,6 +353,17 @@ delegatedProperties.kt:
248353
# 39| -1: [ClassInstanceExpr] new DelegateProvider(...)
249354
# 39| -3: [TypeAccess] DelegateProvider
250355
# 1| 0: [NullLiteral] null
356+
# 39| 1: [PropertyRefExpr] ...::...
357+
# 39| -4: [AnonymousClass] new KProperty0<Integer>(...) { ... }
358+
# 39| 1: [Constructor]
359+
# 39| 5: [BlockStmt] { ... }
360+
# 39| 0: [SuperConstructorInvocationStmt] super(...)
361+
# 39| 1: [Method] get
362+
# 39| 5: [BlockStmt] { ... }
363+
# 39| 0: [ReturnStmt] return ...
364+
# 39| 0: [MethodAccess] <get-varResource2>(...)
365+
# 39| -3: [TypeAccess] KProperty0<Integer>
366+
# 39| 0: [TypeAccess] Integer
251367
# 39| 1: [LocalTypeDeclStmt] class ...
252368
# 39| 0: [LocalClass]
253369
# 39| 1: [Constructor]
@@ -259,6 +375,17 @@ delegatedProperties.kt:
259375
# 39| 0: [MethodAccess] getValue(...)
260376
# 39| -1: [VarAccess] varResource2$delegate
261377
# 0| 0: [NullLiteral] null
378+
# 39| 1: [PropertyRefExpr] ...::...
379+
# 39| -4: [AnonymousClass] new KProperty0<Integer>(...) { ... }
380+
# 39| 1: [Constructor]
381+
# 39| 5: [BlockStmt] { ... }
382+
# 39| 0: [SuperConstructorInvocationStmt] super(...)
383+
# 39| 1: [Method] get
384+
# 39| 5: [BlockStmt] { ... }
385+
# 39| 0: [ReturnStmt] return ...
386+
# 39| 0: [MethodAccess] <get-varResource2>(...)
387+
# 39| -3: [TypeAccess] KProperty0<Integer>
388+
# 39| 0: [TypeAccess] Integer
262389
# 42| 3: [Method] getVarResource0
263390
# 42| 5: [BlockStmt] { ... }
264391
# 42| 0: [ReturnStmt] return ...

0 commit comments

Comments
 (0)