Escape Java keywords#40
Conversation
| def read_from_gapic_yaml(yaml_file): | ||
| with open(yaml_file) as f: | ||
| gapic_yaml = yaml.load(f) | ||
| gapic_yaml = yaml.full_load(f) |
There was a problem hiding this comment.
This change is to get around the PyYAML load() deprecation: https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation
|
|
||
|
|
||
| java_reserved_symbols = { | ||
| "abstract", |
There was a problem hiding this comment.
This set is ripped from gapic-generator's JavaNameFormatter
|
|
||
| private static final PathTemplate PATH_TEMPLATE = | ||
| PathTemplate.createWithoutUrlEncoding("shelves/{shelf_id}/books/{book_id}"); | ||
| PathTemplate.createWithoutUrlEncoding("shelves/{shelf_id}/books/{return}"); |
There was a problem hiding this comment.
In this file, all forms of book_id are replaced with the corresponding form for return.
| 'upper': casing_utils.lower_underscore_to_upper_camel( | ||
| f['parameter_name']), | ||
| 'lower': f['parameter'], | ||
| 'parameter_name_in_map': |
There was a problem hiding this comment.
This is needed in the fieldMap, and the value used in the fieldMap used to just be lower, which used to mean casing_utils.lower_underscore_to_lower_camel(lit), but since lower has changed, we have to make a new variable that refers back to the old meaning.
|
PTAL |
|
|
||
| # Resolve collisions with one or more underscores. | ||
| while (desired_name + "_") in self.symbol_table: | ||
| self.symbol_table.add(desired_name + "_") |
There was a problem hiding this comment.
desired_name is not changed in this loop. Won't it be an infinite loop in that case?
| import copy | ||
|
|
||
|
|
||
| class SymbolTable(object): |
There was a problem hiding this comment.
We should add a test for this class.
|
Fixed a bug and verified fix with a test. PTAL |
michaelbausor
left a comment
There was a problem hiding this comment.
LGTM, one change requested
|
|
||
| # Resolve collisions with one or more underscores. | ||
| while (desired_name + "_") in self.symbol_table: | ||
| self.symbol_table.add(desired_name + "_") |
There was a problem hiding this comment.
Why do we need to add this here? Isn't it already in the symbol table?
There was a problem hiding this comment.
good point, removed
Using a glorifed hashmap implementation that is basically a pared-down version of gapic-generator's SymbolTable.