@@ -6,8 +6,10 @@ 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
9
10
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
10
11
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
12
+ import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol
11
13
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
12
14
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
13
15
import org.jetbrains.kotlin.ir.types.makeNullable
@@ -16,6 +18,7 @@ import org.jetbrains.kotlin.ir.util.functions
16
18
import org.jetbrains.kotlin.ir.util.isVararg
17
19
import org.jetbrains.kotlin.ir.util.nestedClasses
18
20
import org.jetbrains.kotlin.ir.util.properties
21
+ import org.jetbrains.kotlin.platform.jvm.isJvm
19
22
import org.jetbrains.kotlin.platform.konan.isNative
20
23
import org.jetbrains.kotlin.types.Variance
21
24
@@ -33,22 +36,10 @@ internal class RpcIrContext(
33
36
irBuiltIns.arrayClass.typeWith(anyNullable, Variance .OUT_VARIANCE )
34
37
}
35
38
36
- val listOfAnnotations by lazy {
37
- irBuiltIns.listClass.typeWith(irBuiltIns.annotationType)
38
- }
39
-
40
- val arrayOfAnnotations by lazy {
41
- irBuiltIns.arrayClass.typeWith(irBuiltIns.annotationType, Variance .OUT_VARIANCE )
42
- }
43
-
44
39
val kTypeClass by lazy {
45
40
getIrClassSymbol(" kotlin.reflect" , " KType" )
46
41
}
47
42
48
- val suspendFunction2 by lazy {
49
- getIrClassSymbol(" kotlin.coroutines" , " SuspendFunction2" )
50
- }
51
-
52
43
val flow by lazy {
53
44
getIrClassSymbol(" kotlinx.coroutines.flow" , " Flow" )
54
45
}
@@ -77,8 +68,56 @@ internal class RpcIrContext(
77
68
getIrClassSymbol(" kotlinx.rpc.grpc.descriptor" , " GrpcServiceDescriptor" )
78
69
}
79
70
80
- val grpcDelegate by lazy {
81
- getIrClassSymbol(" kotlinx.rpc.grpc.descriptor" , " GrpcDelegate" )
71
+ val grpcServiceDelegate by lazy {
72
+ getIrClassSymbol(" kotlinx.rpc.grpc.descriptor" , " GrpcServiceDelegate" )
73
+ }
74
+
75
+ val grpcPlatformServiceDescriptor by lazy {
76
+ if (isJvmTarget()) {
77
+ getIrClassSymbol(" io.grpc" , " ServiceDescriptor" )
78
+ } else {
79
+ getIrClassSymbol(" kotlinx.rpc.grpc.internal" , " ServiceDescriptor" )
80
+ }
81
+ }
82
+
83
+ val grpcPlatformMethodDescriptor by lazy {
84
+ if (isJvmTarget()) {
85
+ getIrClassSymbol(" io.grpc" , " MethodDescriptor" )
86
+ } else {
87
+ getIrClassSymbol(" kotlinx.rpc.grpc.internal" , " MethodDescriptor" )
88
+ }
89
+ }
90
+
91
+ val grpcPlatformMethodType by lazy {
92
+ getIrClassSymbol(" kotlinx.rpc.grpc.internal" , " MethodType" )
93
+ }
94
+
95
+ val grpcPlatformMethodTypeUnary by lazy {
96
+ grpcPlatformMethodType.enumEntry(" UNARY" )
97
+ }
98
+
99
+ val grpcPlatformMethodTypeServerStreaming by lazy {
100
+ grpcPlatformMethodType.enumEntry(" SERVER_STREAMING" )
101
+ }
102
+
103
+ val grpcPlatformMethodTypeClientStreaming by lazy {
104
+ grpcPlatformMethodType.enumEntry(" CLIENT_STREAMING" )
105
+ }
106
+
107
+ val grpcPlatformMethodTypeBidiStreaming by lazy {
108
+ grpcPlatformMethodType.enumEntry(" BIDI_STREAMING" )
109
+ }
110
+
111
+ val grpcMessageCodec by lazy {
112
+ getIrClassSymbol(" kotlinx.rpc.grpc.codec" , " MessageCodec" )
113
+ }
114
+
115
+ val grpcMessageCodecResolver by lazy {
116
+ getIrClassSymbol(" kotlinx.rpc.grpc.codec" , " MessageCodecResolver" )
117
+ }
118
+
119
+ val withCodecAnnotation by lazy {
120
+ getIrClassSymbol(" kotlinx.rpc.grpc.codec" , " WithCodec" )
82
121
}
83
122
84
123
val rpcType by lazy {
@@ -105,8 +144,12 @@ internal class RpcIrContext(
105
144
getRpcIrClassSymbol(" RpcInvokator" , " descriptor" )
106
145
}
107
146
108
- val rpcInvokatorMethod by lazy {
109
- rpcInvokator.subClass(" Method" )
147
+ val rpcInvokatorUnaryResponse by lazy {
148
+ rpcInvokator.subClass(" UnaryResponse" )
149
+ }
150
+
151
+ val rpcInvokatorFlowResponse by lazy {
152
+ rpcInvokator.subClass(" FlowResponse" )
110
153
}
111
154
112
155
val rpcParameter by lazy {
@@ -137,6 +180,10 @@ internal class RpcIrContext(
137
180
return pluginContext.platform.isNative()
138
181
}
139
182
183
+ fun isJvmTarget (): Boolean {
184
+ return pluginContext.platform.isJvm()
185
+ }
186
+
140
187
fun isWasmTarget (): Boolean {
141
188
return versionSpecificApi.isWasm(pluginContext.platform)
142
189
}
@@ -196,6 +243,22 @@ internal class RpcIrContext(
196
243
namedFunction(" kotlin" , " to" )
197
244
}
198
245
246
+ val serviceDescriptor by lazy {
247
+ namedFunction(" kotlinx.rpc.grpc.internal" , " serviceDescriptor" )
248
+ }
249
+
250
+ val methodDescriptor by lazy {
251
+ namedFunction(" kotlinx.rpc.grpc.internal" , " methodDescriptor" )
252
+ }
253
+
254
+ val grpcServiceDescriptorDelegate by lazy {
255
+ grpcServiceDescriptor.namedFunction(" delegate" )
256
+ }
257
+
258
+ val grpcMessageCodecResolverResolve by lazy {
259
+ grpcMessageCodecResolver.namedFunction(" resolve" )
260
+ }
261
+
199
262
private fun IrClassSymbol.namedFunction (name : String ): IrSimpleFunction {
200
263
return owner.functions.single { it.name.asString() == name }
201
264
}
@@ -214,12 +277,20 @@ internal class RpcIrContext(
214
277
val properties = Properties ()
215
278
216
279
inner class Properties {
280
+ val rpcServiceDescriptorSimpleName by lazy {
281
+ rpcServiceDescriptor.namedProperty(" simpleName" )
282
+ }
283
+
217
284
val rpcServiceDescriptorFqName by lazy {
218
285
rpcServiceDescriptor.namedProperty(" fqName" )
219
286
}
220
287
221
- val grpcServiceDescriptorDelegate by lazy {
222
- grpcServiceDescriptor.namedProperty(" delegate" )
288
+ val rpcServiceDescriptorCallables by lazy {
289
+ rpcServiceDescriptor.namedProperty(" callables" )
290
+ }
291
+
292
+ val mapValues by lazy {
293
+ irBuiltIns.mapClass.namedProperty(" values" )
223
294
}
224
295
225
296
private fun IrClassSymbol.namedProperty (name : String ): IrPropertySymbol {
@@ -231,6 +302,10 @@ internal class RpcIrContext(
231
302
return owner.nestedClasses.single { it.name.asString() == name }.symbol
232
303
}
233
304
305
+ private fun IrClassSymbol.enumEntry (name : String ): IrEnumEntrySymbol {
306
+ return owner.declarations.filterIsInstance<IrEnumEntry >().single { it.name.asString() == name }.symbol
307
+ }
308
+
234
309
private fun getRpcIrClassSymbol (name : String , subpackage : String? = null): IrClassSymbol {
235
310
val suffix = subpackage?.let { " .$subpackage " } ? : " "
236
311
return getIrClassSymbol(" kotlinx.rpc$suffix " , name)
0 commit comments