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

Update NodeMapper to handle Trait sourceLocation #865

Merged
merged 3 commits into from
Jul 19, 2021

Conversation

JordonPhillips
Copy link
Contributor

@JordonPhillips JordonPhillips commented Jul 15, 2021

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.

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.

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.
@JordonPhillips JordonPhillips requested a review from mtdowling July 15, 2021 11:52
@JordonPhillips JordonPhillips added the bug This issue is a bug. label Jul 15, 2021
@gosar
Copy link
Contributor

gosar commented Jul 15, 2021

Do you think the serializer (Trait->Node) is handling sourceLocation?

This updates the serializer for NodeMapper to pass along the
source location.
@@ -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
Copy link
Contributor

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?

Copy link
Contributor Author

@JordonPhillips JordonPhillips Jul 19, 2021

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.

Copy link
Contributor

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.

@JordonPhillips JordonPhillips marked this pull request as ready for review July 19, 2021 10:10
@JordonPhillips JordonPhillips requested a review from kstich as a code owner July 19, 2021 10:10
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.
@JordonPhillips JordonPhillips force-pushed the fix-node-mapper-generics branch from 8ecff32 to 187b9fd Compare July 19, 2021 14:12
@gosar gosar merged commit 4a68144 into main Jul 19, 2021
gosar added a commit to gosar/smithy that referenced this pull request Jul 19, 2021
gosar added a commit to gosar/smithy that referenced this pull request Jul 20, 2021
JordonPhillips pushed a commit that referenced this pull request Jul 21, 2021
JordonPhillips pushed a commit that referenced this pull request Jul 21, 2021
@mtdowling mtdowling deleted the fix-node-mapper-generics branch September 21, 2021 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants