Skip to content

Fix kotlin master builds #345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ package kotlinx.rpc.codegen

import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirFunction
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.jetbrains.kotlin.diagnostics.error0
import org.jetbrains.kotlin.diagnostics.error1
import org.jetbrains.kotlin.diagnostics.error2
import org.jetbrains.kotlin.diagnostics.error3
import org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory
import org.jetbrains.kotlin.diagnostics.rendering.BaseDiagnosticRendererFactory
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.name.Name
Expand All @@ -25,7 +25,7 @@ import org.jetbrains.kotlin.psi.KtElement
// # Instead use KtElement, otherwise problems in IDE and in tests may arise #
// ###########################################################################

object FirRpcDiagnostics {
object FirRpcDiagnostics : RpcKtDiagnosticsContainer() {
val MISSING_RPC_ANNOTATION by error0<KtAnnotated>()
val MISSING_SERIALIZATION_MODULE by error0<KtAnnotated>()
val WRONG_RPC_ANNOTATION_TARGET by error1<KtAnnotated, ConeKotlinType>()
Expand All @@ -35,13 +35,13 @@ object FirRpcDiagnostics {
val TYPE_PARAMETERS_IN_RPC_FUNCTION by error0<KtElement>(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST)
val TYPE_PARAMETERS_IN_RPC_INTERFACE by error0<KtElement>(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST)

init {
RootDiagnosticRendererFactory.registerFactory(RpcDiagnosticRendererFactory)
override fun getRendererFactoryVs(): BaseDiagnosticRendererFactory {
Copy link
Preview

Copilot AI Jun 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding a comment to explain the transition from using an init block for factory registration to the overridden getRendererFactoryVs() approach to aid future maintainers.

Copilot uses AI. Check for mistakes.

return RpcDiagnosticRendererFactory
}
}

@Suppress("PropertyName", "detekt.VariableNaming")
class FirRpcStrictModeDiagnostics(val modes: StrictModeAggregator) {
class FirRpcStrictModeDiagnostics(val modes: StrictModeAggregator) : RpcKtDiagnosticsContainer() {
val STATE_FLOW_IN_RPC_SERVICE by modded0<KtElement>(modes.stateFlow)
val SHARED_FLOW_IN_RPC_SERVICE by modded0<KtElement>(modes.sharedFlow)
val NESTED_STREAMING_IN_RPC_SERVICE by modded0<KtElement>(modes.nestedFlow)
Expand All @@ -50,7 +50,7 @@ class FirRpcStrictModeDiagnostics(val modes: StrictModeAggregator) {
val NON_TOP_LEVEL_SERVER_STREAMING_IN_RPC_SERVICE by modded0<KtElement>(modes.notTopLevelServerFlow)
val FIELD_IN_RPC_SERVICE by modded0<KtElement>(modes.fields)

init {
RootDiagnosticRendererFactory.registerFactory(RpcStrictModeDiagnosticRendererFactory(this))
override fun getRendererFactoryVs(): BaseDiagnosticRendererFactory {
return RpcStrictModeDiagnosticRendererFactory(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,33 @@ package kotlinx.rpc.codegen.checkers.diagnostics

import kotlinx.rpc.codegen.StrictMode
import kotlinx.rpc.codegen.StrictModeAggregator
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap
import org.jetbrains.kotlin.diagnostics.rendering.BaseDiagnosticRendererFactory
import org.jetbrains.kotlin.diagnostics.rendering.Renderer
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers

object RpcDiagnosticRendererFactory : BaseDiagnosticRendererFactory() {
override val MAP = KtDiagnosticFactoryToRendererMap("Rpc").apply {
put(
override val MAP by RpcKtDiagnosticFactoryToRendererMap("Rpc") { map ->
map.put(
factory = FirRpcDiagnostics.MISSING_RPC_ANNOTATION,
message = "Missing @Rpc annotation. " +
"All services children of kotlinx.rpc.RemoteService " +
"must be annotated with kotlinx.rpc.annotations.Rpc",
)

put(
map.put(
factory = FirRpcDiagnostics.MISSING_SERIALIZATION_MODULE,
message = "Missing kotlinx.serialization plugin in the module. " +
"Service generation will not be available. " +
"Add kotlin(\"plugin.serialization\") to your build.gradle.kts plugins section."
)

put(
map.put(
factory = FirRpcDiagnostics.WRONG_RPC_ANNOTATION_TARGET,
message = "@{0} annotation is only applicable to interfaces and annotation classes.",
rendererA = FirDiagnosticRenderers.RENDER_TYPE,
)

put(
map.put(
factory = FirRpcDiagnostics.CHECKED_ANNOTATION_VIOLATION,
message = "{0} type argument is marked with @{1} annotation, but inferred type is {2}. " +
"Provide a type that is marked with @{1} annotation explicitly " +
Expand All @@ -43,24 +42,24 @@ object RpcDiagnosticRendererFactory : BaseDiagnosticRendererFactory() {
rendererC = FirDiagnosticRenderers.SYMBOL,
)

put(
map.put(
factory = FirRpcDiagnostics.NON_SUSPENDING_REQUEST_WITHOUT_STREAMING_RETURN_TYPE,
message = "Non suspending request function is not allowed for functions that doesn't return Flow.",
)

put(
map.put(
factory = FirRpcDiagnostics.AD_HOC_POLYMORPHISM_IN_RPC_SERVICE,
message = "Ad-hoc polymorphism is not allowed in @Rpc services. Found {0} '{1}' functions.",
rendererA = Renderer { it.toString() },
rendererB = Renderer { it.asString() },
)

put(
map.put(
factory = FirRpcDiagnostics.TYPE_PARAMETERS_IN_RPC_FUNCTION,
message = "Type parameters are not allowed in Rpc functions.",
)

put(
map.put(
factory = FirRpcDiagnostics.TYPE_PARAMETERS_IN_RPC_INTERFACE,
message = "Type parameters are not allowed in @Rpc interfaces.",
)
Expand All @@ -82,51 +81,51 @@ private fun Int.indexPositionSpelled(): String {
class RpcStrictModeDiagnosticRendererFactory(
private val diagnostics: FirRpcStrictModeDiagnostics,
) : BaseDiagnosticRendererFactory() {
override val MAP = KtDiagnosticFactoryToRendererMap("Rpc").apply {
override val MAP by RpcKtDiagnosticFactoryToRendererMap("RpcStrictMode") { map ->
diagnostics.STATE_FLOW_IN_RPC_SERVICE?.let {
put(
map.put(
factory = it,
message = message("StateFlow") { stateFlow },
)
}

diagnostics.SHARED_FLOW_IN_RPC_SERVICE?.let {
put(
map.put(
factory = it,
message = message("SharedFlow") { sharedFlow },
)
}

diagnostics.NESTED_STREAMING_IN_RPC_SERVICE?.let {
put(
map.put(
factory = it,
message = message("Nested streaming") { nestedFlow },
)
}

diagnostics.STREAM_SCOPE_FUNCTION_IN_RPC?.let {
put(
map.put(
factory = it,
message = message("Stream scope usage") { streamScopedFunctions },
)
}

diagnostics.SUSPENDING_SERVER_STREAMING_IN_RPC_SERVICE?.let {
put(
map.put(
factory = it,
message = message("Suspend function declaration with server streaming") { suspendingServerStreaming },
)
}

diagnostics.NON_TOP_LEVEL_SERVER_STREAMING_IN_RPC_SERVICE?.let {
put(
map.put(
factory = it,
message = message("Not top-level server-side streaming") { sharedFlow },
)
}

diagnostics.FIELD_IN_RPC_SERVICE?.let {
put(
map.put(
factory = it,
message = message("Field declaration") { fields },
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.codegen.checkers.diagnostics

import org.jetbrains.kotlin.diagnostics.rendering.BaseDiagnosticRendererFactory

interface RpcKtDiagnosticsContainerCore {
fun getRendererFactoryVs() : BaseDiagnosticRendererFactory
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("unused")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.codegen.checkers.diagnostics

import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap

fun RpcKtDiagnosticFactoryToRendererMap(
name: String,
init: (KtDiagnosticFactoryToRendererMap) -> Unit,
): Lazy<KtDiagnosticFactoryToRendererMap> {
return lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
KtDiagnosticFactoryToRendererMap(name).also(init)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.codegen.checkers.diagnostics

abstract class RpcKtDiagnosticsContainer : RpcKtDiagnosticsContainerCore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("unused")

package kotlinx.rpc.codegen.checkers.diagnostics

import kotlinx.rpc.codegen.StrictMode
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactory0
import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies
import org.jetbrains.kotlin.utils.DummyDelegate
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KClass
import kotlin.reflect.KProperty

inline fun <reified T> modded0(mode: StrictMode): DiagnosticFactory0DelegateProviderOnNull {
return DiagnosticFactory0DelegateProviderOnNull(mode, T::class)
}

class DiagnosticFactory0DelegateProviderOnNull(
private val mode: StrictMode,
private val psiType: KClass<*>,
) {
operator fun provideDelegate(
@Suppress("unused")
thisRef: Any?,
prop: KProperty<*>,
): ReadOnlyProperty<Any?, KtDiagnosticFactory0?> {
val severity = when (mode) {
StrictMode.ERROR -> Severity.ERROR
StrictMode.WARNING -> Severity.WARNING
StrictMode.NONE -> null
} ?: return DummyDelegate(null)

return DummyDelegate(
KtDiagnosticFactory0(
name = prop.name,
severity = severity,
defaultPositioningStrategy = SourceElementPositioningStrategies.DEFAULT,
psiType = psiType,
),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.codegen.checkers.diagnostics

import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap

fun RpcKtDiagnosticFactoryToRendererMap(
name: String,
init: (KtDiagnosticFactoryToRendererMap) -> Unit,
): Lazy<KtDiagnosticFactoryToRendererMap> {
return lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
KtDiagnosticFactoryToRendererMap(name).also(init)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.codegen.checkers.diagnostics

abstract class RpcKtDiagnosticsContainer : RpcKtDiagnosticsContainerCore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("unused")

package kotlinx.rpc.codegen.checkers.diagnostics

import kotlinx.rpc.codegen.StrictMode
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactory0
import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies
import org.jetbrains.kotlin.utils.DummyDelegate
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KClass
import kotlin.reflect.KProperty

inline fun <reified T> modded0(mode: StrictMode): DiagnosticFactory0DelegateProviderOnNull {
return DiagnosticFactory0DelegateProviderOnNull(mode, T::class)
}

class DiagnosticFactory0DelegateProviderOnNull(
private val mode: StrictMode,
private val psiType: KClass<*>,
) {
operator fun provideDelegate(
@Suppress("unused")
thisRef: Any?,
prop: KProperty<*>,
): ReadOnlyProperty<Any?, KtDiagnosticFactory0?> {
val severity = when (mode) {
StrictMode.ERROR -> Severity.ERROR
StrictMode.WARNING -> Severity.WARNING
StrictMode.NONE -> null
} ?: return DummyDelegate(null)

return DummyDelegate(
KtDiagnosticFactory0(
name = prop.name,
severity = severity,
defaultPositioningStrategy = SourceElementPositioningStrategies.DEFAULT,
psiType = psiType,
),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.codegen.checkers.diagnostics

import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap

fun RpcKtDiagnosticFactoryToRendererMap(
name: String,
init: (KtDiagnosticFactoryToRendererMap) -> Unit,
): Lazy<KtDiagnosticFactoryToRendererMap> {
return lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
KtDiagnosticFactoryToRendererMap(name).also(init)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.codegen.checkers.diagnostics

abstract class RpcKtDiagnosticsContainer : RpcKtDiagnosticsContainerCore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.types.builder.FirResolvedTypeRefBuilder
import org.jetbrains.kotlin.fir.declarations.FirFunction
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
Expand Down
Loading