-
Notifications
You must be signed in to change notification settings - Fork 218
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
Update NodeMapper to handle Trait sourceLocation #865
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.
Do you think the serializer (Trait->Node) is handling sourceLocation? |
This updates the serializer for NodeMapper to pass along the source location.
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
@@ -65,6 +65,7 @@ public Node serialize(ToNode value, Set<Object> serializedObjects, NodeMapper ma | |||
return null; | |||
} | |||
|
|||
// TODO: make sure every instance of `toNode` is setting this |
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.
what does this comment mean? I'm not sure I understand what needs to be checked and where?
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.
Anything that implements the ToNode
interface needs to set source location on the node. I think your PR does that.
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.
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
Those cases will be fixed with smithy-lang#865
They are fixed via smithy-lang#865
Those cases will be fixed with #865
They are fixed via #865
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
toB 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.