-
Notifications
You must be signed in to change notification settings - Fork 53
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
fix: [gapic-generator-java] align writer behavior for nested types #1709
Conversation
…asses * To illustrate current unintended behavior
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.
No impact on the goldens?
If so, perhaps we can create a (very) simple extended showcase proto to exercise this behavior -- similar to how we did for validating REST-only client generation behavior? |
@meltsufin Not for this change. For a bit more context - this nested class import issue was initially uncovered when the generator mistakenly tried to pull in
@burkedavison I was considering this as well - actually tried doing this for validating the change in #1726, but this fix was easier to unit test so I just went with those instead. I can set up something similarly here if the approach taken in the other PR makes sense? |
I agree with Mike and Burke that it would be better to have a golden test to easily see the changes. Showcase may be a little overkill since this does not interact with the server, a golden unit test would be a great fit. |
ImmutableList.Builder<String> listBuilder = new ImmutableList.Builder<>(); | ||
Class<?> currentClz = clazz(); | ||
while (currentClz.getEnclosingClass() != null) { | ||
listBuilder.add(currentClz.getEnclosingClass().getSimpleName()); | ||
currentClz = currentClz.getEnclosingClass(); | ||
} | ||
return listBuilder.build(); | ||
return listBuilder.build().reverse(); |
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.
Can we achieve the same thing without this change? Seems we can try to get the last element from the list in the writer?
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.
Yes for the import writer, but the JavaWriterVisitor
also relies on this ordering for the enclosing class writes.
This fix to ConcreteReference
wasn't a part of the original issue investigated, but it looked like an implementation bug that perhaps didn't surface in generated code anywhere yet. I think the intended result of this enclosingClassNames
call should have outer to inner ordering, given this original comment and upstream usages of this method in the generator.
|
||
writerVisitor.clear(); | ||
|
||
ConcreteReference nestedConcreteReference = |
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.
This should be break into two test cases if we want to test both type of references. However, I think we only need to test one of them if the only change is in the writer.
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.
I think the additional change in ConcreteReference
is still needed given #1709 (comment). Breaking this into separate test cases makes sense though - will update.
@blakeli0 Makes sense. Looks like there's actually a nested_message.proto that exists and is currently used in |
Added a test proto and new golden unit test in 6ab1628. (Had some uncertainty deciding where best to put this golden test since the existing ones are mostly separate for each I ended up adding one of these into |
[gapic-generator-java-root] Kudos, SonarCloud Quality Gate passed! |
[java_showcase_integration_tests] Kudos, SonarCloud Quality Gate passed! |
[java_showcase_unit_tests] Kudos, SonarCloud Quality Gate passed! |
Thanks Emily! I think your approach is fine, it's very specific to what we want to test. As you mentioned, our golden tests are currently assuming writers behave perfectly so it is a little weird to add a golden test just for writers. If you prefer, we can add this test RPC to one of the existing protos, so that it's tested through other golden tests and don't have to load it separately. |
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.
LGTM. We could move the golden tests to composers or add the test case to one of the existing protos, but I don't think it should block this PR.
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.
LGTM. We could move the golden tests to composers or add the test case to one of the existing protos, but I don't think it should block this PR.
Sounds good - I'll merge this in since the fix is also independent of #1726, so that it can make it into the upcoming release! |
This PR:
JavaWriterVisitor
andImportWriterVisitor
com.example.Outer
), while type references will be written asOuter.Middle.Inner
ConcreteReference
where multiple levels of enclosed classes are written in reversed orderFixes #1708 ☕️