Skip to content

Commit a21a5cc

Browse files
authored
Api naming (#236)
1 parent 41d4a86 commit a21a5cc

File tree

167 files changed

+1464
-1146
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+1464
-1146
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ A few things to remember:
102102
* Every public API (including functions, classes, objects and so on) should be documented,
103103
every parameter, property, return types and exceptions should be described properly.
104104
* A Public API that is not intended to be used by end-users that couldn't be made private/internal due to technical reasons,
105-
should be marked with `@InternalRPCApi` annotation.
105+
should be marked with `@InternalRpcApi` annotation.
106106

107107
### Commit messages
108108

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Then, choose how do you want your service to communicate. For example, you can u
4444
```kotlin
4545
fun main() {
4646
embeddedServer(Netty, 8080) {
47-
install(RPC)
47+
install(Krpc)
4848
routing {
4949
rpc("/awesome") {
5050
rpcConfig {
@@ -61,7 +61,7 @@ fun main() {
6161
```
6262
To connect to the server use the following [Ktor Client](https://ktor.io/docs/create-client.html) setup:
6363
```kotlin
64-
val rpcClient = HttpClient { installRPC() }.rpc {
64+
val rpcClient = HttpClient { installKrpc() }.rpc {
6565
url("ws://localhost:8080/awesome")
6666

6767
rpcConfig {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import org.jetbrains.kotlin.ir.util.dumpKotlinLike
1616

1717
/**
1818
* This class scans user declared RPC service
19-
* and returns all necessary information for code generation by [RPCStubGenerator].
19+
* and returns all necessary information for code generation by [RpcStubGenerator].
2020
*
2121
* Some checks are preformed during scanning,
2222
* but all user-friendly errors are expected to be thrown by frontend plugins
2323
*/
24-
internal object RPCDeclarationScanner {
25-
fun scanServiceDeclaration(service: IrClass, ctx: RPCIrContext, logger: MessageCollector): ServiceDeclaration {
24+
internal object RpcDeclarationScanner {
25+
fun scanServiceDeclaration(service: IrClass, ctx: RpcIrContext, logger: MessageCollector): ServiceDeclaration {
2626
var stubClass: IrClass? = null
2727

2828
val declarations = service.declarations.memoryOptimizedMap { declaration ->

compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RPCIrContext.kt renamed to compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcIrContext.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import org.jetbrains.kotlin.ir.util.properties
1919
import org.jetbrains.kotlin.platform.konan.isNative
2020
import org.jetbrains.kotlin.types.Variance
2121

22-
internal class RPCIrContext(
22+
internal class RpcIrContext(
2323
val pluginContext: IrPluginContext,
2424
val versionSpecificApi: VersionSpecificApi,
2525
) {
@@ -98,7 +98,7 @@ internal class RPCIrContext(
9898
}
9999

100100
val rpcEagerFieldAnnotation by lazy {
101-
getRpcIrClassSymbol("RPCEagerField")
101+
getRpcIrClassSymbol("RpcEagerField")
102102
}
103103

104104
val rpcServiceDescriptor by lazy {
@@ -200,7 +200,7 @@ internal class RPCIrContext(
200200

201201
val lazyGetValue by lazy {
202202
namedFunction("kotlin", "getValue") {
203-
it.owner.extensionReceiverParameter?.type?.classOrNull == this@RPCIrContext.lazy
203+
it.owner.extensionReceiverParameter?.type?.classOrNull == this@RpcIrContext.lazy
204204
}
205205
}
206206

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ import org.jetbrains.kotlin.cli.common.messages.MessageCollector
1111
import org.jetbrains.kotlin.config.CompilerConfiguration
1212
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
1313

14-
class RPCIrExtension(configuration: CompilerConfiguration) : IrGenerationExtension {
14+
class RpcIrExtension(configuration: CompilerConfiguration) : IrGenerationExtension {
1515
private val logger = configuration.get(VersionSpecificApi.INSTANCE.messageCollectorKey, MessageCollector.NONE)
1616

1717
override fun generate(
1818
moduleFragment: IrModuleFragment,
1919
pluginContext: IrPluginContext,
2020
) {
21-
val context = RPCIrContext(pluginContext, VersionSpecificApi.INSTANCE)
21+
val context = RpcIrContext(pluginContext, VersionSpecificApi.INSTANCE)
2222

23-
val processor = RPCIrServiceProcessor(logger)
23+
val processor = RpcIrServiceProcessor(logger)
2424
moduleFragment.transform(processor, context)
2525
}
2626
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ import org.jetbrains.kotlin.ir.declarations.IrClass
1111
import org.jetbrains.kotlin.ir.util.hasAnnotation
1212
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
1313

14-
internal class RPCIrServiceProcessor(
14+
internal class RpcIrServiceProcessor(
1515
@Suppress("unused")
1616
private val logger: MessageCollector,
17-
) : IrElementTransformer<RPCIrContext> {
18-
override fun visitClass(declaration: IrClass, data: RPCIrContext): IrStatement {
17+
) : IrElementTransformer<RpcIrContext> {
18+
override fun visitClass(declaration: IrClass, data: RpcIrContext): IrStatement {
1919
if (declaration.hasAnnotation(RpcClassId.rpcAnnotation)) {
2020
processService(declaration, data)
2121
}
2222

2323
return super.visitClass(declaration, data)
2424
}
2525

26-
private fun processService(service: IrClass, context: RPCIrContext) {
27-
val declaration = RPCDeclarationScanner.scanServiceDeclaration(service, context, logger)
28-
RPCStubGenerator(declaration, context, logger).generate()
26+
private fun processService(service: IrClass, context: RpcIrContext) {
27+
val declaration = RpcDeclarationScanner.scanServiceDeclaration(service, context, logger)
28+
RpcStubGenerator(declaration, context, logger).generate()
2929
}
3030
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ private object Descriptor {
4545
}
4646

4747
@Suppress("detekt.LargeClass", "detekt.TooManyFunctions")
48-
internal class RPCStubGenerator(
48+
internal class RpcStubGenerator(
4949
private val declaration: ServiceDeclaration,
50-
private val ctx: RPCIrContext,
50+
private val ctx: RpcIrContext,
5151
@Suppress("unused")
5252
private val logger: MessageCollector,
5353
) {
@@ -253,7 +253,7 @@ internal class RPCStubGenerator(
253253

254254
/**
255255
* RPC fields.
256-
* Can be of two kinds: Lazy and Eager (defined by `@RPCEagerField` annotation)
256+
* Can be of two kinds: Lazy and Eager (defined by `@RpcEagerField` annotation)
257257
*
258258
* Lazy:
259259
* ``` kotlin
@@ -623,15 +623,15 @@ internal class RPCStubGenerator(
623623
* ```
624624
*
625625
* This method generates missing getters and backing fields' values.
626-
* And adds RPCMethodClassArguments supertype with `asArray` method implemented.
626+
* And adds RpcMethodClassArguments supertype with `asArray` method implemented.
627627
*
628628
* Resulting class:
629629
* ```kotlin
630630
* @Serializable
631631
* class hello$rpcMethod(
632632
* val arg1: String,
633633
* val arg2: Int,
634-
* ) : RPCMethodClassArguments {
634+
* ) : RpcMethodClassArguments {
635635
* // or emptyArray when no arguments
636636
* override fun asArray(): Array<Any?> = arrayOf(arg1, arg2)
637637
* }

compiler-plugin/compiler-plugin-cli/src/main-resources/latest/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
#
44

5-
kotlinx.rpc.codegen.RPCCommandLineProcessor
5+
kotlinx.rpc.codegen.RpcCommandLineProcessor

compiler-plugin/compiler-plugin-cli/src/main-resources/latest/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
#
44

5-
kotlinx.rpc.codegen.RPCCompilerPlugin
5+
kotlinx.rpc.codegen.RpcCompilerPlugin

compiler-plugin/compiler-plugin-cli/src/main/latest/kotlinx/rpc/codegen/RPCCompilerPlugin.kt renamed to compiler-plugin/compiler-plugin-cli/src/main/latest/kotlinx/rpc/codegen/RpcCompilerPlugin.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
package kotlinx.rpc.codegen
66

7-
import kotlinx.rpc.codegen.extension.RPCIrExtension
7+
import kotlinx.rpc.codegen.extension.RpcIrExtension
88
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
99
import org.jetbrains.kotlin.compiler.plugin.CliOption
1010
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
@@ -14,14 +14,14 @@ import org.jetbrains.kotlin.config.CompilerConfiguration
1414
import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrarAdapter
1515

1616
@OptIn(ExperimentalCompilerApi::class)
17-
class RPCCommandLineProcessor : CommandLineProcessor {
17+
class RpcCommandLineProcessor : CommandLineProcessor {
1818
override val pluginId = "kotlinx.rpc.compiler-plugin"
1919

2020
override val pluginOptions = emptyList<CliOption>()
2121
}
2222

2323
@OptIn(ExperimentalCompilerApi::class)
24-
class RPCCompilerPlugin : CompilerPluginRegistrar() {
24+
class RpcCompilerPlugin : CompilerPluginRegistrar() {
2525
override val supportsK2: Boolean = true
2626

2727
override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
@@ -33,6 +33,6 @@ class RPCCompilerPlugin : CompilerPluginRegistrar() {
3333
fun CompilerPluginRegistrar.ExtensionStorage.registerRpcExtensions(configuration: CompilerConfiguration) {
3434
VersionSpecificApi.INSTANCE = VersionSpecificApiImpl
3535

36-
IrGenerationExtension.registerExtension(RPCIrExtension(configuration))
36+
IrGenerationExtension.registerExtension(RpcIrExtension(configuration))
3737
FirExtensionRegistrarAdapter.registerExtension(FirRpcExtensionRegistrar(configuration))
3838
}

compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirGenerationKeys.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,30 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
1212
import org.jetbrains.kotlin.name.Name
1313
import org.jetbrains.kotlinx.serialization.compiler.fir.SerializationPluginKey
1414

15-
internal class RPCGeneratedStubKey(
15+
internal class RpcGeneratedStubKey(
1616
private val serviceName: Name,
1717
val functions: List<FirFunctionSymbol<*>>,
1818
) : GeneratedDeclarationKey() {
1919
override fun toString(): String {
20-
return "RPCGeneratedStubKey.$serviceName"
20+
return "RpcGeneratedStubKey.$serviceName"
2121
}
2222
}
2323

24-
internal val FirBasedSymbol<*>.generatedRpcServiceStubKey: RPCGeneratedStubKey? get() =
25-
(origin as? FirDeclarationOrigin.Plugin)?.key as? RPCGeneratedStubKey
24+
internal val FirBasedSymbol<*>.generatedRpcServiceStubKey: RpcGeneratedStubKey? get() =
25+
(origin as? FirDeclarationOrigin.Plugin)?.key as? RpcGeneratedStubKey
2626

27-
internal class RPCGeneratedRpcMethodClassKey(
27+
internal class RpcGeneratedRpcMethodClassKey(
2828
val rpcMethod: FirFunctionSymbol<*>,
2929
) : GeneratedDeclarationKey() {
3030
val isObject = rpcMethod.valueParameterSymbols.isEmpty()
3131

3232
override fun toString(): String {
33-
return "RPCGeneratedRpcMethodClassKey.${rpcMethod.name}"
33+
return "RpcGeneratedRpcMethodClassKey.${rpcMethod.name}"
3434
}
3535
}
3636

37-
internal val FirBasedSymbol<*>.generatedRpcMethodClassKey: RPCGeneratedRpcMethodClassKey? get() =
38-
(origin as? FirDeclarationOrigin.Plugin)?.key as? RPCGeneratedRpcMethodClassKey
37+
internal val FirBasedSymbol<*>.generatedRpcMethodClassKey: RpcGeneratedRpcMethodClassKey? get() =
38+
(origin as? FirDeclarationOrigin.Plugin)?.key as? RpcGeneratedRpcMethodClassKey
3939

4040
internal object FirRpcServiceStubCompanionObject : GeneratedDeclarationKey() {
4141
override fun toString(): String {

compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirRPCServiceGenerator.kt renamed to compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirRpcServiceGenerator.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ class FirRpcServiceGenerator(
8484
*
8585
* - Companion object of the service stub and method classes.
8686
* If we generate this companion object, we will have [FirClassSymbol.origin]
87-
* of [classSymbol] be set to [RPCGeneratedStubKey],
87+
* of [classSymbol] be set to [RpcGeneratedStubKey],
8888
* because we're inside the previously generated service stub class.
8989
* The same goes for method classes too.
9090
* So we return [SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT]
9191
* and a list of method class names.
9292
*
9393
* - Inside method classes.
9494
* Method classes will too have their nested declarations.
95-
* We detect them by using [RPCGeneratedRpcMethodClassKey].
95+
* We detect them by using [RpcGeneratedRpcMethodClassKey].
9696
* Nested declarations for these classes are provided by the serialization plugin.
9797
* These declarations can be of two types: serializable object and serializable classes.
9898
* In the case of objects,
@@ -183,11 +183,11 @@ class FirRpcServiceGenerator(
183183
private fun generateRpcMethodClass(
184184
owner: FirClassSymbol<*>,
185185
name: Name,
186-
rpcServiceStubKey: RPCGeneratedStubKey,
186+
rpcServiceStubKey: RpcGeneratedStubKey,
187187
): FirClassLikeSymbol<*> {
188188
val methodName = name.rpcMethodName
189189
val rpcMethod = rpcServiceStubKey.functions.single { it.name == methodName }
190-
val rpcMethodClassKey = RPCGeneratedRpcMethodClassKey(rpcMethod)
190+
val rpcMethodClassKey = RpcGeneratedRpcMethodClassKey(rpcMethod)
191191
val classKind = if (rpcMethodClassKey.isObject) ClassKind.OBJECT else ClassKind.CLASS
192192

193193
val rpcMethodClass = createNestedClass(
@@ -261,7 +261,7 @@ class FirRpcServiceGenerator(
261261
.filterIsInstance<FirFunction>()
262262
.map { it.symbol }
263263

264-
return createNestedClass(owner, RpcNames.SERVICE_STUB_NAME, RPCGeneratedStubKey(owner.name, functions)) {
264+
return createNestedClass(owner, RpcNames.SERVICE_STUB_NAME, RpcGeneratedStubKey(owner.name, functions)) {
265265
visibility = Visibilities.Public
266266
modality = Modality.FINAL
267267
}.symbol
@@ -293,7 +293,7 @@ class FirRpcServiceGenerator(
293293
private fun getCallableNamesForRpcMethodClass(
294294
classSymbol: FirClassSymbol<*>,
295295
context: MemberGenerationContext,
296-
rpcMethodClassKey: RPCGeneratedRpcMethodClassKey,
296+
rpcMethodClassKey: RpcGeneratedRpcMethodClassKey,
297297
): Set<Name> {
298298
return if (rpcMethodClassKey.isObject) {
299299
// add .serializer() method for a serializable object
@@ -321,7 +321,7 @@ class FirRpcServiceGenerator(
321321
*/
322322
private fun generateConstructorsForRpcMethodClass(
323323
context: MemberGenerationContext,
324-
rpcMethodClassKey: RPCGeneratedRpcMethodClassKey,
324+
rpcMethodClassKey: RpcGeneratedRpcMethodClassKey,
325325
): List<FirConstructorSymbol> {
326326
if (rpcMethodClassKey.isObject) {
327327
return createDefaultPrivateConstructor(context.owner, rpcMethodClassKey).symbol.let(::listOf)
@@ -366,7 +366,7 @@ class FirRpcServiceGenerator(
366366
private fun generatePropertiesForRpcMethodClass(
367367
callableId: CallableId,
368368
owner: FirClassSymbol<*>,
369-
rpcMethodClassKey: RPCGeneratedRpcMethodClassKey,
369+
rpcMethodClassKey: RpcGeneratedRpcMethodClassKey,
370370
): List<FirPropertySymbol> {
371371
val valueParam = rpcMethodClassKey.rpcMethod.valueParameterSymbols.find {
372372
it.name == callableId.callableName

core/api/core.api

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@ public final class kotlinx/rpc/AwaitFieldInitializationKt {
33
public static final fun awaitFieldInitialization (Lkotlinx/rpc/RemoteService;Lkotlin/reflect/KClass;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
44
}
55

6-
public abstract interface class kotlinx/rpc/RPC : kotlinx/coroutines/CoroutineScope {
7-
}
8-
9-
public abstract interface annotation class kotlinx/rpc/RPCEagerField : java/lang/annotation/Annotation {
10-
}
11-
12-
public abstract interface class kotlinx/rpc/RPCServer : kotlinx/coroutines/CoroutineScope {
13-
public abstract fun registerService (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function1;)V
14-
}
15-
166
public final class kotlinx/rpc/RegisterFieldKt {
177
public static final fun registerPlainFlowField (Lkotlinx/rpc/RpcClient;Lkotlinx/coroutines/CoroutineScope;Lkotlinx/rpc/descriptor/RpcServiceDescriptor;Ljava/lang/String;J)Lkotlinx/coroutines/flow/Flow;
188
public static final fun registerSharedFlowField (Lkotlinx/rpc/RpcClient;Lkotlinx/coroutines/CoroutineScope;Lkotlinx/rpc/descriptor/RpcServiceDescriptor;Ljava/lang/String;J)Lkotlinx/coroutines/flow/SharedFlow;
@@ -45,7 +35,14 @@ public abstract interface class kotlinx/rpc/RpcClient : kotlinx/coroutines/Corou
4535
public abstract fun provideStubContext (J)Lkotlin/coroutines/CoroutineContext;
4636
}
4737

48-
public final class kotlinx/rpc/UninitializedRPCFieldException : java/lang/Exception {
38+
public abstract interface annotation class kotlinx/rpc/RpcEagerField : java/lang/annotation/Annotation {
39+
}
40+
41+
public abstract interface class kotlinx/rpc/RpcServer : kotlinx/coroutines/CoroutineScope {
42+
public abstract fun registerService (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function1;)V
43+
}
44+
45+
public final class kotlinx/rpc/UninitializedRpcFieldException : java/lang/Exception {
4946
public fun <init> (Ljava/lang/String;Lkotlin/reflect/KProperty;)V
5047
public fun getMessage ()Ljava/lang/String;
5148
}
@@ -87,7 +84,6 @@ public final class kotlinx/rpc/descriptor/RpcParameter {
8784
public abstract interface class kotlinx/rpc/descriptor/RpcServiceDescriptor {
8885
public abstract fun createInstance (JLkotlinx/rpc/RpcClient;)Lkotlinx/rpc/RemoteService;
8986
public abstract fun getCallable (Ljava/lang/String;)Lkotlinx/rpc/descriptor/RpcCallable;
90-
public abstract fun getFields (Lkotlinx/rpc/RemoteService;)Ljava/util/List;
9187
public abstract fun getFqName ()Ljava/lang/String;
9288
}
9389

core/src/commonMain/kotlin/kotlinx/rpc/RemoteService.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,3 @@ import kotlinx.rpc.annotations.Rpc
1616
* @see Rpc
1717
*/
1818
public interface RemoteService : CoroutineScope
19-
20-
@Deprecated(
21-
message = "Deprecated in favor of RemoteService. Will be removed in 0.5.0",
22-
replaceWith = ReplaceWith("RemoteService", "kotlinx.rpc.RemoteService"),
23-
level = DeprecationLevel.ERROR,
24-
)
25-
public interface RPC : CoroutineScope

core/src/commonMain/kotlin/kotlinx/rpc/RPCEagerField.kt renamed to core/src/commonMain/kotlin/kotlinx/rpc/RpcEagerField.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ package kotlinx.rpc
88
* The field marked with this annotation will be initialized with the service creation.
99
*/
1010
@Target(AnnotationTarget.PROPERTY)
11-
public annotation class RPCEagerField
11+
public annotation class RpcEagerField
12+
13+
@Deprecated("Use RpcEagerField instead", ReplaceWith("RpcEagerField"), level = DeprecationLevel.ERROR)
14+
public typealias RPCEagerField = RpcEagerField

0 commit comments

Comments
 (0)