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

fix(types): Use fully-qualified message type names [ggj] #723

Merged
merged 2 commits into from
May 13, 2021

Conversation

miraleung
Copy link
Contributor

Addresses the use case where a proto message foo.bar.Car has an internal field with the same short name, such as bar.foo.Car.

@miraleung miraleung requested a review from a team as a code owner May 11, 2021 20:09
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label May 11, 2021
@miraleung miraleung requested a review from vam-google May 11, 2021 20:09
@codecov
Copy link

codecov bot commented May 11, 2021

Codecov Report

Merging #723 (13c92e1) into master (2318136) will decrease coverage by 0.19%.
The diff coverage is 79.01%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #723      +/-   ##
==========================================
- Coverage   92.52%   92.33%   -0.20%     
==========================================
  Files         124      124              
  Lines       13459    13489      +30     
  Branches      981      994      +13     
==========================================
+ Hits        12453    12455       +2     
- Misses        765      784      +19     
- Partials      241      250       +9     
Impacted Files Coverage Δ
...rator/gapic/composer/ServiceStubClassComposer.java 99.18% <ø> (-0.01%) ⬇️
.../com/google/api/generator/gapic/model/Message.java 80.76% <ø> (-11.54%) ⬇️
...pic/composer/ServiceStubSettingsClassComposer.java 99.10% <50.00%> (+0.07%) ⬆️
...google/api/generator/gapic/protoparser/Parser.java 48.06% <65.11%> (+0.36%) ⬆️
...gapic/composer/ServiceClientTestClassComposer.java 89.60% <90.90%> (ø)
...tor/gapic/composer/BatchingDescriptorComposer.java 99.73% <100.00%> (ø)
...tor/gapic/composer/ServiceClientClassComposer.java 98.45% <100.00%> (-0.01%) ⬇️
...ic/composer/defaultvalue/DefaultValueComposer.java 92.09% <100.00%> (ø)
...er/samplecode/ServiceClientSampleCodeComposer.java 99.28% <100.00%> (+<0.01%) ⬆️
...pi/generator/gapic/protoparser/HttpRuleParser.java 90.76% <100.00%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2318136...13c92e1. Read the comment docs.

Copy link
Contributor

@vam-google vam-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with few minor comments, please address those before submitting

@@ -30,6 +30,9 @@
public abstract class Message {
public abstract String name();

// The fully-qualified proto name, which differs from the Java fully-qualified name.
public abstract String fullProtoName();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please specify how exactly they are different? Is it about the extra com. prefix for java names, or more than that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's the proto package versus the java_package. Added an example.

// These can be short names (e.g. FooMessage) or fully-qualified names with the *proto* package.
String responseTypeName = lroInfo.getResponseType();
String metadataTypeName = lroInfo.getMetadataType();
String[] responseTypeNameComponents = responseTypeName.split("\\.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but it seems like you don't need the full set of compontents, only the last element after dot, so it can be something like.

String responseTypeShortName = responseTypeName.substring(responseTypeName.lastIndexOf(".") + 1)

It is not about performance, mainly just to make it clear that the other compnents are not needed to the readers of the code.

Copy link
Contributor Author

@miraleung miraleung May 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. FWIW, the tradeoff here is an extra check that the index is >= 0.

// The messageTypes map keys to the Java fully-qualified name.
for (Map.Entry<String, Message> messageEntry : messageTypes.entrySet()) {
String[] packageComponents = messageEntry.getKey().split("\\.");
String messageShortName = packageComponents[packageComponents.length - 1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar situation as with responseTypeShortName and metadataTypeShortName

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

for (Map.Entry<String, Message> messageEntry : messageTypes.entrySet()) {
String[] packageComponents = messageEntry.getKey().split("\\.");
String messageShortName = packageComponents[packageComponents.length - 1];
if (responseMessage == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The responseMessage logic and metadataMessage logic seem to be a copypaste of each other. Please consider moving that into a private or method combining this to a for loop with 2 elements in it (response and metadata messages).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd considered using these, which would result in the following tradeoffs:

  • Nested loop: Need an extra map or data structure to associate responseMessage, responseTypeName, isResponseTypeNameShortOnly, which would be less readable, or recompute the latter in the loop (which is inefficient).
  • Separate method: Need to take four parameters at best - the three above plus messageEntry, which would make the call site, helper signature, and method itself less readable.

Given that the logic is relatively small, copy-pasting does not seem to have significantly better or worse tradeoffs compared to the alternative approches.

@miraleung miraleung merged commit 8a5c36c into master May 13, 2021
@miraleung miraleung deleted the dev/full_msg_types branch May 13, 2021 22:21
suztomo pushed a commit that referenced this pull request Mar 21, 2023
* chore: update dependencies for regapic

* add more dependencies and trigger comment

* update goldens

* fix indentation

* remove duplicate gax-httpjson dependency

* remove duplicated dependencies
Source-Link: googleapis/synthtool@fa54eb2
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:1ec28a46062b19135b11178ceee60231e5f5a92dab454e23ae0aab72cd875906
suztomo pushed a commit that referenced this pull request Mar 21, 2023
…-plugin to v3.3.2 (#723)

[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [org.apache.maven.plugins:maven-javadoc-plugin](https://maven.apache.org/plugins/) | `3.3.1` -> `3.3.2` | [![age](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-javadoc-plugin/3.3.2/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-javadoc-plugin/3.3.2/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-javadoc-plugin/3.3.2/compatibility-slim/3.3.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-javadoc-plugin/3.3.2/confidence-slim/3.3.1)](https://docs.renovatebot.com/merge-confidence/) |

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-core).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants