@@ -6,15 +6,15 @@ package kotlinx.rpc.codegen.extension
6
6
7
7
import kotlinx.rpc.codegen.VersionSpecificApi
8
8
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
9
- import org.jetbrains.kotlin.ir.declarations.IrEnumEntry
10
- import org.jetbrains.kotlin.ir.declarations.IrProperty
11
9
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
12
10
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
11
+ import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
13
12
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
14
13
import org.jetbrains.kotlin.ir.types.classOrNull
15
14
import org.jetbrains.kotlin.ir.types.makeNullable
16
15
import org.jetbrains.kotlin.ir.util.functions
17
16
import org.jetbrains.kotlin.ir.util.isVararg
17
+ import org.jetbrains.kotlin.ir.util.nestedClasses
18
18
import org.jetbrains.kotlin.ir.util.properties
19
19
import org.jetbrains.kotlin.platform.konan.isNative
20
20
import org.jetbrains.kotlin.types.Variance
@@ -53,10 +53,18 @@ internal class RPCIrContext(
53
53
getIrClassSymbol(" kotlin" , " Function0" )
54
54
}
55
55
56
+ val function1 by lazy {
57
+ getIrClassSymbol(" kotlin" , " Function1" )
58
+ }
59
+
56
60
val suspendFunction0 by lazy {
57
61
getIrClassSymbol(" kotlin.coroutines" , " SuspendFunction0" )
58
62
}
59
63
64
+ val suspendFunction2 by lazy {
65
+ getIrClassSymbol(" kotlin.coroutines" , " SuspendFunction2" )
66
+ }
67
+
60
68
val flow by lazy {
61
69
getIrClassSymbol(" kotlinx.coroutines.flow" , " Flow" )
62
70
}
@@ -78,45 +86,55 @@ internal class RPCIrContext(
78
86
}
79
87
80
88
val rpcClient by lazy {
81
- getRpcIrClassSymbol(" RPCClient " )
89
+ getRpcIrClassSymbol(" RpcClient " )
82
90
}
83
91
84
92
val rpcCall by lazy {
85
- getRpcIrClassSymbol(" RPCCall" )
93
+ getRpcIrClassSymbol(" RpcCall" )
94
+ }
95
+
96
+ val withServiceDescriptor by lazy {
97
+ getRpcIrClassSymbol(" WithServiceDescriptor" , " internal" )
86
98
}
87
99
88
- val rpcCallType by lazy {
89
- getRpcIrClassSymbol(" RPCCall.Type " )
100
+ val rpcEagerFieldAnnotation by lazy {
101
+ getRpcIrClassSymbol(" RPCEagerField " )
90
102
}
91
103
92
- val rpcCallTypeMethod by lazy {
93
- rpcCallType.owner.declarations.filterIsInstance<IrEnumEntry >().single {
94
- it.name.asString() == " Method"
95
- }.symbol
104
+ val rpcServiceDescriptor by lazy {
105
+ getRpcIrClassSymbol(" RpcServiceDescriptor" , " descriptor" )
96
106
}
97
107
98
- val rpcField by lazy {
99
- getRpcIrClassSymbol(" RPCField " )
108
+ val rpcCallable by lazy {
109
+ getRpcIrClassSymbol(" RpcCallable " , " descriptor " )
100
110
}
101
111
102
- val withRPCStubObjectAnnotation by lazy {
103
- getRpcIrClassSymbol(" WithRPCStubObject " , " internal " )
112
+ private val rpcInvokator by lazy {
113
+ getRpcIrClassSymbol(" RpcInvokator " , " descriptor " )
104
114
}
105
115
106
- val rpcEagerFieldAnnotation by lazy {
107
- getRpcIrClassSymbol( " RPCEagerField " )
116
+ val rpcInvokatorMethod by lazy {
117
+ rpcInvokator.subClass( " Method " )
108
118
}
109
119
110
- val rpcStubObject by lazy {
111
- getRpcIrClassSymbol(" RPCStubObject" , " internal" )
120
+ val rpcInvokatorField by lazy {
121
+ rpcInvokator.subClass(" Field" )
122
+ }
123
+
124
+ val rpcParameter by lazy {
125
+ getRpcIrClassSymbol(" RpcParameter" , " descriptor" )
112
126
}
113
127
114
128
val rpcDeferredField by lazy {
115
- getRpcIrClassSymbol(" RPCDeferredField " , " internal" )
129
+ getRpcIrClassSymbol(" RpcDeferredField " , " internal" )
116
130
}
117
131
118
- val rpcMethodClassArguments by lazy {
119
- getRpcIrClassSymbol(" RPCMethodClassArguments" , " internal" )
132
+ val fieldDataObject by lazy {
133
+ getRpcIrClassSymbol(" FieldDataObject" , " internal" )
134
+ }
135
+
136
+ val rpcMethodClass by lazy {
137
+ getRpcIrClassSymbol(" RpcMethodClass" , " internal" )
120
138
}
121
139
122
140
fun isJsTarget (): Boolean {
@@ -135,15 +153,19 @@ internal class RPCIrContext(
135
153
136
154
inner class Functions {
137
155
val registerPlainFlowField by lazy {
138
- rpcClient. namedFunction(" registerPlainFlowField" )
156
+ namedFunction(" kotlinx.rpc " , " registerPlainFlowField" )
139
157
}
140
158
141
159
val registerSharedFlowField by lazy {
142
- rpcClient. namedFunction(" registerSharedFlowField" )
160
+ namedFunction(" kotlinx.rpc " , " registerSharedFlowField" )
143
161
}
144
162
145
163
val registerStateFlowField by lazy {
146
- rpcClient.namedFunction(" registerStateFlowField" )
164
+ namedFunction(" kotlinx.rpc" , " registerStateFlowField" )
165
+ }
166
+
167
+ val dataCast by lazy {
168
+ namedFunction(" kotlinx.rpc.internal" , " dataCast" )
147
169
}
148
170
149
171
val rpcClientCall by lazy {
@@ -155,7 +177,7 @@ internal class RPCIrContext(
155
177
}
156
178
157
179
val asArray by lazy {
158
- rpcMethodClassArguments .namedFunction(" asArray" )
180
+ rpcMethodClass .namedFunction(" asArray" )
159
181
}
160
182
161
183
val typeOf by lazy {
@@ -217,7 +239,7 @@ internal class RPCIrContext(
217
239
private fun namedFunction (
218
240
packageName : String ,
219
241
name : String ,
220
- filterOverloads : ((IrSimpleFunctionSymbol ) -> Boolean )? = null
242
+ filterOverloads : ((IrSimpleFunctionSymbol ) -> Boolean )? = null,
221
243
): IrSimpleFunctionSymbol {
222
244
val found = versionSpecificApi.referenceFunctions(pluginContext, packageName, name)
223
245
@@ -232,17 +254,25 @@ internal class RPCIrContext(
232
254
rpcClient.namedProperty(" coroutineContext" )
233
255
}
234
256
235
- private fun IrClassSymbol.namedProperty (name : String ): IrProperty {
236
- return owner.properties.single { it.name.asString() == name }
257
+ val rpcServiceDescriptorFqName by lazy {
258
+ rpcServiceDescriptor.namedProperty(" fqName" )
259
+ }
260
+
261
+ private fun IrClassSymbol.namedProperty (name : String ): IrPropertySymbol {
262
+ return owner.properties.single { it.name.asString() == name }.symbol
237
263
}
238
264
}
239
265
266
+ private fun IrClassSymbol.subClass (name : String ): IrClassSymbol {
267
+ return owner.nestedClasses.single { it.name.asString() == name }.symbol
268
+ }
269
+
240
270
private fun getRpcIrClassSymbol (name : String , subpackage : String? = null): IrClassSymbol {
241
271
val suffix = subpackage?.let { " .$subpackage " } ? : " "
242
272
return getIrClassSymbol(" kotlinx.rpc$suffix " , name)
243
273
}
244
274
245
- fun getIrClassSymbol (packageName : String , name : String ): IrClassSymbol {
275
+ private fun getIrClassSymbol (packageName : String , name : String ): IrClassSymbol {
246
276
return versionSpecificApi.referenceClass(pluginContext, packageName, name)
247
277
? : error(" Unable to find symbol. Package: $packageName , name: $name " )
248
278
}
0 commit comments