Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Sample: Use slashes instead of underscores in PHP namespaces for nested enums and messages #2757

Merged
merged 14 commits into from
May 29, 2019

Conversation

yihanzhen
Copy link
Contributor

No description provided.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label May 7, 2019
@yihanzhen
Copy link
Contributor Author

PTAL

@codecov
Copy link

codecov bot commented May 7, 2019

Codecov Report

Merging #2757 into master will increase coverage by <.01%.
The diff coverage is 85%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2757      +/-   ##
============================================
+ Coverage     87.18%   87.19%   +<.01%     
+ Complexity     5699     5698       -1     
============================================
  Files           473      473              
  Lines         22615    22609       -6     
  Branches       2426     2425       -1     
============================================
- Hits          19716    19713       -3     
+ Misses         2080     2078       -2     
+ Partials        819      818       -1
Impacted Files Coverage Δ Complexity Δ
...gen/transformer/php/PhpModelTypeNameConverter.java 84.11% <85%> (+1.81%) 23 <0> (-1) ⬇️

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 5bad4a2...ab4d4e1. Read the comment docs.

@codecov
Copy link

codecov bot commented May 7, 2019

Codecov Report

Merging #2757 into master will increase coverage by 0.02%.
The diff coverage is 90%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2757      +/-   ##
============================================
+ Coverage     87.23%   87.25%   +0.02%     
+ Complexity     5723     5721       -2     
============================================
  Files           474      474              
  Lines         22685    22674      -11     
  Branches       2435     2432       -3     
============================================
- Hits          19789    19784       -5     
+ Misses         2077     2073       -4     
+ Partials        819      817       -2
Impacted Files Coverage Δ Complexity Δ
...gen/transformer/php/PhpModelTypeNameConverter.java 86.27% <90%> (+3.97%) 22 <1> (-2) ⬇️

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 955dd27...3ad0953. Read the comment docs.

Copy link
Contributor

@beccasaurus beccasaurus left a comment

Choose a reason for hiding this comment

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

Ooooooo pretty

Copy link
Contributor

@dwsupplee dwsupplee left a comment

Choose a reason for hiding this comment

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

Should we make sure we keep the code coverage within the 87.18% limit?

@yihanzhen
Copy link
Contributor Author

We don't usually enforce that... but it does seem the changes in this PR could use some more testing. I'll see if I can reach the target code coverage.

@yihanzhen
Copy link
Contributor Author

PTAL

Copy link
Contributor

@dwsupplee dwsupplee left a comment

Choose a reason for hiding this comment

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

Does this test/cover the case where the relative name could conflict?

For example, could the following occur?:

use Test\One\Hello;
use Test\Two\Hello;

@yihanzhen
Copy link
Contributor Author

In this example, the second Hello will be used by its full name.
Added a test to show this logic too.

Copy link
Contributor

@dwsupplee dwsupplee left a comment

Choose a reason for hiding this comment

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

This looks really nice, thank you @hzyi-google. I think it would also be worthwhile for @michaelbausor to take a peek before merging.

.append("\\")
.append(component.substring(0, 1).toUpperCase())
.append(component.substring(1));
return typeNameConverter.getTypeName(builder.toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the point of this for loop if we always return on the first element?

@michaelbausor
Copy link
Contributor

Fixes #2141

@yihanzhen
Copy link
Contributor Author

@michaelbausor Thanks for the catch! Fixed and also added a test. PTAL

* </ul>
*
* <p>To correctly output these type names, we need to check whether the parent of a proto element
* is a message, and if so use '_' as a separator.
*/
private TypeName getTypeName(ProtoElement elem, int maxDepth) {
Copy link
Contributor

Choose a reason for hiding this comment

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

maxDepth is unused now - can we remove it?

// Create the type name based on the element's full name
for (String component : fullName.split("\\.")) {
builder
.append("\\")
Copy link
Contributor

Choose a reason for hiding this comment

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

This step of splitting, appending \, capitalizing, and rejoining is duplicated. Consider the following refactor: create a helper function:

private static String makeNamespacePiece(String piece) {
  return "\\" + piece.substring(0, 1).toUpperCase() + piece.substring(1);
}

Then use streams:

String s = fullName.split("\\.").stream().transform(makeNamespacePiece).joinStrings();

(I don't think joinStrings() is a thing, but use a collector to join the strings in some way).

@yihanzhen yihanzhen merged commit bc9741c into googleapis:master May 29, 2019
busunkim96 pushed a commit to busunkim96/gapic-generator that referenced this pull request Nov 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes This human has signed the Contributor License Agreement. Core: Sample-gen
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants