Skip to content
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

Add trait code generation #117

Closed
mtdowling opened this issue Jul 15, 2019 · 2 comments · Fixed by #2074
Closed

Add trait code generation #117

mtdowling opened this issue Jul 15, 2019 · 2 comments · Fixed by #2074
Labels
feature-request A feature should be added or improved.

Comments

@mtdowling
Copy link
Member

mtdowling commented Jul 15, 2019

The code used to represent typed values for traits are ripe for code generation-- they're mostly the same thing and formulaic depending on the type of trait.

I pushed up a proof of concept branch to kick start the idea. It needs work and has lots of todos. I probably wont have the cycles to finish this for the next few weeks, so anyone is free to take it over.

https://github.com/awslabs/smithy/tree/smithy-codegen-traits/codegen/smithy-codegen-traits/src/main/java/software/amazon/smithy/codegen/traits

Notes and considerations:

  • While it would be nice to generate the traits in the smithy-model package, it might not be worth it at this point since it would require pulling a ton of code out into a lower-level package that doesn't depend on code generation so that the smithy-model package could.
  • It would be nice if this could be an exercise to prove out the design of CodeWriter, but if that proves insufficient, feel free to pull in a dependency on JavaPoet.
  • Traits that target structure shapes should inline the members of the targeted structure into the trait itself rather than require a structure value to be passed into the code generated trait.

Tracking: SDK-23707

@mtdowling mtdowling added the feature-request A feature should be added or improved. label Sep 19, 2019
@mtdowling mtdowling added the GA label Feb 26, 2020
@mtdowling mtdowling removed the GA label Mar 13, 2020
@robin-aws
Copy link
Contributor

Would it fit better to create a meta-trait that could connect a trait to the structure declaration that defines its value shape? These implicit shapes would become explicit, and this problem would be mostly solved by existing code generation logic. There's probably some user understanding benefit here, and some deeper dogfooding of the IDL.

@mtdowling
Copy link
Member Author

I think we basically did what you're suggesting. You define traits in the model by adding the trait trait to a shape. I think the issue description here may have been written before we made that change, so the last bullet point doesn't make much sense anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants