-
Notifications
You must be signed in to change notification settings - Fork 219
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
Trait code generation #2074
Merged
Merged
Trait code generation #2074
Conversation
This file contains 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
hpmellema
commented
Dec 14, 2023
...ore/src/main/java/software/amazon/smithy/traitcodegen/generators/common/ToNodeGenerator.java
Outdated
Show resolved
Hide resolved
JordonPhillips
requested changes
Jan 25, 2024
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.
Union shapes don't appear to be supported anywhere. We need like a DataShapeVisitor
or something that forces people to implement all data shapes but no service shapes.
review is still in progress, this covers everything before the interceptors.
smithy-trait-codegen/annotation-processor/processor/build.gradle
Outdated
Show resolved
Hide resolved
...n/codegen-core/src/main/java/software/amazon/smithy/traitcodegen/GenerateTraitDirective.java
Outdated
Show resolved
Hide resolved
...n/codegen-core/src/main/java/software/amazon/smithy/traitcodegen/GenerateTraitDirective.java
Outdated
Show resolved
Hide resolved
...ore/src/main/java/software/amazon/smithy/traitcodegen/generators/common/GetterGenerator.java
Outdated
Show resolved
Hide resolved
...re/src/main/java/software/amazon/smithy/traitcodegen/generators/common/BuilderGenerator.java
Outdated
Show resolved
Hide resolved
...ava/software/amazon/smithy/traitcodegen/generators/traits/DefaultTraitGeneratorProvider.java
Outdated
Show resolved
Hide resolved
...e/src/main/java/software/amazon/smithy/traitcodegen/generators/traits/ProviderGenerator.java
Outdated
Show resolved
Hide resolved
.../src/main/java/software/amazon/smithy/traitcodegen/generators/traits/EnumTraitGenerator.java
Outdated
Show resolved
Hide resolved
hpmellema
force-pushed
the
trait-code-generation
branch
2 times, most recently
from
January 25, 2024 19:08
83eb527
to
2765ba7
Compare
hpmellema
force-pushed
the
trait-code-generation
branch
5 times, most recently
from
February 22, 2024 20:49
a2c5b37
to
d7e51c4
Compare
JordonPhillips
requested changes
Feb 27, 2024
smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/Mapper.java
Outdated
Show resolved
Hide resolved
smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegen.java
Outdated
Show resolved
Hide resolved
smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegen.java
Show resolved
Hide resolved
...ait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/TraitGenerator.java
Outdated
Show resolved
Hide resolved
...ware/amazon/smithy/traitcodegen/integrations/javadoc/BuilderClassSectionDocsInterceptor.java
Show resolved
Hide resolved
...-codegen/src/main/java/software/amazon/smithy/traitcodegen/sections/BuilderClassSection.java
Show resolved
Hide resolved
...-codegen/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin
Outdated
Show resolved
Hide resolved
sugmanue
reviewed
Feb 28, 2024
smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenUtils.java
Outdated
Show resolved
Hide resolved
smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenUtils.java
Outdated
Show resolved
Hide resolved
smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenUtils.java
Outdated
Show resolved
Hide resolved
...t-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/BuilderGenerator.java
Outdated
Show resolved
Hide resolved
...t-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/BuilderGenerator.java
Outdated
Show resolved
Hide resolved
...hy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenSettings.java
Show resolved
Hide resolved
smithy-trait-codegen/src/test/resources/META-INF/smithy/non-java-names.smithy
Outdated
Show resolved
Hide resolved
smithy-trait-codegen/src/test/resources/META-INF/smithy/non-java-names.smithy
Outdated
Show resolved
Hide resolved
...y-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/LoadsFromModelTest.java
Show resolved
Hide resolved
...ware/amazon/smithy/traitcodegen/integrations/uniqueitems/UniqueItemDecoratorIntegration.java
Show resolved
Hide resolved
JordonPhillips
requested changes
Feb 28, 2024
...-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/TraitCodegenPluginTest.java
Outdated
Show resolved
Hide resolved
JordonPhillips
approved these changes
Mar 27, 2024
sugmanue
reviewed
Mar 27, 2024
smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegen.java
Outdated
Show resolved
Hide resolved
...hy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenSettings.java
Outdated
Show resolved
Hide resolved
...it-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenSymbolProvider.java
Outdated
Show resolved
Hide resolved
smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenUtils.java
Outdated
Show resolved
Hide resolved
...t-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/BuilderGenerator.java
Outdated
Show resolved
Hide resolved
...t-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/BuilderGenerator.java
Outdated
Show resolved
Hide resolved
...-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/FromNodeGenerator.java
Show resolved
Hide resolved
...n/java/software/amazon/smithy/traitcodegen/integrations/idref/IdRefDecoratorIntegration.java
Outdated
Show resolved
Hide resolved
…tcodegen/TraitCodegenSettings.java Co-authored-by: Manuel Sugawara <sugmanue@amazon.com>
Co-authored-by: Manuel Sugawara <sugmanue@amazon.com>
sugmanue
approved these changes
Mar 27, 2024
10 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
resolves #117
Description of changes:
This pull request adds a new plugin that generates Java trait classes from smithy models. The generation of java trait classes directly from smithy models removes the need to hand-write most trait implementations.
Background
There are a number of common trait definitions that we see across smithy projects. Each of these trait definitions requires a developer to:
This boilerplate can be removed for the majority of custom trait use cases using smithy code generation (handling steps 2 and 3). Issue #117 first introduced this idea.
Caveats
Blob
andUnion
traits are not currently handled by this plugin. We can add support for these trait types in later PRs as the need arises.Configuration
The plugin defines the following configuration options:
How is the list of shapes to generate determined?
This code generation plugin creates its own Codegen Orchestration class
TraitCodegen
that handles the trait code generation process. The set of shapes to generate is determined as follows:@trait
trait applied in the specified namespaceThese shapes are then iterated through to generate all required trait classes.
In addition to generating trait implementation classes, this plugin also automatically adds trait Implementation classes to the trait service provider file (
META-INF/services/software.amazon.smithy.model.traits.TraitService
).Example
Lets say we have the following smithy model:
We can add the trait codegen plugin to our
smithy-build.json
as follows:Running
smithy build
will then generate the following class definition for our trait:Additional examples can be viewed by pulling down this branch, building it and inspecting the generated code in
smithy-trait-codegen/build/integ
.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.