Skip to content

Commit 8e56647

Browse files
committed
Rename RustCodegenServerPlugin to RustServerCodegenPlugin
For consistency with `RustClientCodegenPlugin`. This is a better name, since the plugin is named `rust-server-codegen`. This commit also contains other drive-by improvements made while working on #2302.
1 parent 7bf9251 commit 8e56647

File tree

12 files changed

+31
-35
lines changed

12 files changed

+31
-35
lines changed

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ class RustClientCodegenPlugin : DecoratableBuildPlugin() {
6666
}
6767

6868
companion object {
69-
/** SymbolProvider
69+
/**
7070
* When generating code, smithy types need to be converted into Rust types—that is the core role of the symbol provider
7171
*
72-
* The Symbol provider is composed of a base `SymbolVisitor` which handles the core functionality, then is layered
72+
* The Symbol provider is composed of a base [SymbolVisitor] which handles the core functionality, then is layered
7373
* with other symbol providers, documented inline, to handle the full scope of Smithy types.
7474
*/
7575
fun baseSymbolProvider(model: Model, serviceShape: ServiceShape, symbolVisitorConfig: SymbolVisitorConfig) =

codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ class RustWriter private constructor(
481481
* Callers must take care to use [this] when writing to ensure code is written to the right place:
482482
* ```kotlin
483483
* val writer = RustWriter.forModule("model")
484-
* writer.withModule(RustModule.public("nested")) {
484+
* writer.withInlineModule(RustModule.public("nested")) {
485485
* Generator(...).render(this) // GOOD
486486
* Generator(...).render(writer) // WRONG!
487487
* }

codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/DirectedWalker.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@ import java.util.function.Predicate
1919
class DirectedWalker(model: Model) {
2020
private val inner = Walker(model)
2121

22-
fun walkShapes(shape: Shape): Set<Shape> {
23-
return walkShapes(shape) { _ -> true }
24-
}
22+
fun walkShapes(shape: Shape): Set<Shape> = walkShapes(shape) { true }
2523

26-
fun walkShapes(shape: Shape, predicate: Predicate<Relationship>): Set<Shape> {
27-
return inner.walkShapes(shape) { rel -> predicate.test(rel) && rel.direction == RelationshipDirection.DIRECTED }
28-
}
24+
fun walkShapes(shape: Shape, predicate: Predicate<Relationship>): Set<Shape> =
25+
inner.walkShapes(shape) { rel -> predicate.test(rel) && rel.direction == RelationshipDirection.DIRECTED }
2926
}

codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ fun generatePluginContext(
190190
)
191191
}
192192

193-
val settings = settingsBuilder.merge(additionalSettings)
194-
.build()
193+
val settings = settingsBuilder.merge(additionalSettings).build()
195194
val pluginContext = PluginContext.builder().model(model).fileManifest(manifest).settings(settings).build()
196195
return pluginContext to testPath
197196
}
Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,30 @@ import java.util.logging.Logger
3030
* `resources/META-INF.services/software.amazon.smithy.build.SmithyBuildPlugin` refers to this class by name which
3131
* enables the smithy-build plugin to invoke `execute` with all Smithy plugin context + models.
3232
*/
33-
class RustCodegenServerPlugin : SmithyBuildPlugin {
33+
class RustServerCodegenPlugin : SmithyBuildPlugin {
3434
private val logger = Logger.getLogger(javaClass.name)
3535

3636
override fun getName(): String = "rust-server-codegen"
3737

38-
override fun execute(context: PluginContext) {
39-
// Suppress extremely noisy logs about reserved words
38+
/**
39+
* See [software.amazon.smithy.rust.codegen.client.smithy.RustClientCodegenPlugin].
40+
*/
41+
override fun execute(
42+
context: PluginContext,
43+
) {
4044
Logger.getLogger(ReservedWordSymbolProvider::class.java.name).level = Level.OFF
41-
// Discover [RustCodegenDecorators] on the classpath. [RustCodegenDecorator] returns different types of
42-
// customizations. A customization is a function of:
43-
// - location (e.g. the mutate section of an operation)
44-
// - context (e.g. the of the operation)
45-
// - writer: The active RustWriter at the given location
46-
val codegenDecorator: CombinedServerCodegenDecorator =
47-
CombinedServerCodegenDecorator.fromClasspath(context, ServerRequiredCustomizations())
48-
49-
// ServerCodegenVisitor is the main driver of code generation that traverses the model and generates code
45+
val codegenDecorator =
46+
CombinedServerCodegenDecorator.fromClasspath(
47+
context,
48+
ServerRequiredCustomizations(),
49+
)
5050
logger.info("Loaded plugin to generate pure Rust bindings for the server SDK")
5151
ServerCodegenVisitor(context, codegenDecorator).execute()
5252
}
5353

5454
companion object {
5555
/**
56-
* When generating code, smithy types need to be converted into Rust types—that is the core role of the symbol provider.
57-
*
58-
* The Symbol provider is composed of a base [SymbolVisitor] which handles the core functionality, then is layered
59-
* with other symbol providers, documented inline, to handle the full scope of Smithy types.
56+
* See [software.amazon.smithy.rust.codegen.client.smithy.RustClientCodegenPlugin].
6057
*/
6158
fun baseSymbolProvider(
6259
model: Model,

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenContext.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget
1313
import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider
1414

1515
/**
16-
* [ServerCodegenContext] contains code-generation context that is _specific_ to the [RustCodegenServerPlugin] plugin
16+
* [ServerCodegenContext] contains code-generation context that is _specific_ to the [RustServerCodegenPlugin] plugin
1717
* from the `rust-codegen-server` subproject.
1818
*
1919
* It inherits from [CodegenContext], which contains code-generation context that is common to _all_ smithy-rs plugins.

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ open class ServerCodegenVisitor(
129129
service,
130130
symbolVisitorConfig,
131131
settings.codegenConfig.publicConstrainedTypes,
132-
RustCodegenServerPlugin::baseSymbolProvider,
132+
RustServerCodegenPlugin::baseSymbolProvider,
133133
)
134134

135135
codegenContext = ServerCodegenContext(

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRustSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import java.util.Optional
2525
*/
2626

2727
/**
28-
* Settings used by [RustCodegenServerPlugin].
28+
* Settings used by [RustServerCodegenPlugin].
2929
*/
3030
data class ServerRustSettings(
3131
override val service: ShapeId,

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ValidateUnsupportedConstraints.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ data class ValidationResult(val shouldAbort: Boolean, val messages: List<LogMess
134134

135135
private val unsupportedConstraintsOnMemberShapes = allConstraintTraits - RequiredTrait::class.java
136136

137+
/**
138+
* Validate that all constrained operations have the shape [validationExceptionShapeId] shape attached to their errors.
139+
*/
137140
fun validateOperationsWithConstrainedInputHaveValidationExceptionAttached(
138141
model: Model,
139142
service: ServiceShape,

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customize/ServerCodegenDecorator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ interface ServerCodegenDecorator : CoreCodegenDecorator<ServerCodegenContext> {
2828
*
2929
* This makes the actual concrete codegen simpler by not needing to deal with multiple separate decorators.
3030
*/
31-
class CombinedServerCodegenDecorator(decorators: List<ServerCodegenDecorator>) :
31+
class CombinedServerCodegenDecorator(private val decorators: List<ServerCodegenDecorator>) :
3232
CombinedCoreCodegenDecorator<ServerCodegenContext, ServerCodegenDecorator>(decorators),
3333
ServerCodegenDecorator {
3434
override val name: String

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig
1919
import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator
2020
import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock
2121
import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig
22-
import software.amazon.smithy.rust.codegen.server.smithy.RustCodegenServerPlugin
22+
import software.amazon.smithy.rust.codegen.server.smithy.RustServerCodegenPlugin
2323
import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenConfig
2424
import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext
2525
import software.amazon.smithy.rust.codegen.server.smithy.ServerRustSettings
@@ -53,7 +53,7 @@ fun serverTestSymbolProviders(
5353
(serviceShape ?: testServiceShapeFor(model)).id,
5454
)
5555
).codegenConfig.publicConstrainedTypes,
56-
RustCodegenServerPlugin::baseSymbolProvider,
56+
RustServerCodegenPlugin::baseSymbolProvider,
5757
)
5858

5959
fun serverTestRustSettings(
@@ -98,7 +98,7 @@ fun serverTestCodegenContext(
9898
service,
9999
ServerTestSymbolVisitorConfig,
100100
settings.codegenConfig.publicConstrainedTypes,
101-
RustCodegenServerPlugin::baseSymbolProvider,
101+
RustServerCodegenPlugin::baseSymbolProvider,
102102
)
103103

104104
return ServerCodegenContext(

codegen-server/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
# SPDX-License-Identifier: Apache-2.0
44
#
5-
software.amazon.smithy.rust.codegen.server.smithy.RustCodegenServerPlugin
5+
software.amazon.smithy.rust.codegen.server.smithy.RustServerCodegenPlugin

0 commit comments

Comments
 (0)