Add and remove members to index automatically#206
Merged
Conversation
b0af5e6 to
e774e8f
Compare
kstich
requested changes
Nov 15, 2019
smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeIndex.java
Outdated
Show resolved
Hide resolved
smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeIndex.java
Outdated
Show resolved
Hide resolved
JordonPhillips
approved these changes
Nov 15, 2019
This commit updates the ShapeIndex to automatically add and remove members from shapes that have members. This required some extra functionality be introduced to shapes which then in turn resulted in cleanup in other places in the codebase. 1. ShapeIndex now automatically adds and removes members when shapes are added. 2. There is now a members() method on all shapes to return the members contained in the shape (if any). Shapes that have no members just return an empty collection by default, and shapes that do contain members override the abstract method. 3. Because members are now less important to contain a reference to outside of their containing shapes (since you don't need to explicitly add them to a shape index), you can now automatically create member shapes for container shapes by just passing in the target of the member or passing both the target and a consumer that accepts the created MemberShape.Builder type. This removes the need to create the right shape ID for the shape (suffixing with "$" + the member name). 4. ShapeIndex doesn't really need a ConcurrentHashMap to cache different groups of shape types. The code that was used for that was overly complicated and likely made it slower rather than faster (the majority of models will use the prelude and will have more than 50 shapes, so the optimizations that were in place don't really make sense any more). 5. Because there's so much shared code between StructureShape and UnionShape, I created an abstract class for their shape and builders to make them simpler to maintain. 6. A couple model transformations were updated to use the new members() method. 7. Members of structures and unions are now sorted rather than maintain insert order. Nothing should ever depend on a stable order based on inserts since Smithy models can be loaded and aggregated from multiple sources.
e774e8f to
283ea69
Compare
kstich
approved these changes
Nov 15, 2019
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
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.
This commit updates the ShapeIndex to automatically add and remove
members from shapes that have members. This required some extra
functionality be introduced to shapes which then in turn resulted in
cleanup in other places in the codebase.
added.
contained in the shape (if any). Shapes that have no members just
return an empty collection by default, and shapes that do contain
members override the abstract method.
outside of their containing shapes (since you don't need to
explicitly add them to a shape index), you can now automatically
create member shapes for container shapes by just passing in the
target of the member or passing both the target and a consumer that
accepts the created MemberShape.Builder type. This removes the need
to create the right shape ID for the shape (suffixing with "$" + the
member name).
groups of shape types. The code that was used for that was overly
complicated and likely made it slower rather than faster (the
majority of models will use the prelude and will have more than 50
shapes, so the optimizations that were in place don't really make
sense any more).
UnionShape, I created an abstract class for their shape and builders
to make them simpler to maintain.
method.
insert order. Nothing should ever depend on a stable order based on
inserts since Smithy models can be loaded and aggregated from
multiple sources.
Issue #, if available:
Description of changes:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.