-
Notifications
You must be signed in to change notification settings - Fork 43
Strict mode #243
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
Strict mode #243
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
071df9d
Added strict mode options to CLI and Gradle, and diagnostic declarations
Mr3zee 0f7fcbf
Added diagnostic implementations for strict mode
Mr3zee 1ed006e
Fixed compiler tests classpath
Mr3zee ba377da
Updated checker and added tests for strict mode
Mr3zee 386bbcc
Added minor checks for `@Rpc` services
Mr3zee 909f8a2
Added compiler tests for generic checks
Mr3zee 54cf575
updated box tests
Mr3zee 4c505d2
Added docs, changed defaults
Mr3zee cbdf468
PR comments
Mr3zee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/StrictMode.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| /* | ||
| * Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
| */ | ||
|
|
||
| package kotlinx.rpc.codegen | ||
|
|
||
| import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption | ||
| import org.jetbrains.kotlin.compiler.plugin.CliOption | ||
| import org.jetbrains.kotlin.config.CompilerConfiguration | ||
| import org.jetbrains.kotlin.config.CompilerConfigurationKey | ||
| import kotlin.text.lowercase | ||
|
|
||
| enum class StrictMode { | ||
| NONE, WARNING, ERROR; | ||
|
|
||
| companion object { | ||
| fun fromCli(value: String): StrictMode? { | ||
| return when (value.lowercase()) { | ||
| "none" -> NONE | ||
| "warning" -> WARNING | ||
| "error" -> ERROR | ||
| else -> null | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| data class StrictModeAggregator( | ||
| val stateFlow: StrictMode, | ||
| val sharedFlow: StrictMode, | ||
| val nestedFlow: StrictMode, | ||
| val streamScopedFunctions: StrictMode, | ||
| val suspendingServerStreaming: StrictMode, | ||
| val notTopLevelServerFlow: StrictMode, | ||
| val fields: StrictMode, | ||
| ) | ||
|
|
||
| object StrictModeConfigurationKeys { | ||
| val STATE_FLOW = CompilerConfigurationKey.create<StrictMode>("state flow rpc mode") | ||
| val SHARED_FLOW = CompilerConfigurationKey.create<StrictMode>("shared flow rpc mode") | ||
| val NESTED_FLOW = CompilerConfigurationKey.create<StrictMode>("nested flow rpc mode") | ||
| val STREAM_SCOPED_FUNCTIONS = CompilerConfigurationKey.create<StrictMode>("stream scoped rpc mode") | ||
| val SUSPENDING_SERVER_STREAMING = CompilerConfigurationKey.create<StrictMode>( | ||
| "suspending server streaming rpc mode" | ||
| ) | ||
| val NOT_TOP_LEVEL_SERVER_FLOW = CompilerConfigurationKey.create<StrictMode>("not top level server flow rpc mode") | ||
| val FIELDS = CompilerConfigurationKey.create<StrictMode>("fields rpc mode") | ||
| } | ||
|
|
||
| fun CompilerConfiguration.strictModeAggregator(): StrictModeAggregator { | ||
| return StrictModeAggregator( | ||
| stateFlow = get(StrictModeConfigurationKeys.STATE_FLOW, StrictMode.WARNING), | ||
| sharedFlow = get(StrictModeConfigurationKeys.SHARED_FLOW, StrictMode.WARNING), | ||
| nestedFlow = get(StrictModeConfigurationKeys.NESTED_FLOW, StrictMode.WARNING), | ||
| streamScopedFunctions = get(StrictModeConfigurationKeys.STREAM_SCOPED_FUNCTIONS, StrictMode.NONE), | ||
| suspendingServerStreaming = get(StrictModeConfigurationKeys.SUSPENDING_SERVER_STREAMING, StrictMode.NONE), | ||
| notTopLevelServerFlow = get(StrictModeConfigurationKeys.NOT_TOP_LEVEL_SERVER_FLOW, StrictMode.WARNING), | ||
| fields = get(StrictModeConfigurationKeys.FIELDS, StrictMode.WARNING), | ||
| ) | ||
| } | ||
|
|
||
| object StrictModeCliOptions { | ||
| val STATE_FLOW = CliOption( | ||
| optionName = "strict-stateFlow", | ||
| valueDescription = VALUE_DESCRIPTION, | ||
| description = description("StateFlow"), | ||
| required = false, | ||
| allowMultipleOccurrences = false, | ||
| ) | ||
|
|
||
| val SHARED_FLOW = CliOption( | ||
| optionName = "strict-sharedFlow", | ||
| valueDescription = VALUE_DESCRIPTION, | ||
| description = description("SharedFlow"), | ||
| required = false, | ||
| allowMultipleOccurrences = false, | ||
| ) | ||
|
|
||
| val NESTED_FLOW = CliOption( | ||
| optionName = "strict-nested-flow", | ||
| valueDescription = VALUE_DESCRIPTION, | ||
| description = description("Nested flows"), | ||
| required = false, | ||
| allowMultipleOccurrences = false, | ||
| ) | ||
|
|
||
| val STREAM_SCOPED_FUNCTIONS = CliOption( | ||
| optionName = "strict-stream-scope", | ||
| valueDescription = VALUE_DESCRIPTION, | ||
| description = description("Stream Scopes"), | ||
| required = false, | ||
| allowMultipleOccurrences = false, | ||
| ) | ||
|
|
||
| val SUSPENDING_SERVER_STREAMING = CliOption( | ||
| optionName = "strict-suspending-server-streaming", | ||
| valueDescription = VALUE_DESCRIPTION, | ||
| description = description("suspending server streaming methods"), | ||
| required = false, | ||
| allowMultipleOccurrences = false, | ||
| ) | ||
|
|
||
| val NOT_TOP_LEVEL_SERVER_FLOW = CliOption( | ||
| optionName = "strict-not-top-level-server-flow", | ||
| valueDescription = VALUE_DESCRIPTION, | ||
| description = description("not top-level server streaming declarations"), | ||
| required = false, | ||
| allowMultipleOccurrences = false, | ||
| ) | ||
|
|
||
| val FIELDS = CliOption( | ||
| optionName = "strict-fields", | ||
| valueDescription = VALUE_DESCRIPTION, | ||
| description = description("fields"), | ||
| required = false, | ||
| allowMultipleOccurrences = false, | ||
| ) | ||
|
|
||
| const val VALUE_DESCRIPTION = "none, warning or error" | ||
|
|
||
| fun description(entity: String): String { | ||
| return "Diagnostic level for $entity in @Rpc services." | ||
| } | ||
|
|
||
| val configurationMapper = mapOf( | ||
| STATE_FLOW to StrictModeConfigurationKeys.STATE_FLOW, | ||
| SHARED_FLOW to StrictModeConfigurationKeys.SHARED_FLOW, | ||
| NESTED_FLOW to StrictModeConfigurationKeys.NESTED_FLOW, | ||
| STREAM_SCOPED_FUNCTIONS to StrictModeConfigurationKeys.STREAM_SCOPED_FUNCTIONS, | ||
| SUSPENDING_SERVER_STREAMING to StrictModeConfigurationKeys.SUSPENDING_SERVER_STREAMING, | ||
| NOT_TOP_LEVEL_SERVER_FLOW to StrictModeConfigurationKeys.NOT_TOP_LEVEL_SERVER_FLOW, | ||
| FIELDS to StrictModeConfigurationKeys.FIELDS, | ||
| ) | ||
| } | ||
|
|
||
| fun AbstractCliOption.processAsStrictModeOption(value: String, configuration: CompilerConfiguration): Boolean { | ||
| val key = StrictModeCliOptions.configurationMapper[this] ?: return false | ||
| val mode = StrictMode.fromCli(value) ?: return false | ||
|
|
||
| configuration.put(key, mode) | ||
| return true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reason for the shadow jar