From e9f1240b60063328ba885aca93f8650546e9d30d Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Thu, 14 Mar 2019 12:06:51 -0700 Subject: [PATCH 01/30] change book name --- test/testdata/library_gapic.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testdata/library_gapic.yaml b/test/testdata/library_gapic.yaml index 70f075c..becefb2 100644 --- a/test/testdata/library_gapic.yaml +++ b/test/testdata/library_gapic.yaml @@ -20,7 +20,7 @@ collections: common_resource_name: com.google.cloud.ProjectName - name_pattern: shelves/{shelf_id} entity_name: shelf -- name_pattern: shelves/{shelf_id}/books/{book_id} +- name_pattern: shelves/{shelf_id}/books/{return} entity_name: book language_overrides: - language: java From 512cad301341790b24090ab03c3bb7b3f87d1802 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Thu, 14 Mar 2019 17:18:22 -0700 Subject: [PATCH 02/30] fixed? --- plugin/templates/resource_name.py | 4 +- plugin/utils/symbol_table.py | 109 ++++++++++++++++++++ test/testdata/java_shelf_book_name.baseline | 40 +++---- test/testdata/library_gapic.yaml | 2 +- 4 files changed, 133 insertions(+), 22 deletions(-) create mode 100644 plugin/utils/symbol_table.py diff --git a/plugin/templates/resource_name.py b/plugin/templates/resource_name.py index bac3c01..a5412ca 100644 --- a/plugin/templates/resource_name.py +++ b/plugin/templates/resource_name.py @@ -30,6 +30,7 @@ import os from plugin.utils import path_template from plugin.utils import casing_utils +from plugin.utils.symbol_table import SymbolTable RESOURCE_NAMES_GLOBAL_PACKAGE_JAVA = 'com.google.api.resourcenames' @@ -59,6 +60,7 @@ def package(self): class ResourceName(ResourceNameBase): def __init__(self, collection_config, java_package, oneof): + symbol_table = SymbolTable() entity_name = collection_config.java_entity_name name_template = path_template.PathTemplate( @@ -92,7 +94,7 @@ def __init__(self, collection_config, java_package, oneof): self.parameter_list[-1]['not_last'] = False self.format_fields = [{ 'upper': casing_utils.lower_camel_to_upper_camel(f['parameter']), - 'lower': f['parameter'], + 'lower': symbol_table.getNewSymbol(f['parameter']), } for f in self.parameter_list] self.format_string = collection_config.name_pattern self.package_name = java_package diff --git a/plugin/utils/symbol_table.py b/plugin/utils/symbol_table.py new file mode 100644 index 0000000..ecf6890 --- /dev/null +++ b/plugin/utils/symbol_table.py @@ -0,0 +1,109 @@ +# Copyright 2019 Google LLC +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +""" +A utility class used to get and store unique symbols. +""" + +import copy + +class SymbolTable(object): + + """ + Initialize a case-sensitive SymbolTable with a set of symbols. + """ + def __init__(self): + self.symbol_table = copy.deepcopy(java_reserved_symbols) + + def getNewSymbol(self, desired_name): + + if not (desired_name in self.symbol_table): + self.symbol_table.append(desired_name) + return desired_name + + # Resolve collisions with a numeric suffix, starting with 2. + i = 2 + while (desired_name + str(i)) in self.symbol_table : + self.symbol_table.append(desired_name + str(i)) + return desired_name + str(i) + + +java_reserved_symbols = [ + "abstract", + "assert", + "boolean", + "break", + "byte", + "case", + "catch", + "char", + "class", + "const", + "continue", + "default", + "do", + "double", + "else", + "enum", + "extends", + "false", + "final", + "finally", + "float", + "for", + "goto", + "if", + "implements", + "import", + "instanceof", + "int", + "interface", + "long", + "native", + "new", + "null", + "package", + "private", + "protected", + "public", + "return", + "short", + "static", + "strictfp", + "super", + "switch", + "synchronized", + "this", + "throw", + "throws", + "transient", + "true", + "try", + "void", + "volatile", + "while"] diff --git a/test/testdata/java_shelf_book_name.baseline b/test/testdata/java_shelf_book_name.baseline index 5a85fb6..bca3e6a 100644 --- a/test/testdata/java_shelf_book_name.baseline +++ b/test/testdata/java_shelf_book_name.baseline @@ -27,19 +27,19 @@ import java.util.List; public class ShelfBookName extends BookName { private static final PathTemplate PATH_TEMPLATE = - PathTemplate.createWithoutUrlEncoding("shelves/{shelf_id}/books/{book_id}"); + PathTemplate.createWithoutUrlEncoding("shelves/{shelf_id}/books/{return}"); private volatile Map fieldValuesMap; private final String shelfId; - private final String bookId; + private final String return2; public String getShelfId() { return shelfId; } - public String getBookId() { - return bookId; + public String getReturn() { + return return2; } public static Builder newBuilder() { @@ -52,20 +52,20 @@ public class ShelfBookName extends BookName { private ShelfBookName(Builder builder) { shelfId = Preconditions.checkNotNull(builder.getShelfId()); - bookId = Preconditions.checkNotNull(builder.getBookId()); + return2 = Preconditions.checkNotNull(builder.getReturn()); } - public static ShelfBookName of(String shelfId, String bookId) { + public static ShelfBookName of(String shelfId, String return) { return newBuilder() .setShelfId(shelfId) - .setBookId(bookId) + .setReturn(return2) .build(); } - public static String format(String shelfId, String bookId) { + public static String format(String shelfId, String return) { return newBuilder() .setShelfId(shelfId) - .setBookId(bookId) + .setReturn(return2) .build() .toString(); } @@ -76,7 +76,7 @@ public class ShelfBookName extends BookName { } Map matchMap = PATH_TEMPLATE.validatedMatch(formattedString, "ShelfBookName.parse: formattedString not in valid format"); - return of(matchMap.get("shelf_id"), matchMap.get("book_id")); + return of(matchMap.get("shelf_id"), matchMap.get("return")); } public static List parseList(List formattedStrings) { @@ -109,7 +109,7 @@ public class ShelfBookName extends BookName { if (fieldValuesMap == null) { ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); fieldMapBuilder.put("shelfId", shelfId); - fieldMapBuilder.put("bookId", bookId); + fieldMapBuilder.put("return2", return2); fieldValuesMap = fieldMapBuilder.build(); } } @@ -123,21 +123,21 @@ public class ShelfBookName extends BookName { @Override public String toString() { - return PATH_TEMPLATE.instantiate("shelf_id", shelfId, "book_id", bookId); + return PATH_TEMPLATE.instantiate("shelf_id", shelfId, "return", return); } /** Builder for ShelfBookName. */ public static class Builder { private String shelfId; - private String bookId; + private String return2; public String getShelfId() { return shelfId; } - public String getBookId() { - return bookId; + public String getReturn() { + return return2; } public Builder setShelfId(String shelfId) { @@ -145,8 +145,8 @@ public class ShelfBookName extends BookName { return this; } - public Builder setBookId(String bookId) { - this.bookId = bookId; + public Builder setReturn(String return2) { + this.return2 = return2; return this; } @@ -155,7 +155,7 @@ public class ShelfBookName extends BookName { private Builder(ShelfBookName shelfBookName) { shelfId = shelfBookName.shelfId; - bookId = shelfBookName.bookId; + return2 = shelfBookName.return2; } public ShelfBookName build() { @@ -171,7 +171,7 @@ public class ShelfBookName extends BookName { if (o instanceof ShelfBookName) { ShelfBookName that = (ShelfBookName) o; return (this.shelfId.equals(that.shelfId)) - && (this.bookId.equals(that.bookId)); + && (this.return.equals(that.return)); } return false; } @@ -182,7 +182,7 @@ public class ShelfBookName extends BookName { h *= 1000003; h ^= shelfId.hashCode(); h *= 1000003; - h ^= bookId.hashCode(); + h ^= return.hashCode(); return h; } } diff --git a/test/testdata/library_gapic.yaml b/test/testdata/library_gapic.yaml index becefb2..b44a0a9 100644 --- a/test/testdata/library_gapic.yaml +++ b/test/testdata/library_gapic.yaml @@ -20,7 +20,7 @@ collections: common_resource_name: com.google.cloud.ProjectName - name_pattern: shelves/{shelf_id} entity_name: shelf -- name_pattern: shelves/{shelf_id}/books/{return} +- name_pattern: shelves/{shelf_id}/books/{return} # Test using a Java keyword ("return"). entity_name: book language_overrides: - language: java From 02792053a19ea41935e1f73fdde7c580b30f6152 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Thu, 14 Mar 2019 17:22:45 -0700 Subject: [PATCH 03/30] make symboltable a set --- plugin/utils/symbol_table.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugin/utils/symbol_table.py b/plugin/utils/symbol_table.py index ecf6890..0dec198 100644 --- a/plugin/utils/symbol_table.py +++ b/plugin/utils/symbol_table.py @@ -31,6 +31,7 @@ """ import copy +from sets import Set class SymbolTable(object): @@ -43,17 +44,17 @@ def __init__(self): def getNewSymbol(self, desired_name): if not (desired_name in self.symbol_table): - self.symbol_table.append(desired_name) + self.symbol_table.add(desired_name) return desired_name # Resolve collisions with a numeric suffix, starting with 2. i = 2 while (desired_name + str(i)) in self.symbol_table : - self.symbol_table.append(desired_name + str(i)) + self.symbol_table.add(desired_name + str(i)) return desired_name + str(i) -java_reserved_symbols = [ +java_reserved_symbols = Set([ "abstract", "assert", "boolean", @@ -106,4 +107,4 @@ def getNewSymbol(self, desired_name): "try", "void", "volatile", - "while"] + "while"]) From 9b9509b42c772868b3b9f0963ad39ab1e00e7e76 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Thu, 14 Mar 2019 17:31:57 -0700 Subject: [PATCH 04/30] flake8 formatting --- plugin/utils/symbol_table.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/plugin/utils/symbol_table.py b/plugin/utils/symbol_table.py index 0dec198..684e50b 100644 --- a/plugin/utils/symbol_table.py +++ b/plugin/utils/symbol_table.py @@ -33,25 +33,26 @@ import copy from sets import Set + class SymbolTable(object): - """ - Initialize a case-sensitive SymbolTable with a set of symbols. - """ - def __init__(self): - self.symbol_table = copy.deepcopy(java_reserved_symbols) + """ + Initialize a case-sensitive SymbolTable with a set of symbols. + """ + def __init__(self): + self.symbol_table = copy.deepcopy(java_reserved_symbols) - def getNewSymbol(self, desired_name): + def getNewSymbol(self, desired_name): - if not (desired_name in self.symbol_table): - self.symbol_table.add(desired_name) - return desired_name + if not (desired_name in self.symbol_table): + self.symbol_table.add(desired_name) + return desired_name - # Resolve collisions with a numeric suffix, starting with 2. - i = 2 - while (desired_name + str(i)) in self.symbol_table : - self.symbol_table.add(desired_name + str(i)) - return desired_name + str(i) + # Resolve collisions with a numeric suffix, starting with 2. + i = 2 + while (desired_name + str(i)) in self.symbol_table: + self.symbol_table.add(desired_name + str(i)) + return desired_name + str(i) java_reserved_symbols = Set([ From 5d7751212b53828bbedf4996653f6c52f6d134d1 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Thu, 14 Mar 2019 17:37:30 -0700 Subject: [PATCH 05/30] use protoc 3.6.1 --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index ef2dfef..491e777 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,9 @@ python: - "3.5" - "3.6" before_script: - - wget https://github.com/google/protobuf/releases/download/v3.3.0/protoc-3.3.0-linux-x86_64.zip -O /tmp/protoc.tar.gz - - unzip -o /tmp/protoc.tar.gz -d protoc-3.3.0 - - export PATH=$PATH:$PWD/protoc-3.3.0/bin + - wget https://github.com/google/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip -O /tmp/protoc.tar.gz + - unzip -o /tmp/protoc.tar.gz -d protoc-3.6.1 + - export PATH=$PATH:$PWD/protoc-3.6.1/bin - git clone https://github.com/googleapis/googleapis.git install: pip install codecov tox-travis script: tox test/test_plugin_baseline.py From faf7ec161f1d25151f4ba65b5717a9ef0f037e79 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Thu, 14 Mar 2019 17:43:57 -0700 Subject: [PATCH 06/30] sudo? --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 491e777..f541a3f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,6 @@ before_script: - export PATH=$PATH:$PWD/protoc-3.6.1/bin - git clone https://github.com/googleapis/googleapis.git install: pip install codecov tox-travis -script: tox test/test_plugin_baseline.py +script: sudo tox test/test_plugin_baseline.py after_success: - codecov From f0f8eced437b4a08e7100c89339ba8a1d63df772 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Thu, 14 Mar 2019 17:52:59 -0700 Subject: [PATCH 07/30] avoid deprecated warning on yaml loader --- plugin/utils/gapic_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/utils/gapic_utils.py b/plugin/utils/gapic_utils.py index 4744bc6..ec01d59 100644 --- a/plugin/utils/gapic_utils.py +++ b/plugin/utils/gapic_utils.py @@ -34,7 +34,7 @@ def read_from_gapic_yaml(yaml_file): with open(yaml_file) as f: - gapic_yaml = yaml.load(f) + gapic_yaml = yaml.load(f, Loader=yaml.FullLoader) collections = {} if 'collections' in gapic_yaml: From 45cc3ce9e8151ffc1cbac569ad8d894b58191102 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Thu, 14 Mar 2019 17:55:20 -0700 Subject: [PATCH 08/30] print out error --- test/test_plugin_baseline.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_plugin_baseline.py b/test/test_plugin_baseline.py index 4f12f90..cc47d5c 100644 --- a/test/test_plugin_baseline.py +++ b/test/test_plugin_baseline.py @@ -17,6 +17,7 @@ import subprocess import shutil import difflib +import sys from plugin.utils import casing_utils @@ -71,7 +72,7 @@ def format_output_arg(name, output_dir, extra_arg=None): '--plugin=protoc-gen-gapic=gapic_plugin.py'] args += ['-I' + path for path in include_dirs] args += proto_files - subprocess.check_call(args) + subprocess.check_call(args, stderr=sys.stderr) def clean_test_output(): From 5e7205405e6b9a79b3cf1fe12071988d162effca Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Thu, 14 Mar 2019 17:59:09 -0700 Subject: [PATCH 09/30] ok actually print out error --- test/test_plugin_baseline.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/test_plugin_baseline.py b/test/test_plugin_baseline.py index cc47d5c..4b697c6 100644 --- a/test/test_plugin_baseline.py +++ b/test/test_plugin_baseline.py @@ -72,7 +72,11 @@ def format_output_arg(name, output_dir, extra_arg=None): '--plugin=protoc-gen-gapic=gapic_plugin.py'] args += ['-I' + path for path in include_dirs] args += proto_files - subprocess.check_call(args, stderr=sys.stderr) + try: + subprocess.check_call(args, stderr=sys.stderr) + except subprocess.CalledProcessError as e: + sys.stderr.write(e.message) + def clean_test_output(): From 91e83e542b5b2f0f873ac97a6ec51ece56fc4fc5 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Thu, 14 Mar 2019 18:01:01 -0700 Subject: [PATCH 10/30] remove sudo --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f541a3f..491e777 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,6 @@ before_script: - export PATH=$PATH:$PWD/protoc-3.6.1/bin - git clone https://github.com/googleapis/googleapis.git install: pip install codecov tox-travis -script: sudo tox test/test_plugin_baseline.py +script: tox test/test_plugin_baseline.py after_success: - codecov From 5613d699d479679b7858855f36a0c6600affe894 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Thu, 14 Mar 2019 18:11:37 -0700 Subject: [PATCH 11/30] hhhh --- test/test_plugin_baseline.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/test_plugin_baseline.py b/test/test_plugin_baseline.py index 4b697c6..f57a309 100644 --- a/test/test_plugin_baseline.py +++ b/test/test_plugin_baseline.py @@ -70,13 +70,14 @@ def format_output_arg(name, output_dir, extra_arg=None): args.append(format_output_arg(lang_out, output_dir)) args += [format_output_arg('gapic', output_dir, gapic_yaml), '--plugin=protoc-gen-gapic=gapic_plugin.py'] - args += ['-I' + path for path in include_dirs] + args += ['-I ' + path for path in include_dirs] args += proto_files try: - subprocess.check_call(args, stderr=sys.stderr) + subprocess.check_call(args, stderr=sys.stderr) except subprocess.CalledProcessError as e: - sys.stderr.write(e.message) - + # if e.hasAttr(message) + # sys.stderr.write(e.message) + sys.stderr.write(str(e)) def clean_test_output(): From 9e37a787a02c01f32d6d3f92ddd47e928dd18af5 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 15 Mar 2019 10:25:10 -0700 Subject: [PATCH 12/30] revert somethings --- plugin/utils/gapic_utils.py | 2 +- plugin/utils/symbol_table.py | 3 +-- test/test_plugin_baseline.py | 16 +++++++--------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/plugin/utils/gapic_utils.py b/plugin/utils/gapic_utils.py index ec01d59..4744bc6 100644 --- a/plugin/utils/gapic_utils.py +++ b/plugin/utils/gapic_utils.py @@ -34,7 +34,7 @@ def read_from_gapic_yaml(yaml_file): with open(yaml_file) as f: - gapic_yaml = yaml.load(f, Loader=yaml.FullLoader) + gapic_yaml = yaml.load(f) collections = {} if 'collections' in gapic_yaml: diff --git a/plugin/utils/symbol_table.py b/plugin/utils/symbol_table.py index 684e50b..0a1a8c4 100644 --- a/plugin/utils/symbol_table.py +++ b/plugin/utils/symbol_table.py @@ -31,7 +31,6 @@ """ import copy -from sets import Set class SymbolTable(object): @@ -55,7 +54,7 @@ def getNewSymbol(self, desired_name): return desired_name + str(i) -java_reserved_symbols = Set([ +java_reserved_symbols = set([ "abstract", "assert", "boolean", diff --git a/test/test_plugin_baseline.py b/test/test_plugin_baseline.py index f57a309..3bac38b 100644 --- a/test/test_plugin_baseline.py +++ b/test/test_plugin_baseline.py @@ -14,10 +14,10 @@ import os import pytest -import subprocess +# import subprocess import shutil import difflib -import sys +# import sys from plugin.utils import casing_utils @@ -70,14 +70,12 @@ def format_output_arg(name, output_dir, extra_arg=None): args.append(format_output_arg(lang_out, output_dir)) args += [format_output_arg('gapic', output_dir, gapic_yaml), '--plugin=protoc-gen-gapic=gapic_plugin.py'] - args += ['-I ' + path for path in include_dirs] + args += ['-I' + path for path in include_dirs] args += proto_files - try: - subprocess.check_call(args, stderr=sys.stderr) - except subprocess.CalledProcessError as e: - # if e.hasAttr(message) - # sys.stderr.write(e.message) - sys.stderr.write(str(e)) + # try: + # subprocess.check_call(args, stderr=sys.stderr) + # except subprocess.CalledProcessError as e: + # sys.stderr.write(str(e)) def clean_test_output(): From 2ec65a24cb3159cd03facaca824501db31a3d16a Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 15 Mar 2019 10:55:27 -0700 Subject: [PATCH 13/30] cleanup a little --- plugin/templates/resource_name.py | 4 +--- plugin/utils/gapic_utils.py | 2 +- test/test_plugin_baseline.py | 14 ++++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/plugin/templates/resource_name.py b/plugin/templates/resource_name.py index a5412ca..bac3c01 100644 --- a/plugin/templates/resource_name.py +++ b/plugin/templates/resource_name.py @@ -30,7 +30,6 @@ import os from plugin.utils import path_template from plugin.utils import casing_utils -from plugin.utils.symbol_table import SymbolTable RESOURCE_NAMES_GLOBAL_PACKAGE_JAVA = 'com.google.api.resourcenames' @@ -60,7 +59,6 @@ def package(self): class ResourceName(ResourceNameBase): def __init__(self, collection_config, java_package, oneof): - symbol_table = SymbolTable() entity_name = collection_config.java_entity_name name_template = path_template.PathTemplate( @@ -94,7 +92,7 @@ def __init__(self, collection_config, java_package, oneof): self.parameter_list[-1]['not_last'] = False self.format_fields = [{ 'upper': casing_utils.lower_camel_to_upper_camel(f['parameter']), - 'lower': symbol_table.getNewSymbol(f['parameter']), + 'lower': f['parameter'], } for f in self.parameter_list] self.format_string = collection_config.name_pattern self.package_name = java_package diff --git a/plugin/utils/gapic_utils.py b/plugin/utils/gapic_utils.py index 4744bc6..880c755 100644 --- a/plugin/utils/gapic_utils.py +++ b/plugin/utils/gapic_utils.py @@ -34,7 +34,7 @@ def read_from_gapic_yaml(yaml_file): with open(yaml_file) as f: - gapic_yaml = yaml.load(f) + gapic_yaml = yaml.full_load(f) collections = {} if 'collections' in gapic_yaml: diff --git a/test/test_plugin_baseline.py b/test/test_plugin_baseline.py index 3bac38b..1b7a786 100644 --- a/test/test_plugin_baseline.py +++ b/test/test_plugin_baseline.py @@ -14,10 +14,10 @@ import os import pytest -# import subprocess +import subprocess import shutil import difflib -# import sys +from sys import stderr from plugin.utils import casing_utils @@ -72,10 +72,10 @@ def format_output_arg(name, output_dir, extra_arg=None): '--plugin=protoc-gen-gapic=gapic_plugin.py'] args += ['-I' + path for path in include_dirs] args += proto_files - # try: - # subprocess.check_call(args, stderr=sys.stderr) - # except subprocess.CalledProcessError as e: - # sys.stderr.write(str(e)) + try: + subprocess.check_call(args) + except subprocess.CalledProcessError as exc: + stderr.write("Status : FAIL, return code %s, message %s" % (exc.returncode, exc.output)) def clean_test_output(): @@ -86,6 +86,8 @@ def clean_test_output(): @pytest.fixture(scope='class') def run_protoc(): clean_test_output() + assert(os.path.isdir(TEST_OUTPUT_DIR)) + stderr.write("LKSDJFLKSDJFLKSDJF:LKSJF\n\n\n\nn\\nskfjlskdjflksdjf;" + str(os.path.isdir(TEST_OUTPUT_DIR))) gapic_yaml = os.path.join(TEST_DIR, 'library_gapic.yaml') # TODO: make this path configurable include_dirs = ['.', './googleapis'] From 2c9116a35eb4187f4426a63f0713be9e39e2d48d Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 15 Mar 2019 10:58:04 -0700 Subject: [PATCH 14/30] put changes back in --- plugin/templates/resource_name.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin/templates/resource_name.py b/plugin/templates/resource_name.py index bac3c01..a5412ca 100644 --- a/plugin/templates/resource_name.py +++ b/plugin/templates/resource_name.py @@ -30,6 +30,7 @@ import os from plugin.utils import path_template from plugin.utils import casing_utils +from plugin.utils.symbol_table import SymbolTable RESOURCE_NAMES_GLOBAL_PACKAGE_JAVA = 'com.google.api.resourcenames' @@ -59,6 +60,7 @@ def package(self): class ResourceName(ResourceNameBase): def __init__(self, collection_config, java_package, oneof): + symbol_table = SymbolTable() entity_name = collection_config.java_entity_name name_template = path_template.PathTemplate( @@ -92,7 +94,7 @@ def __init__(self, collection_config, java_package, oneof): self.parameter_list[-1]['not_last'] = False self.format_fields = [{ 'upper': casing_utils.lower_camel_to_upper_camel(f['parameter']), - 'lower': f['parameter'], + 'lower': symbol_table.getNewSymbol(f['parameter']), } for f in self.parameter_list] self.format_string = collection_config.name_pattern self.package_name = java_package From 76e3856867d58ab8861ec77296e97cb32430a1af Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 15 Mar 2019 11:01:16 -0700 Subject: [PATCH 15/30] cleanup --- test/test_plugin_baseline.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/test_plugin_baseline.py b/test/test_plugin_baseline.py index 1b7a786..c7d0540 100644 --- a/test/test_plugin_baseline.py +++ b/test/test_plugin_baseline.py @@ -75,7 +75,7 @@ def format_output_arg(name, output_dir, extra_arg=None): try: subprocess.check_call(args) except subprocess.CalledProcessError as exc: - stderr.write("Status : FAIL, return code %s, message %s" % (exc.returncode, exc.output)) + stderr.write("Status : FAIL, message %s" % exc.output) def clean_test_output(): @@ -86,8 +86,6 @@ def clean_test_output(): @pytest.fixture(scope='class') def run_protoc(): clean_test_output() - assert(os.path.isdir(TEST_OUTPUT_DIR)) - stderr.write("LKSDJFLKSDJFLKSDJF:LKSJF\n\n\n\nn\\nskfjlskdjflksdjf;" + str(os.path.isdir(TEST_OUTPUT_DIR))) gapic_yaml = os.path.join(TEST_DIR, 'library_gapic.yaml') # TODO: make this path configurable include_dirs = ['.', './googleapis'] From 272c1544bcb3e29e0c63635ef69a53315c0b31ea Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 15 Mar 2019 11:08:04 -0700 Subject: [PATCH 16/30] made baseline as expected --- test/testdata/java_archived_book_name.baseline | 4 ++-- test/testdata/java_shelf_book_name.baseline | 12 ++++++------ test/testdata/java_shelf_name.baseline | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/testdata/java_archived_book_name.baseline b/test/testdata/java_archived_book_name.baseline index 47124ef..5416a2a 100644 --- a/test/testdata/java_archived_book_name.baseline +++ b/test/testdata/java_archived_book_name.baseline @@ -55,14 +55,14 @@ public class ArchivedBookName extends BookName { bookId = Preconditions.checkNotNull(builder.getBookId()); } - public static ArchivedBookName of(String archiveId, String bookId) { + public static ArchivedBookName of(String , String ) { return newBuilder() .setArchiveId(archiveId) .setBookId(bookId) .build(); } - public static String format(String archiveId, String bookId) { + public static String format(String , String ) { return newBuilder() .setArchiveId(archiveId) .setBookId(bookId) diff --git a/test/testdata/java_shelf_book_name.baseline b/test/testdata/java_shelf_book_name.baseline index bca3e6a..27cfbb1 100644 --- a/test/testdata/java_shelf_book_name.baseline +++ b/test/testdata/java_shelf_book_name.baseline @@ -27,7 +27,7 @@ import java.util.List; public class ShelfBookName extends BookName { private static final PathTemplate PATH_TEMPLATE = - PathTemplate.createWithoutUrlEncoding("shelves/{shelf_id}/books/{return}"); + PathTemplate.createWithoutUrlEncoding("shelves/{shelf_id}/books/{return2}"); private volatile Map fieldValuesMap; @@ -55,14 +55,14 @@ public class ShelfBookName extends BookName { return2 = Preconditions.checkNotNull(builder.getReturn()); } - public static ShelfBookName of(String shelfId, String return) { + public static ShelfBookName of(String , String ) { return newBuilder() .setShelfId(shelfId) .setReturn(return2) .build(); } - public static String format(String shelfId, String return) { + public static String format(String , String ) { return newBuilder() .setShelfId(shelfId) .setReturn(return2) @@ -76,7 +76,7 @@ public class ShelfBookName extends BookName { } Map matchMap = PATH_TEMPLATE.validatedMatch(formattedString, "ShelfBookName.parse: formattedString not in valid format"); - return of(matchMap.get("shelf_id"), matchMap.get("return")); + return of(matchMap.get("shelf_id"), matchMap.get("return2")); } public static List parseList(List formattedStrings) { @@ -123,7 +123,7 @@ public class ShelfBookName extends BookName { @Override public String toString() { - return PATH_TEMPLATE.instantiate("shelf_id", shelfId, "return", return); + return PATH_TEMPLATE.instantiate("shelf_id", shelfId, "return", return2); } /** Builder for ShelfBookName. */ @@ -171,7 +171,7 @@ public class ShelfBookName extends BookName { if (o instanceof ShelfBookName) { ShelfBookName that = (ShelfBookName) o; return (this.shelfId.equals(that.shelfId)) - && (this.return.equals(that.return)); + && (this.return2.equals(that.return2)); } return false; } diff --git a/test/testdata/java_shelf_name.baseline b/test/testdata/java_shelf_name.baseline index 4ed2fe9..8437d96 100644 --- a/test/testdata/java_shelf_name.baseline +++ b/test/testdata/java_shelf_name.baseline @@ -49,13 +49,13 @@ public class ShelfName implements ResourceName { shelfId = Preconditions.checkNotNull(builder.getShelfId()); } - public static ShelfName of(String shelfId) { + public static ShelfName of(String ) { return newBuilder() .setShelfId(shelfId) .build(); } - public static String format(String shelfId) { + public static String format(String ) { return newBuilder() .setShelfId(shelfId) .build() From 013496d659d6dc5442c8e81409f0c7b2de890055 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 15 Mar 2019 11:10:40 -0700 Subject: [PATCH 17/30] use set literal --- plugin/utils/symbol_table.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/utils/symbol_table.py b/plugin/utils/symbol_table.py index 0a1a8c4..0895fb6 100644 --- a/plugin/utils/symbol_table.py +++ b/plugin/utils/symbol_table.py @@ -54,7 +54,7 @@ def getNewSymbol(self, desired_name): return desired_name + str(i) -java_reserved_symbols = set([ +java_reserved_symbols = { "abstract", "assert", "boolean", @@ -107,4 +107,4 @@ def getNewSymbol(self, desired_name): "try", "void", "volatile", - "while"]) + "while"} From 1e8edb84b6a51163e5284ed2de6a96d5aa640854 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 15 Mar 2019 11:12:09 -0700 Subject: [PATCH 18/30] using underscores instead of numbers --- plugin/utils/symbol_table.py | 9 +++-- .../testdata/java_archived_book_name.baseline | 4 +-- test/testdata/java_shelf_book_name.baseline | 34 +++++++++---------- test/testdata/java_shelf_name.baseline | 4 +-- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/plugin/utils/symbol_table.py b/plugin/utils/symbol_table.py index 0895fb6..fee8d58 100644 --- a/plugin/utils/symbol_table.py +++ b/plugin/utils/symbol_table.py @@ -47,11 +47,10 @@ def getNewSymbol(self, desired_name): self.symbol_table.add(desired_name) return desired_name - # Resolve collisions with a numeric suffix, starting with 2. - i = 2 - while (desired_name + str(i)) in self.symbol_table: - self.symbol_table.add(desired_name + str(i)) - return desired_name + str(i) + # Resolve collisions with one or more underscores. + while (desired_name + "_") in self.symbol_table: + self.symbol_table.add(desired_name + "_") + return desired_name + "_" java_reserved_symbols = { diff --git a/test/testdata/java_archived_book_name.baseline b/test/testdata/java_archived_book_name.baseline index 5416a2a..47124ef 100644 --- a/test/testdata/java_archived_book_name.baseline +++ b/test/testdata/java_archived_book_name.baseline @@ -55,14 +55,14 @@ public class ArchivedBookName extends BookName { bookId = Preconditions.checkNotNull(builder.getBookId()); } - public static ArchivedBookName of(String , String ) { + public static ArchivedBookName of(String archiveId, String bookId) { return newBuilder() .setArchiveId(archiveId) .setBookId(bookId) .build(); } - public static String format(String , String ) { + public static String format(String archiveId, String bookId) { return newBuilder() .setArchiveId(archiveId) .setBookId(bookId) diff --git a/test/testdata/java_shelf_book_name.baseline b/test/testdata/java_shelf_book_name.baseline index 27cfbb1..e6e9ffb 100644 --- a/test/testdata/java_shelf_book_name.baseline +++ b/test/testdata/java_shelf_book_name.baseline @@ -27,19 +27,19 @@ import java.util.List; public class ShelfBookName extends BookName { private static final PathTemplate PATH_TEMPLATE = - PathTemplate.createWithoutUrlEncoding("shelves/{shelf_id}/books/{return2}"); + PathTemplate.createWithoutUrlEncoding("shelves/{shelf_id}/books/{return}"); private volatile Map fieldValuesMap; private final String shelfId; - private final String return2; + private final String return_; public String getShelfId() { return shelfId; } public String getReturn() { - return return2; + return return_; } public static Builder newBuilder() { @@ -52,20 +52,20 @@ public class ShelfBookName extends BookName { private ShelfBookName(Builder builder) { shelfId = Preconditions.checkNotNull(builder.getShelfId()); - return2 = Preconditions.checkNotNull(builder.getReturn()); + return_ = Preconditions.checkNotNull(builder.getReturn()); } - public static ShelfBookName of(String , String ) { + public static ShelfBookName of(String shelfId, String return) { return newBuilder() .setShelfId(shelfId) - .setReturn(return2) + .setReturn(return_) .build(); } - public static String format(String , String ) { + public static String format(String shelfId, String return) { return newBuilder() .setShelfId(shelfId) - .setReturn(return2) + .setReturn(return_) .build() .toString(); } @@ -76,7 +76,7 @@ public class ShelfBookName extends BookName { } Map matchMap = PATH_TEMPLATE.validatedMatch(formattedString, "ShelfBookName.parse: formattedString not in valid format"); - return of(matchMap.get("shelf_id"), matchMap.get("return2")); + return of(matchMap.get("shelf_id"), matchMap.get("return")); } public static List parseList(List formattedStrings) { @@ -109,7 +109,7 @@ public class ShelfBookName extends BookName { if (fieldValuesMap == null) { ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); fieldMapBuilder.put("shelfId", shelfId); - fieldMapBuilder.put("return2", return2); + fieldMapBuilder.put("return_", return_); fieldValuesMap = fieldMapBuilder.build(); } } @@ -123,21 +123,21 @@ public class ShelfBookName extends BookName { @Override public String toString() { - return PATH_TEMPLATE.instantiate("shelf_id", shelfId, "return", return2); + return PATH_TEMPLATE.instantiate("shelf_id", shelfId, "return", return); } /** Builder for ShelfBookName. */ public static class Builder { private String shelfId; - private String return2; + private String return_; public String getShelfId() { return shelfId; } public String getReturn() { - return return2; + return return_; } public Builder setShelfId(String shelfId) { @@ -145,8 +145,8 @@ public class ShelfBookName extends BookName { return this; } - public Builder setReturn(String return2) { - this.return2 = return2; + public Builder setReturn(String return_) { + this.return_ = return_; return this; } @@ -155,7 +155,7 @@ public class ShelfBookName extends BookName { private Builder(ShelfBookName shelfBookName) { shelfId = shelfBookName.shelfId; - return2 = shelfBookName.return2; + return_ = shelfBookName.return_; } public ShelfBookName build() { @@ -171,7 +171,7 @@ public class ShelfBookName extends BookName { if (o instanceof ShelfBookName) { ShelfBookName that = (ShelfBookName) o; return (this.shelfId.equals(that.shelfId)) - && (this.return2.equals(that.return2)); + && (this.return.equals(that.return)); } return false; } diff --git a/test/testdata/java_shelf_name.baseline b/test/testdata/java_shelf_name.baseline index 8437d96..4ed2fe9 100644 --- a/test/testdata/java_shelf_name.baseline +++ b/test/testdata/java_shelf_name.baseline @@ -49,13 +49,13 @@ public class ShelfName implements ResourceName { shelfId = Preconditions.checkNotNull(builder.getShelfId()); } - public static ShelfName of(String ) { + public static ShelfName of(String shelfId) { return newBuilder() .setShelfId(shelfId) .build(); } - public static String format(String ) { + public static String format(String shelfId) { return newBuilder() .setShelfId(shelfId) .build() From 1f95c14ea05cfdda0071d892554e7bd05ccc7bcb Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 15 Mar 2019 11:13:23 -0700 Subject: [PATCH 19/30] made baseline what is expected --- test/testdata/java_shelf_book_name.baseline | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/testdata/java_shelf_book_name.baseline b/test/testdata/java_shelf_book_name.baseline index e6e9ffb..67f4631 100644 --- a/test/testdata/java_shelf_book_name.baseline +++ b/test/testdata/java_shelf_book_name.baseline @@ -55,14 +55,14 @@ public class ShelfBookName extends BookName { return_ = Preconditions.checkNotNull(builder.getReturn()); } - public static ShelfBookName of(String shelfId, String return) { + public static ShelfBookName of(String shelfId, String return_) { return newBuilder() .setShelfId(shelfId) .setReturn(return_) .build(); } - public static String format(String shelfId, String return) { + public static String format(String shelfId, String return_) { return newBuilder() .setShelfId(shelfId) .setReturn(return_) @@ -123,7 +123,7 @@ public class ShelfBookName extends BookName { @Override public String toString() { - return PATH_TEMPLATE.instantiate("shelf_id", shelfId, "return", return); + return PATH_TEMPLATE.instantiate("shelf_id", shelfId, "return", return_); } /** Builder for ShelfBookName. */ @@ -171,7 +171,7 @@ public class ShelfBookName extends BookName { if (o instanceof ShelfBookName) { ShelfBookName that = (ShelfBookName) o; return (this.shelfId.equals(that.shelfId)) - && (this.return.equals(that.return)); + && (this.return_.equals(that.return_)); } return false; } From 682856f828fc897f302a81e52a1153979ed2d772 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 15 Mar 2019 11:22:47 -0700 Subject: [PATCH 20/30] formatting --- plugin/templates/resource_name.py | 8 +++++--- test/testdata/java_shelf_book_name.baseline | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/plugin/templates/resource_name.py b/plugin/templates/resource_name.py index a5412ca..f8d4816 100644 --- a/plugin/templates/resource_name.py +++ b/plugin/templates/resource_name.py @@ -85,7 +85,8 @@ def __init__(self, collection_config, java_package, oneof): self.parent_interface = 'ResourceName' self.extension_keyword = 'implements' self.parameter_list = [{ - 'parameter': casing_utils.lower_underscore_to_lower_camel(lit), + 'parameter': symbol_table.getNewSymbol( + casing_utils.lower_underscore_to_lower_camel(lit)), 'parameter_name': lit, 'not_first': True, 'not_last': True, @@ -93,8 +94,9 @@ def __init__(self, collection_config, java_package, oneof): self.parameter_list[0]['not_first'] = False self.parameter_list[-1]['not_last'] = False self.format_fields = [{ - 'upper': casing_utils.lower_camel_to_upper_camel(f['parameter']), - 'lower': symbol_table.getNewSymbol(f['parameter']), + 'upper': casing_utils.lower_underscore_to_upper_camel( + f['parameter_name']), + 'lower': f['parameter'], } for f in self.parameter_list] self.format_string = collection_config.name_pattern self.package_name = java_package diff --git a/test/testdata/java_shelf_book_name.baseline b/test/testdata/java_shelf_book_name.baseline index 67f4631..b35bde0 100644 --- a/test/testdata/java_shelf_book_name.baseline +++ b/test/testdata/java_shelf_book_name.baseline @@ -182,7 +182,7 @@ public class ShelfBookName extends BookName { h *= 1000003; h ^= shelfId.hashCode(); h *= 1000003; - h ^= return.hashCode(); + h ^= return_.hashCode(); return h; } } From e902c2c85e80bfc79702299651ddb7f47c8515f4 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 15 Mar 2019 11:34:28 -0700 Subject: [PATCH 21/30] leave fieldmap as is --- plugin/templates/resource_name.mustache | 2 +- plugin/templates/resource_name.py | 1 + test/testdata/java_shelf_book_name.baseline | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin/templates/resource_name.mustache b/plugin/templates/resource_name.mustache index f93291d..ba462a4 100644 --- a/plugin/templates/resource_name.mustache +++ b/plugin/templates/resource_name.mustache @@ -107,7 +107,7 @@ public class {{className}} {{extensionKeyword}} {{parentInterface}} { if (fieldValuesMap == null) { ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); {{#formatFields}} - fieldMapBuilder.put("{{lower}}", {{lower}}); + fieldMapBuilder.put("{{parameter_name}}", {{lower}}); {{/formatFields}} fieldValuesMap = fieldMapBuilder.build(); } diff --git a/plugin/templates/resource_name.py b/plugin/templates/resource_name.py index f8d4816..5db0279 100644 --- a/plugin/templates/resource_name.py +++ b/plugin/templates/resource_name.py @@ -97,6 +97,7 @@ def __init__(self, collection_config, java_package, oneof): 'upper': casing_utils.lower_underscore_to_upper_camel( f['parameter_name']), 'lower': f['parameter'], + 'parameter_name': casing_utils.lower_underscore_to_lower_camel(f['parameter_name']), } for f in self.parameter_list] self.format_string = collection_config.name_pattern self.package_name = java_package diff --git a/test/testdata/java_shelf_book_name.baseline b/test/testdata/java_shelf_book_name.baseline index b35bde0..7e4fa44 100644 --- a/test/testdata/java_shelf_book_name.baseline +++ b/test/testdata/java_shelf_book_name.baseline @@ -109,7 +109,7 @@ public class ShelfBookName extends BookName { if (fieldValuesMap == null) { ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); fieldMapBuilder.put("shelfId", shelfId); - fieldMapBuilder.put("return_", return_); + fieldMapBuilder.put("return", return_); fieldValuesMap = fieldMapBuilder.build(); } } From a0dc7b7d0ea8e2dc26e0049a08edb49a9a68a249 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 15 Mar 2019 11:43:54 -0700 Subject: [PATCH 22/30] make parameter_name_in_map more explicit --- plugin/templates/resource_name.mustache | 2 +- plugin/templates/resource_name.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/templates/resource_name.mustache b/plugin/templates/resource_name.mustache index ba462a4..ea3e023 100644 --- a/plugin/templates/resource_name.mustache +++ b/plugin/templates/resource_name.mustache @@ -107,7 +107,7 @@ public class {{className}} {{extensionKeyword}} {{parentInterface}} { if (fieldValuesMap == null) { ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); {{#formatFields}} - fieldMapBuilder.put("{{parameter_name}}", {{lower}}); + fieldMapBuilder.put("{{parameter_name_in_map}}", {{lower}}); {{/formatFields}} fieldValuesMap = fieldMapBuilder.build(); } diff --git a/plugin/templates/resource_name.py b/plugin/templates/resource_name.py index 5db0279..952b9c5 100644 --- a/plugin/templates/resource_name.py +++ b/plugin/templates/resource_name.py @@ -97,7 +97,7 @@ def __init__(self, collection_config, java_package, oneof): 'upper': casing_utils.lower_underscore_to_upper_camel( f['parameter_name']), 'lower': f['parameter'], - 'parameter_name': casing_utils.lower_underscore_to_lower_camel(f['parameter_name']), + 'parameter_name_in_map': casing_utils.lower_underscore_to_lower_camel(f['parameter_name']), } for f in self.parameter_list] self.format_string = collection_config.name_pattern self.package_name = java_package From d4564c2829b05a98ed0176724ac9414c84e109a4 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 15 Mar 2019 11:45:25 -0700 Subject: [PATCH 23/30] formatting --- plugin/templates/resource_name.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin/templates/resource_name.py b/plugin/templates/resource_name.py index 952b9c5..dd2f992 100644 --- a/plugin/templates/resource_name.py +++ b/plugin/templates/resource_name.py @@ -97,7 +97,9 @@ def __init__(self, collection_config, java_package, oneof): 'upper': casing_utils.lower_underscore_to_upper_camel( f['parameter_name']), 'lower': f['parameter'], - 'parameter_name_in_map': casing_utils.lower_underscore_to_lower_camel(f['parameter_name']), + 'parameter_name_in_map': + casing_utils.lower_underscore_to_lower_camel( + f['parameter_name']), } for f in self.parameter_list] self.format_string = collection_config.name_pattern self.package_name = java_package From 10fba4c3a3ebafa532d3f7906feb4715ff151a16 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 15 Mar 2019 11:57:43 -0700 Subject: [PATCH 24/30] update pyyaml and protobuf --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 2fd72b2..de59084 100644 --- a/setup.py +++ b/setup.py @@ -41,9 +41,9 @@ install_requires = [ 'pystache >= 0.5.4', - 'protobuf >= 3.3', + 'protobuf >= 3.6', 'google-gax >= 0.12.3', - 'pyyaml >= 3.12', + 'pyyaml >= 3.13', ] setup( From 2cbfbe440705aa7fccae7d75e575c5b9b0610a99 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 15 Mar 2019 12:07:18 -0700 Subject: [PATCH 25/30] use load() again --- plugin/utils/gapic_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/utils/gapic_utils.py b/plugin/utils/gapic_utils.py index 880c755..ec01d59 100644 --- a/plugin/utils/gapic_utils.py +++ b/plugin/utils/gapic_utils.py @@ -34,7 +34,7 @@ def read_from_gapic_yaml(yaml_file): with open(yaml_file) as f: - gapic_yaml = yaml.full_load(f) + gapic_yaml = yaml.load(f, Loader=yaml.FullLoader) collections = {} if 'collections' in gapic_yaml: From 4aa12c734e26f8b1a58c2f9b1ef511bb5b1486ba Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 15 Mar 2019 12:35:25 -0700 Subject: [PATCH 26/30] fix symbol_table and add a test --- plugin/utils/symbol_table.py | 2 ++ test/test_symbol_table.py | 43 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 test/test_symbol_table.py diff --git a/plugin/utils/symbol_table.py b/plugin/utils/symbol_table.py index fee8d58..109d54f 100644 --- a/plugin/utils/symbol_table.py +++ b/plugin/utils/symbol_table.py @@ -50,6 +50,8 @@ def getNewSymbol(self, desired_name): # Resolve collisions with one or more underscores. while (desired_name + "_") in self.symbol_table: self.symbol_table.add(desired_name + "_") + desired_name = desired_name + "_" + self.symbol_table.add(desired_name + "_") return desired_name + "_" diff --git a/test/test_symbol_table.py b/test/test_symbol_table.py new file mode 100644 index 0000000..a7a2954 --- /dev/null +++ b/test/test_symbol_table.py @@ -0,0 +1,43 @@ +# Copyright 2019 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from plugin.utils.symbol_table import SymbolTable + + +def test_symbol_table(): + table = SymbolTable() + + # Escape a key word once + keyword = "interface" + escaped_keyword = table.getNewSymbol(keyword) + assert escaped_keyword == "interface_" + assert keyword == "interface" + + # Escape a key word twice + assert table.getNewSymbol("interface") == "interface__" + + # Add a non-keyword + assert table.getNewSymbol("bridge") == "bridge" + # Escape the same non-keyword + assert table.getNewSymbol("bridge") == "bridge_" + + # Escape a keyword that already has an underscore + assert table.getNewSymbol("class_") == "class_" + assert table.getNewSymbol("class") == "class__" + assert table.getNewSymbol("class_") == "class___" + + # Make sure that a new instance of SymbolTable uses a different base set + new_table = SymbolTable() + assert new_table.getNewSymbol("interface") == "interface_" + From e593ac5b537f6e49e61e6f1a5c5fb382291bb0db Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 15 Mar 2019 12:35:54 -0700 Subject: [PATCH 27/30] formatting --- test/test_symbol_table.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_symbol_table.py b/test/test_symbol_table.py index a7a2954..f6d3fe7 100644 --- a/test/test_symbol_table.py +++ b/test/test_symbol_table.py @@ -40,4 +40,3 @@ def test_symbol_table(): # Make sure that a new instance of SymbolTable uses a different base set new_table = SymbolTable() assert new_table.getNewSymbol("interface") == "interface_" - From 774bb9246b9c81eec189805e938391dfda917ccf Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 15 Mar 2019 13:11:41 -0700 Subject: [PATCH 28/30] revert the pyyaml stuff --- plugin/utils/gapic_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/utils/gapic_utils.py b/plugin/utils/gapic_utils.py index ec01d59..4744bc6 100644 --- a/plugin/utils/gapic_utils.py +++ b/plugin/utils/gapic_utils.py @@ -34,7 +34,7 @@ def read_from_gapic_yaml(yaml_file): with open(yaml_file) as f: - gapic_yaml = yaml.load(f, Loader=yaml.FullLoader) + gapic_yaml = yaml.load(f) collections = {} if 'collections' in gapic_yaml: From 00dfd0e5958643f579c60425b78a9e2aa98469c8 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Fri, 15 Mar 2019 13:12:09 -0700 Subject: [PATCH 29/30] revert pyyaml change --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index de59084..98f1948 100644 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ 'pystache >= 0.5.4', 'protobuf >= 3.6', 'google-gax >= 0.12.3', - 'pyyaml >= 3.13', + 'pyyaml >= 3.12', ] setup( From 8f238b58846ccf14b52d8f8621649993abc25752 Mon Sep 17 00:00:00 2001 From: Andrea Lin Date: Mon, 18 Mar 2019 15:02:02 -0700 Subject: [PATCH 30/30] removed extraneous line --- plugin/utils/symbol_table.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin/utils/symbol_table.py b/plugin/utils/symbol_table.py index 109d54f..8702d28 100644 --- a/plugin/utils/symbol_table.py +++ b/plugin/utils/symbol_table.py @@ -49,7 +49,6 @@ def getNewSymbol(self, desired_name): # Resolve collisions with one or more underscores. while (desired_name + "_") in self.symbol_table: - self.symbol_table.add(desired_name + "_") desired_name = desired_name + "_" self.symbol_table.add(desired_name + "_") return desired_name + "_"