@@ -8,54 +8,99 @@ class Test(var a: List<Any>, b: List<Any>)
8
8
9
9
fun main () {
10
10
val tmp = Test (emptyList(), emptyList())
11
- tmp.a = listOf ( Reflekt .objects().withSubType <AInterface >().withAnnotations<AInterface >(FirstAnnotation ::class ))
12
- println (tmp)
11
+ tmp.a = Reflekt .objects().withSupertype <AInterface >().withAnnotations<AInterface >(FirstAnnotation ::class ).toList( )
12
+ println (tmp.a )
13
13
14
- val objects = Reflekt .objects().withSubType <AInterface >().withAnnotations<AInterface >(FirstAnnotation ::class , SecondAnnotation ::class ).toList()
14
+ val objects = Reflekt .objects().withSupertype <AInterface >().withAnnotations<AInterface >(FirstAnnotation ::class , SecondAnnotation ::class ).toList()
15
15
println (objects)
16
- val objects1 = Reflekt .objects().withSubType <AInterface >()
16
+ val objects1 = Reflekt .objects().withSupertype <AInterface >()
17
17
.withAnnotations<AInterface >(FirstAnnotation ::class , SecondAnnotation ::class ).toList()
18
18
println (objects1)
19
19
20
- val objects2 = Reflekt .objects().withSubTypes (AInterface ::class , A1 ::class )
20
+ val objects2 = Reflekt .objects().withSupertypes (AInterface ::class , A1 ::class )
21
21
.withAnnotations<AInterface >(FirstAnnotation ::class , SecondAnnotation ::class ).toList()
22
22
println (objects2)
23
23
24
- val objects3 = Reflekt .objects().withSubTypes (AInterface ::class , A1 ::class )
24
+ val objects3 = Reflekt .objects().withSupertypes (AInterface ::class , A1 ::class )
25
25
.withAnnotations<AInterface >(FirstAnnotation ::class ).toList()
26
26
println (objects3)
27
27
28
28
val objects4 = Reflekt .objects().withAnnotations<AInterface >(FirstAnnotation ::class ).toList()
29
29
println (objects4)
30
30
val objects5 = Reflekt .objects().withAnnotations<AInterface >(FirstAnnotation ::class ).toList()
31
31
println (objects5)
32
- val objects6 = Reflekt .objects().withAnnotations<A1 >(FirstAnnotation ::class ).withSubType <AInterface >().toList()
32
+ val objects6 = Reflekt .objects().withAnnotations<A1 >(FirstAnnotation ::class ).withSupertype <AInterface >().toList()
33
33
println (objects6)
34
- val objects7 = Reflekt .objects().withAnnotations<A1 >(FirstAnnotation ::class ).withSubTypes (AInterface ::class ).toList()
34
+ val objects7 = Reflekt .objects().withAnnotations<A1 >(FirstAnnotation ::class ).withSupertypes (AInterface ::class ).toList()
35
35
println (objects7)
36
- val objects8 = Reflekt .objects().withSubType <AInterface >().toList()
36
+ val objects8 = Reflekt .objects().withSupertype <AInterface >().toList()
37
37
println (objects8)
38
38
39
- val classes1 = Reflekt .classes().withSubType <AInterface >().toList()
39
+ val classes1 = Reflekt .classes().withSupertype <AInterface >().toList()
40
40
println (classes1)
41
- val classes2 = Reflekt .classes().withSubType <BInterface >().toSet()
41
+ val classes2 = Reflekt .classes().withSupertype <BInterface >().toSet()
42
42
println (classes2)
43
43
val classes3 = Reflekt .classes().withAnnotations<B2 >(FirstAnnotation ::class , SecondAnnotation ::class ).toList()
44
44
println (classes3)
45
45
46
- val classes4 = Reflekt .classes().withSubType <Action >().toList()
46
+ val classes4 = Reflekt .classes().withSupertype <Action >().toList()
47
47
println (classes4)
48
48
49
49
val functions = Reflekt .functions().withAnnotations< () -> Unit > (FirstAnnotation ::class ).toList()
50
50
println (functions)
51
51
52
- val smartClasses = SmartReflekt .classes<BInterface >().filter { it.isData() }.resolve()
53
- println (smartClasses)
54
-
55
- val smartObjects = SmartReflekt .objects<BInterface >().filter { it.isCompanion() }.resolve()
56
- println (smartObjects)
52
+ // TODO: it does not work (error with TestFunctions$Companion), see issue#52: https://github.com/JetBrains-Research/reflekt/issues/52
53
+ // val smartClasses = SmartReflekt.classes<BInterface>().filter { it.isData() }.resolve()
54
+ // println(smartClasses)
55
+ //
56
+ // val smartObjects = SmartReflekt.objects<BInterface>().filter { it.isCompanion() }.resolve()
57
+ // println(smartObjects)
57
58
58
59
val smartFunctions = SmartReflekt .functions< () -> Unit > ().filter { it.isTopLevel && it.name == " foo" }.resolve()
59
60
println (smartFunctions)
60
61
smartFunctions.forEach { it() }
62
+
63
+ val fooBoolean = SmartReflekt .functions< () -> Boolean > ().filter { it.isTopLevel && it.name == " fooBoolean" }.resolve().onEach { it() }
64
+ .map { it.toString() }.toSet()
65
+ println (" fooBoolean: $fooBoolean " )
66
+
67
+ val fooStar = SmartReflekt .functions< (List <* >) -> Unit > ().filter { it.isTopLevel && it.name == " withStar" }.resolve().onEach { it(listOf (1 )) }
68
+ .map { it.toString() }.toSet()
69
+ println (" fooStar: $fooStar " )
70
+
71
+ // TODO: we will support gnerics with bounds
72
+ // val fooBound = SmartReflekt.functions<(Number) -> Unit>().filter { it.isTopLevel && it.name == "withBound" }.resolve().onEach { it(listOf(1)) }
73
+ // .map { it.toString() }.toSet()
74
+ // println("fooBound: $fooBound")
75
+
76
+ /* *
77
+ * Such calls still fail, but it seems it's not a Reflekt problem since Kotlin doesn't consider our functions as subtypes of the given signature.
78
+ */
79
+
80
+ // val fooArray = SmartReflekt.functions<Function0<Array<*>>>().filter { it.isTopLevel && it.name == "fooArray" }.resolve().onEach { it() }.map { it.toString() }.toSet()
81
+ // println(fooArray)
82
+ //
83
+ // val fooList = SmartReflekt.functions<Function0<List<*>>>().filter { it.isTopLevel && it.name == "fooList" }.resolve().onEach { it() }.map { it.toString() }.toSet()
84
+ // println(fooList)
85
+ //
86
+ // val fooMyInClass = SmartReflekt.functions<Function0<MyInClass<*>>>().filter { it.isTopLevel && it.name == "fooMyInClass" }.resolve().onEach { it() }.map { it.toString() }.toSet()
87
+ // println(fooMyInClass)
88
+
89
+ /* *
90
+ * The simplest way to check it's to pass our functions as a parameter of an argument with the given signature:
91
+ */
92
+ // arrayTestFun(::fooArray)
93
+ // listTestFun(::fooList)
94
+ // myInClassTestFun(::fooMyInClass)
95
+
96
+ /* *
97
+ * For each of the functions Kotlin says [NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER] Not enough information to infer type variable T
98
+ * Maybe we need to check https://kotlinlang.org/spec/type-system.html#mixed-site-variance
99
+ */
61
100
}
101
+
102
+ fun arrayTestFun (funToTest : Function0 <Array <* >>) {}
103
+
104
+ fun listTestFun (funToTest : Function0 <List <* >>) {}
105
+
106
+ fun myInClassTestFun (funToTest : Function0 <MyInClass <* >>) {}
0 commit comments