Skip to content

Commit 700fad1

Browse files
authored
Fix kotlin master builds (#345)
1 parent d13fe18 commit 700fad1

File tree

26 files changed

+531
-34
lines changed

26 files changed

+531
-34
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ package kotlinx.rpc.codegen
66

77
import org.jetbrains.kotlin.KtSourceElement
88
import org.jetbrains.kotlin.fir.FirSession
9-
import org.jetbrains.kotlin.fir.declarations.FirFunction
109
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
11-
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
1210
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
1311
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
1412
import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol
1513
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
16-
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
1714
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
1815
import org.jetbrains.kotlin.fir.types.ConeKotlinType
1916
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef

compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/diagnostics/FirRpcDiagnostics.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.diagnostics.error0
1212
import org.jetbrains.kotlin.diagnostics.error1
1313
import org.jetbrains.kotlin.diagnostics.error2
1414
import org.jetbrains.kotlin.diagnostics.error3
15-
import org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory
15+
import org.jetbrains.kotlin.diagnostics.rendering.BaseDiagnosticRendererFactory
1616
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
1717
import org.jetbrains.kotlin.fir.types.ConeKotlinType
1818
import org.jetbrains.kotlin.name.Name
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.psi.KtElement
2525
// # Instead use KtElement, otherwise problems in IDE and in tests may arise #
2626
// ###########################################################################
2727

28-
object FirRpcDiagnostics {
28+
object FirRpcDiagnostics : RpcKtDiagnosticsContainer() {
2929
val MISSING_RPC_ANNOTATION by error0<KtAnnotated>()
3030
val MISSING_SERIALIZATION_MODULE by error0<KtAnnotated>()
3131
val WRONG_RPC_ANNOTATION_TARGET by error1<KtAnnotated, ConeKotlinType>()
@@ -35,13 +35,13 @@ object FirRpcDiagnostics {
3535
val TYPE_PARAMETERS_IN_RPC_FUNCTION by error0<KtElement>(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST)
3636
val TYPE_PARAMETERS_IN_RPC_INTERFACE by error0<KtElement>(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST)
3737

38-
init {
39-
RootDiagnosticRendererFactory.registerFactory(RpcDiagnosticRendererFactory)
38+
override fun getRendererFactoryVs(): BaseDiagnosticRendererFactory {
39+
return RpcDiagnosticRendererFactory
4040
}
4141
}
4242

4343
@Suppress("PropertyName", "detekt.VariableNaming")
44-
class FirRpcStrictModeDiagnostics(val modes: StrictModeAggregator) {
44+
class FirRpcStrictModeDiagnostics(val modes: StrictModeAggregator) : RpcKtDiagnosticsContainer() {
4545
val STATE_FLOW_IN_RPC_SERVICE by modded0<KtElement>(modes.stateFlow)
4646
val SHARED_FLOW_IN_RPC_SERVICE by modded0<KtElement>(modes.sharedFlow)
4747
val NESTED_STREAMING_IN_RPC_SERVICE by modded0<KtElement>(modes.nestedFlow)
@@ -50,7 +50,7 @@ class FirRpcStrictModeDiagnostics(val modes: StrictModeAggregator) {
5050
val NON_TOP_LEVEL_SERVER_STREAMING_IN_RPC_SERVICE by modded0<KtElement>(modes.notTopLevelServerFlow)
5151
val FIELD_IN_RPC_SERVICE by modded0<KtElement>(modes.fields)
5252

53-
init {
54-
RootDiagnosticRendererFactory.registerFactory(RpcStrictModeDiagnosticRendererFactory(this))
53+
override fun getRendererFactoryVs(): BaseDiagnosticRendererFactory {
54+
return RpcStrictModeDiagnosticRendererFactory(this)
5555
}
5656
}

compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/diagnostics/RpcDiagnosticRendererFactory.kt

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,33 @@ package kotlinx.rpc.codegen.checkers.diagnostics
66

77
import kotlinx.rpc.codegen.StrictMode
88
import kotlinx.rpc.codegen.StrictModeAggregator
9-
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap
109
import org.jetbrains.kotlin.diagnostics.rendering.BaseDiagnosticRendererFactory
1110
import org.jetbrains.kotlin.diagnostics.rendering.Renderer
1211
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers
1312

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

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

30-
put(
29+
map.put(
3130
factory = FirRpcDiagnostics.WRONG_RPC_ANNOTATION_TARGET,
3231
message = "@{0} annotation is only applicable to interfaces and annotation classes.",
3332
rendererA = FirDiagnosticRenderers.RENDER_TYPE,
3433
)
3534

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

46-
put(
45+
map.put(
4746
factory = FirRpcDiagnostics.NON_SUSPENDING_REQUEST_WITHOUT_STREAMING_RETURN_TYPE,
4847
message = "Non suspending request function is not allowed for functions that doesn't return Flow.",
4948
)
5049

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

58-
put(
57+
map.put(
5958
factory = FirRpcDiagnostics.TYPE_PARAMETERS_IN_RPC_FUNCTION,
6059
message = "Type parameters are not allowed in Rpc functions.",
6160
)
6261

63-
put(
62+
map.put(
6463
factory = FirRpcDiagnostics.TYPE_PARAMETERS_IN_RPC_INTERFACE,
6564
message = "Type parameters are not allowed in @Rpc interfaces.",
6665
)
@@ -82,51 +81,51 @@ private fun Int.indexPositionSpelled(): String {
8281
class RpcStrictModeDiagnosticRendererFactory(
8382
private val diagnostics: FirRpcStrictModeDiagnostics,
8483
) : BaseDiagnosticRendererFactory() {
85-
override val MAP = KtDiagnosticFactoryToRendererMap("Rpc").apply {
84+
override val MAP by RpcKtDiagnosticFactoryToRendererMap("RpcStrictMode") { map ->
8685
diagnostics.STATE_FLOW_IN_RPC_SERVICE?.let {
87-
put(
86+
map.put(
8887
factory = it,
8988
message = message("StateFlow") { stateFlow },
9089
)
9190
}
9291

9392
diagnostics.SHARED_FLOW_IN_RPC_SERVICE?.let {
94-
put(
93+
map.put(
9594
factory = it,
9695
message = message("SharedFlow") { sharedFlow },
9796
)
9897
}
9998

10099
diagnostics.NESTED_STREAMING_IN_RPC_SERVICE?.let {
101-
put(
100+
map.put(
102101
factory = it,
103102
message = message("Nested streaming") { nestedFlow },
104103
)
105104
}
106105

107106
diagnostics.STREAM_SCOPE_FUNCTION_IN_RPC?.let {
108-
put(
107+
map.put(
109108
factory = it,
110109
message = message("Stream scope usage") { streamScopedFunctions },
111110
)
112111
}
113112

114113
diagnostics.SUSPENDING_SERVER_STREAMING_IN_RPC_SERVICE?.let {
115-
put(
114+
map.put(
116115
factory = it,
117116
message = message("Suspend function declaration with server streaming") { suspendingServerStreaming },
118117
)
119118
}
120119

121120
diagnostics.NON_TOP_LEVEL_SERVER_STREAMING_IN_RPC_SERVICE?.let {
122-
put(
121+
map.put(
123122
factory = it,
124123
message = message("Not top-level server-side streaming") { sharedFlow },
125124
)
126125
}
127126

128127
diagnostics.FIELD_IN_RPC_SERVICE?.let {
129-
put(
128+
map.put(
130129
factory = it,
131130
message = message("Field declaration") { fields },
132131
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.rpc.codegen.checkers.diagnostics
6+
7+
import org.jetbrains.kotlin.diagnostics.rendering.BaseDiagnosticRendererFactory
8+
9+
interface RpcKtDiagnosticsContainerCore {
10+
fun getRendererFactoryVs() : BaseDiagnosticRendererFactory
11+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
@file:Suppress("unused")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.rpc.codegen.checkers.diagnostics
6+
7+
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap
8+
9+
fun RpcKtDiagnosticFactoryToRendererMap(
10+
name: String,
11+
init: (KtDiagnosticFactoryToRendererMap) -> Unit,
12+
): Lazy<KtDiagnosticFactoryToRendererMap> {
13+
return lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
14+
KtDiagnosticFactoryToRendererMap(name).also(init)
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.rpc.codegen.checkers.diagnostics
6+
7+
abstract class RpcKtDiagnosticsContainer : RpcKtDiagnosticsContainerCore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
@file:Suppress("unused")
6+
7+
package kotlinx.rpc.codegen.checkers.diagnostics
8+
9+
import kotlinx.rpc.codegen.StrictMode
10+
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactory0
11+
import org.jetbrains.kotlin.diagnostics.Severity
12+
import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies
13+
import org.jetbrains.kotlin.utils.DummyDelegate
14+
import kotlin.properties.ReadOnlyProperty
15+
import kotlin.reflect.KClass
16+
import kotlin.reflect.KProperty
17+
18+
inline fun <reified T> modded0(mode: StrictMode): DiagnosticFactory0DelegateProviderOnNull {
19+
return DiagnosticFactory0DelegateProviderOnNull(mode, T::class)
20+
}
21+
22+
class DiagnosticFactory0DelegateProviderOnNull(
23+
private val mode: StrictMode,
24+
private val psiType: KClass<*>,
25+
) {
26+
operator fun provideDelegate(
27+
@Suppress("unused")
28+
thisRef: Any?,
29+
prop: KProperty<*>,
30+
): ReadOnlyProperty<Any?, KtDiagnosticFactory0?> {
31+
val severity = when (mode) {
32+
StrictMode.ERROR -> Severity.ERROR
33+
StrictMode.WARNING -> Severity.WARNING
34+
StrictMode.NONE -> null
35+
} ?: return DummyDelegate(null)
36+
37+
return DummyDelegate(
38+
KtDiagnosticFactory0(
39+
name = prop.name,
40+
severity = severity,
41+
defaultPositioningStrategy = SourceElementPositioningStrategies.DEFAULT,
42+
psiType = psiType,
43+
),
44+
)
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.rpc.codegen.checkers.diagnostics
6+
7+
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap
8+
9+
fun RpcKtDiagnosticFactoryToRendererMap(
10+
name: String,
11+
init: (KtDiagnosticFactoryToRendererMap) -> Unit,
12+
): Lazy<KtDiagnosticFactoryToRendererMap> {
13+
return lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
14+
KtDiagnosticFactoryToRendererMap(name).also(init)
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.rpc.codegen.checkers.diagnostics
6+
7+
abstract class RpcKtDiagnosticsContainer : RpcKtDiagnosticsContainerCore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
@file:Suppress("unused")
6+
7+
package kotlinx.rpc.codegen.checkers.diagnostics
8+
9+
import kotlinx.rpc.codegen.StrictMode
10+
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactory0
11+
import org.jetbrains.kotlin.diagnostics.Severity
12+
import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies
13+
import org.jetbrains.kotlin.utils.DummyDelegate
14+
import kotlin.properties.ReadOnlyProperty
15+
import kotlin.reflect.KClass
16+
import kotlin.reflect.KProperty
17+
18+
inline fun <reified T> modded0(mode: StrictMode): DiagnosticFactory0DelegateProviderOnNull {
19+
return DiagnosticFactory0DelegateProviderOnNull(mode, T::class)
20+
}
21+
22+
class DiagnosticFactory0DelegateProviderOnNull(
23+
private val mode: StrictMode,
24+
private val psiType: KClass<*>,
25+
) {
26+
operator fun provideDelegate(
27+
@Suppress("unused")
28+
thisRef: Any?,
29+
prop: KProperty<*>,
30+
): ReadOnlyProperty<Any?, KtDiagnosticFactory0?> {
31+
val severity = when (mode) {
32+
StrictMode.ERROR -> Severity.ERROR
33+
StrictMode.WARNING -> Severity.WARNING
34+
StrictMode.NONE -> null
35+
} ?: return DummyDelegate(null)
36+
37+
return DummyDelegate(
38+
KtDiagnosticFactory0(
39+
name = prop.name,
40+
severity = severity,
41+
defaultPositioningStrategy = SourceElementPositioningStrategies.DEFAULT,
42+
psiType = psiType,
43+
),
44+
)
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.rpc.codegen.checkers.diagnostics
6+
7+
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap
8+
9+
fun RpcKtDiagnosticFactoryToRendererMap(
10+
name: String,
11+
init: (KtDiagnosticFactoryToRendererMap) -> Unit,
12+
): Lazy<KtDiagnosticFactoryToRendererMap> {
13+
return lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
14+
KtDiagnosticFactoryToRendererMap(name).also(init)
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.rpc.codegen.checkers.diagnostics
6+
7+
abstract class RpcKtDiagnosticsContainer : RpcKtDiagnosticsContainerCore

compiler-plugin/compiler-plugin-k2/src/main/v_2_2/kotlinx/rpc/codegen/FirVersionSpecificApiImpl.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.fir.types.ConeKotlinType
1515
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
1616
import org.jetbrains.kotlin.fir.types.FirTypeRef
1717
import org.jetbrains.kotlin.fir.types.builder.FirResolvedTypeRefBuilder
18-
import org.jetbrains.kotlin.fir.declarations.FirFunction
1918
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
2019
import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol
2120
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol

0 commit comments

Comments
 (0)