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

Skip to content

Commit 4b55dce

Browse files
tamasvajkigfoo
authored andcommitted
Add generic function and property reference test cases
1 parent 18812c8 commit 4b55dce

3 files changed

Lines changed: 283 additions & 0 deletions

File tree

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

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ reflection.kt:
5858
# 49| -1: [ThisAccess] this
5959
# 49| -3: [TypeAccess] KProperty0<Character>
6060
# 49| 0: [StringLiteral] abcd
61+
# 52| 3: [ExtensionMethod] ext1
62+
#-----| 2: (Generic Parameters)
63+
# 52| 0: [TypeVariable] T2
64+
#-----| 4: (Parameters)
65+
# 52| 0: [Parameter] <this>
66+
# 52| 5: [BlockStmt] { ... }
67+
# 52| 0: [ReturnStmt] return ...
68+
# 52| 0: [MethodAccess] toString(...)
69+
# 52| -1: [ThisAccess] this
70+
# 54| 4: [ExtensionMethod] ext2
71+
#-----| 4: (Parameters)
72+
# 54| 0: [Parameter] <this>
73+
# 54| 5: [BlockStmt] { ... }
74+
# 54| 0: [ReturnStmt] return ...
75+
# 54| 0: [MethodAccess] toString(...)
76+
# 54| -1: [ThisAccess] this
6177
# 3| 2: [Class] Reflection
6278
# 3| 1: [Constructor] Reflection
6379
# 3| 5: [BlockStmt] { ... }
@@ -369,3 +385,233 @@ reflection.kt:
369385
# 39| 5: [BlockStmt] { ... }
370386
# 39| 0: [ReturnStmt] return ...
371387
# 39| 0: [VarAccess] INSTANCE
388+
# 56| 3: [Class] Class1
389+
# 56| 1: [Constructor] Class1
390+
# 56| 5: [BlockStmt] { ... }
391+
# 56| 0: [SuperConstructorInvocationStmt] super(...)
392+
# 56| 1: [ExprStmt] <Expr>;
393+
# 56| 0: [MethodAccess] <obinit>(...)
394+
# 57| 3: [Method] fn
395+
# 57| 5: [BlockStmt] { ... }
396+
# 58| 0: [ExprStmt] <Expr>;
397+
# 58| 0: [MethodAccess] println(...)
398+
# 58| -1: [TypeAccess] ConsoleKt
399+
# 58| 0: [MemberRefExpr] ...::...
400+
# 58| -4: [AnonymousClass] new Function2<Generic<T1>,T1,String>(...) { ... }
401+
# 58| 1: [Constructor]
402+
# 58| 5: [BlockStmt] { ... }
403+
# 58| 0: [SuperConstructorInvocationStmt] super(...)
404+
# 58| 1: [Method] invoke
405+
#-----| 4: (Parameters)
406+
# 58| 0: [Parameter] a0
407+
# 58| 1: [Parameter] a1
408+
# 58| 5: [BlockStmt] { ... }
409+
# 58| 0: [ReturnStmt] return ...
410+
# 58| 0: [MethodAccess] m1(...)
411+
# 58| -1: [VarAccess] a0
412+
# 58| 0: [VarAccess] a1
413+
# 58| -3: [TypeAccess] Function2<Generic<T1>,T1,String>
414+
# 59| 1: [ExprStmt] <Expr>;
415+
# 59| 0: [MethodAccess] println(...)
416+
# 59| -1: [TypeAccess] ConsoleKt
417+
# 59| 0: [MemberRefExpr] ...::...
418+
# 59| -4: [AnonymousClass] new Function1<T1,String>(...) { ... }
419+
# 59| 1: [Constructor]
420+
#-----| 4: (Parameters)
421+
# 59| 0: [Parameter] <dispatchReceiver>
422+
# 59| 5: [BlockStmt] { ... }
423+
# 59| 0: [SuperConstructorInvocationStmt] super(...)
424+
# 59| 1: [ExprStmt] <Expr>;
425+
# 59| 0: [AssignExpr] ...=...
426+
# 59| 0: [VarAccess] this.<dispatchReceiver>
427+
# 59| -1: [ThisAccess] this
428+
# 59| 1: [VarAccess] <dispatchReceiver>
429+
# 59| 1: [Method] invoke
430+
#-----| 4: (Parameters)
431+
# 59| 0: [Parameter] a0
432+
# 59| 5: [BlockStmt] { ... }
433+
# 59| 0: [ReturnStmt] return ...
434+
# 59| 0: [MethodAccess] m1(...)
435+
# 59| -1: [VarAccess] this.<dispatchReceiver>
436+
# 59| -1: [ThisAccess] this
437+
# 59| 0: [VarAccess] a0
438+
# 59| 1: [FieldDeclaration] Generic<Integer> <dispatchReceiver>;
439+
# 59| -1: [TypeAccess] Generic<Integer>
440+
# 59| -3: [TypeAccess] Function1<T1,String>
441+
# 59| 0: [ClassInstanceExpr] new Generic<Integer>(...)
442+
# 59| -3: [TypeAccess] Generic<Integer>
443+
# 59| 0: [TypeAccess] Integer
444+
# 60| 2: [ExprStmt] <Expr>;
445+
# 60| 0: [MethodAccess] println(...)
446+
# 60| -1: [TypeAccess] ConsoleKt
447+
# 60| 0: [MemberRefExpr] ...::...
448+
# 60| -4: [AnonymousClass] new Function1<Generic<T2>,String>(...) { ... }
449+
# 60| 1: [Constructor]
450+
# 60| 5: [BlockStmt] { ... }
451+
# 60| 0: [SuperConstructorInvocationStmt] super(...)
452+
# 60| 1: [Method] invoke
453+
#-----| 4: (Parameters)
454+
# 60| 0: [Parameter] a0
455+
# 60| 5: [BlockStmt] { ... }
456+
# 60| 0: [ReturnStmt] return ...
457+
# 60| 0: [MethodAccess] ext1(...)
458+
# 60| -2: [TypeAccess] Integer
459+
# 60| 0: [VarAccess] a0
460+
# 60| -3: [TypeAccess] Function1<Generic<T2>,String>
461+
# 61| 3: [ExprStmt] <Expr>;
462+
# 61| 0: [MethodAccess] println(...)
463+
# 61| -1: [TypeAccess] ConsoleKt
464+
# 61| 0: [MemberRefExpr] ...::...
465+
# 61| -4: [AnonymousClass] new Function0<String>(...) { ... }
466+
# 61| 1: [Constructor]
467+
#-----| 4: (Parameters)
468+
# 61| 0: [Parameter] <extensionReceiver>
469+
# 61| 5: [BlockStmt] { ... }
470+
# 61| 0: [SuperConstructorInvocationStmt] super(...)
471+
# 61| 1: [ExprStmt] <Expr>;
472+
# 61| 0: [AssignExpr] ...=...
473+
# 61| 0: [VarAccess] this.<extensionReceiver>
474+
# 61| -1: [ThisAccess] this
475+
# 61| 1: [VarAccess] <extensionReceiver>
476+
# 61| 1: [Method] invoke
477+
# 61| 5: [BlockStmt] { ... }
478+
# 61| 0: [ReturnStmt] return ...
479+
# 61| 0: [MethodAccess] ext1(...)
480+
# 61| -2: [TypeAccess] Integer
481+
# 61| 0: [VarAccess] this.<extensionReceiver>
482+
# 61| -1: [ThisAccess] this
483+
# 61| 1: [FieldDeclaration] Generic<Integer> <extensionReceiver>;
484+
# 61| -1: [TypeAccess] Generic<Integer>
485+
# 61| -3: [TypeAccess] Function0<String>
486+
# 61| 0: [ClassInstanceExpr] new Generic<Integer>(...)
487+
# 61| -3: [TypeAccess] Generic<Integer>
488+
# 61| 0: [TypeAccess] Integer
489+
# 62| 4: [ExprStmt] <Expr>;
490+
# 62| 0: [MethodAccess] println(...)
491+
# 62| -1: [TypeAccess] ConsoleKt
492+
# 62| 0: [MemberRefExpr] ...::...
493+
# 62| -4: [AnonymousClass] new Function1<Generic<Integer>,String>(...) { ... }
494+
# 62| 1: [Constructor]
495+
# 62| 5: [BlockStmt] { ... }
496+
# 62| 0: [SuperConstructorInvocationStmt] super(...)
497+
# 62| 1: [Method] invoke
498+
#-----| 4: (Parameters)
499+
# 62| 0: [Parameter] a0
500+
# 62| 5: [BlockStmt] { ... }
501+
# 62| 0: [ReturnStmt] return ...
502+
# 62| 0: [MethodAccess] ext2(...)
503+
# 62| 0: [VarAccess] a0
504+
# 62| -3: [TypeAccess] Function1<Generic<Integer>,String>
505+
# 63| 5: [ExprStmt] <Expr>;
506+
# 63| 0: [MethodAccess] println(...)
507+
# 63| -1: [TypeAccess] ConsoleKt
508+
# 63| 0: [MemberRefExpr] ...::...
509+
# 63| -4: [AnonymousClass] new Function0<String>(...) { ... }
510+
# 63| 1: [Constructor]
511+
#-----| 4: (Parameters)
512+
# 63| 0: [Parameter] <extensionReceiver>
513+
# 63| 5: [BlockStmt] { ... }
514+
# 63| 0: [SuperConstructorInvocationStmt] super(...)
515+
# 63| 1: [ExprStmt] <Expr>;
516+
# 63| 0: [AssignExpr] ...=...
517+
# 63| 0: [VarAccess] this.<extensionReceiver>
518+
# 63| -1: [ThisAccess] this
519+
# 63| 1: [VarAccess] <extensionReceiver>
520+
# 63| 1: [Method] invoke
521+
# 63| 5: [BlockStmt] { ... }
522+
# 63| 0: [ReturnStmt] return ...
523+
# 63| 0: [MethodAccess] ext2(...)
524+
# 63| 0: [VarAccess] this.<extensionReceiver>
525+
# 63| -1: [ThisAccess] this
526+
# 63| 1: [FieldDeclaration] Generic<Integer> <extensionReceiver>;
527+
# 63| -1: [TypeAccess] Generic<Integer>
528+
# 63| -3: [TypeAccess] Function0<String>
529+
# 63| 0: [ClassInstanceExpr] new Generic<Integer>(...)
530+
# 63| -3: [TypeAccess] Generic<Integer>
531+
# 63| 0: [TypeAccess] Integer
532+
# 65| 6: [ExprStmt] <Expr>;
533+
# 65| 0: [MethodAccess] println(...)
534+
# 65| -1: [TypeAccess] ConsoleKt
535+
# 65| 0: [PropertyRefExpr] ...::...
536+
# 65| -4: [AnonymousClass] new KMutableProperty1<Generic<Integer>,Integer>(...) { ... }
537+
# 65| 1: [Constructor]
538+
# 65| 5: [BlockStmt] { ... }
539+
# 65| 0: [SuperConstructorInvocationStmt] super(...)
540+
# 65| 1: [Method] get
541+
#-----| 4: (Parameters)
542+
# 65| 0: [Parameter] a0
543+
# 65| 5: [BlockStmt] { ... }
544+
# 65| 0: [ReturnStmt] return ...
545+
# 65| 0: [MethodAccess] getP2(...)
546+
# 65| -1: [VarAccess] a0
547+
# 65| 1: [Method] set
548+
#-----| 4: (Parameters)
549+
# 65| 0: [Parameter] a0
550+
# 65| 1: [Parameter] a1
551+
# 65| 5: [BlockStmt] { ... }
552+
# 65| 0: [ReturnStmt] return ...
553+
# 65| 0: [MethodAccess] setP2(...)
554+
# 65| -1: [VarAccess] a0
555+
# 65| 0: [VarAccess] a1
556+
# 65| -3: [TypeAccess] KMutableProperty1<Generic<Integer>,Integer>
557+
# 66| 7: [ExprStmt] <Expr>;
558+
# 66| 0: [MethodAccess] println(...)
559+
# 66| -1: [TypeAccess] ConsoleKt
560+
# 66| 0: [PropertyRefExpr] ...::...
561+
# 66| -4: [AnonymousClass] new KMutableProperty0<Integer>(...) { ... }
562+
# 66| 1: [Constructor]
563+
#-----| 4: (Parameters)
564+
# 66| 0: [Parameter] <dispatchReceiver>
565+
# 66| 5: [BlockStmt] { ... }
566+
# 66| 0: [SuperConstructorInvocationStmt] super(...)
567+
# 66| 1: [ExprStmt] <Expr>;
568+
# 66| 0: [AssignExpr] ...=...
569+
# 66| 0: [VarAccess] this.<dispatchReceiver>
570+
# 66| -1: [ThisAccess] this
571+
# 66| 1: [VarAccess] <dispatchReceiver>
572+
# 66| 1: [FieldDeclaration] Generic<Integer> <dispatchReceiver>;
573+
# 66| -1: [TypeAccess] Generic<Integer>
574+
# 66| 1: [Method] get
575+
# 66| 5: [BlockStmt] { ... }
576+
# 66| 0: [ReturnStmt] return ...
577+
# 66| 0: [MethodAccess] getP2(...)
578+
# 66| -1: [VarAccess] this.<dispatchReceiver>
579+
# 66| -1: [ThisAccess] this
580+
# 66| 1: [Method] set
581+
#-----| 4: (Parameters)
582+
# 66| 0: [Parameter] a0
583+
# 66| 5: [BlockStmt] { ... }
584+
# 66| 0: [ReturnStmt] return ...
585+
# 66| 0: [MethodAccess] setP2(...)
586+
# 66| -1: [VarAccess] this.<dispatchReceiver>
587+
# 66| -1: [ThisAccess] this
588+
# 66| 0: [VarAccess] a0
589+
# 66| -3: [TypeAccess] KMutableProperty0<Integer>
590+
# 66| 0: [ClassInstanceExpr] new Generic<Integer>(...)
591+
# 66| -3: [TypeAccess] Generic<Integer>
592+
# 66| 0: [TypeAccess] Integer
593+
# 69| 4: [Class,GenericType,ParameterizedType] Generic
594+
#-----| -2: (Generic Parameters)
595+
# 69| 0: [TypeVariable] T1
596+
# 69| 1: [Constructor] Generic
597+
# 69| 5: [BlockStmt] { ... }
598+
# 69| 0: [SuperConstructorInvocationStmt] super(...)
599+
# 69| 1: [ExprStmt] <Expr>;
600+
# 69| 0: [MethodAccess] <obinit>(...)
601+
# 70| 3: [Method] m1
602+
#-----| 4: (Parameters)
603+
# 70| 0: [Parameter] i
604+
# 70| 5: [BlockStmt] { ... }
605+
# 70| 0: [ReturnStmt] return ...
606+
# 70| 0: [MethodAccess] toString(...)
607+
# 70| -1: [ThisAccess] this
608+
# 72| 4: [Method] getP2
609+
# 72| 5: [BlockStmt] { ... }
610+
# 72| 0: [ReturnStmt] return ...
611+
# 72| 0: [NullLiteral] null
612+
# 73| 5: [Method] setP2
613+
#-----| 4: (Parameters)
614+
# 73| 0: [Parameter] value
615+
# 73| 5: [BlockStmt] { ... }
616+
# 73| 0: [ReturnStmt] return ...
617+
# 73| 0: [VarAccess] INSTANCE

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,25 @@ invocation
3636
| reflection.kt:49:30:49:34 | get(...) | file://<external>/KProperty0.class:0:0:0:0 | get |
3737
functionReferences
3838
| reflection.kt:5:49:5:54 | ...::... | reflection.kt:5:49:5:54 | invoke | reflection.kt:27:9:27:33 | m |
39+
| reflection.kt:12:38:12:44 | ...::... | reflection.kt:12:38:12:44 | invoke | file://<external>/KProperty1.class:0:0:0:0 | get |
40+
| reflection.kt:19:44:19:50 | ...::... | reflection.kt:19:44:19:50 | invoke | file://<external>/KMutableProperty1.class:0:0:0:0 | set |
41+
| reflection.kt:58:17:58:32 | ...::... | reflection.kt:58:17:58:32 | invoke | reflection.kt:70:9:70:38 | m1 |
42+
| reflection.kt:59:17:59:34 | ...::... | reflection.kt:59:17:59:34 | invoke | reflection.kt:70:9:70:38 | m1 |
43+
| reflection.kt:60:17:60:34 | ...::... | reflection.kt:60:17:60:34 | invoke | reflection.kt:52:1:52:52 | ext1 |
44+
| reflection.kt:61:17:61:36 | ...::... | reflection.kt:61:17:61:36 | invoke | reflection.kt:52:1:52:52 | ext1 |
45+
| reflection.kt:62:17:62:34 | ...::... | reflection.kt:62:17:62:34 | invoke | reflection.kt:54:1:54:48 | ext2 |
46+
| reflection.kt:63:17:63:36 | ...::... | reflection.kt:63:17:63:36 | invoke | reflection.kt:54:1:54:48 | ext2 |
3947
propertyGetReferences
4048
| reflection.kt:8:38:8:42 | ...::... | reflection.kt:8:38:8:42 | get | reflection.kt:8:38:8:42 | get |
4149
| reflection.kt:13:35:13:41 | ...::... | reflection.kt:13:35:13:41 | get | reflection.kt:13:35:13:41 | get |
4250
| reflection.kt:15:45:15:49 | ...::... | reflection.kt:15:45:15:49 | get | reflection.kt:15:45:15:49 | get |
4351
| reflection.kt:20:42:20:48 | ...::... | reflection.kt:20:42:20:48 | get | reflection.kt:20:42:20:48 | get |
4452
| reflection.kt:48:13:48:28 | ...::... | reflection.kt:48:13:48:28 | get | reflection.kt:48:13:48:28 | get |
4553
| reflection.kt:49:13:49:28 | ...::... | reflection.kt:49:13:49:28 | get | reflection.kt:49:13:49:28 | get |
54+
| reflection.kt:65:17:65:32 | ...::... | reflection.kt:65:17:65:32 | get | reflection.kt:65:17:65:32 | get |
55+
| reflection.kt:66:17:66:34 | ...::... | reflection.kt:66:17:66:34 | get | reflection.kt:66:17:66:34 | get |
4656
propertySetReferences
4757
| reflection.kt:15:45:15:49 | ...::... | reflection.kt:15:45:15:49 | set | reflection.kt:15:45:15:49 | set |
4858
| reflection.kt:20:42:20:48 | ...::... | reflection.kt:20:42:20:48 | set | reflection.kt:20:42:20:48 | set |
59+
| reflection.kt:65:17:65:32 | ...::... | reflection.kt:65:17:65:32 | set | reflection.kt:65:17:65:32 | set |
60+
| reflection.kt:66:17:66:34 | ...::... | reflection.kt:66:17:66:34 | set | reflection.kt:66:17:66:34 | set |

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,28 @@ fun fn2() {
4848
println(String::lastChar.get("abc"))
4949
println("abcd"::lastChar.get())
5050
}
51+
52+
fun <T2> Class1.Generic<T2>.ext1() = this.toString()
53+
54+
fun Class1.Generic<Int>.ext2() = this.toString()
55+
56+
class Class1 {
57+
fun fn() {
58+
println(Generic<Int>::m1)
59+
println(Generic<Int>()::m1)
60+
println(Generic<Int>::ext1)
61+
println(Generic<Int>()::ext1)
62+
println(Generic<Int>::ext2)
63+
println(Generic<Int>()::ext2)
64+
65+
println(Generic<Int>::p2)
66+
println(Generic<Int>()::p2)
67+
}
68+
69+
class Generic<T1> {
70+
fun m1(i:T1) = this.toString()
71+
var p2: T1?
72+
get() = null
73+
set(value) = Unit
74+
}
75+
}

0 commit comments

Comments
 (0)