Update NodeMapper to handle Trait sourceLocation#865
Merged
Conversation
This updates NodeMapper so that it can properly set source location on traits that use the AbstractTraitBuilder. Unfortunately the fix implemented here is a hack that looks for that specific case, and the same root cause may bite us elsewhere. The true root cause is that our default deserializer is unable to resolve generics. AbstractTraitBuilder generically defines the return value of the setter `sourceLocation` to `B extends AbstractTraitBuilder`. When we use reflection to look at the return type, all we see is `AbstractTraitBuilder`. We *can* also get the type variable, but actually resolving it will take a decent amount of effort as that functionality isn't built in.
Contributor
|
Do you think the serializer (Trait->Node) is handling sourceLocation? |
This updates the serializer for NodeMapper to pass along the source location.
gosar
reviewed
Jul 16, 2021
smithy-model/src/test/java/software/amazon/smithy/model/node/NodeMapperTest.java
Outdated
Show resolved
Hide resolved
smithy-model/src/test/java/software/amazon/smithy/model/node/NodeMapperTest.java
Outdated
Show resolved
Hide resolved
| return null; | ||
| } | ||
|
|
||
| // TODO: make sure every instance of `toNode` is setting this |
Contributor
There was a problem hiding this comment.
what does this comment mean? I'm not sure I understand what needs to be checked and where?
Contributor
Author
There was a problem hiding this comment.
Anything that implements the ToNode interface needs to set source location on the node. I think your PR does that.
Contributor
There was a problem hiding this comment.
The comment does not clarify that you are talking about sourceLocation.
smithy-model/src/main/java/software/amazon/smithy/model/node/DefaultNodeDeserializers.java
Show resolved
Hide resolved
This updates the builder detection in the node deserializer to check to see if the builder type is assignable to a given method's return type. This removes the need for a hack enabling source location, but it's still not perfect. Ideally we should attempt to resolve any generic return types.
8ecff32 to
187b9fd
Compare
gosar
approved these changes
Jul 19, 2021
gosar
added a commit
to gosar/smithy
that referenced
this pull request
Jul 19, 2021
Those cases will be fixed with smithy-lang#865
gosar
added a commit
to gosar/smithy
that referenced
this pull request
Jul 20, 2021
They are fixed via smithy-lang#865
JordonPhillips
pushed a commit
that referenced
this pull request
Jul 21, 2021
Those cases will be fixed with #865
JordonPhillips
pushed a commit
that referenced
this pull request
Jul 21, 2021
They are fixed via #865
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 updates NodeMapper so that it can properly set source location on traits that use the AbstractTraitBuilder. Unfortunately the fix implemented here is a hack that looks for that specific case, and the same root cause may bite us elsewhere.
The true root cause is that our default deserializer is unable to resolve generics. AbstractTraitBuilder generically defines the return value of the setter
sourceLocationtoB extends AbstractTraitBuilder. When we use reflection to look at the return type, all we see isAbstractTraitBuilder. We can also get the type variable, but actually resolving it will take a decent amount of effort as that functionality isn't built in.This is related to #864
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.