Skip to content

Commit

Permalink
[ggj][codegen] fix: init remaining resname tokenVars to null (#329)
Browse files Browse the repository at this point in the history
* feat: add protobuf comment parser util

* fix: add basic proto build rules

* feat: add header comments to ServiceClient

* fix: build protoc at test time

* fix!: wrap protobuf location and process comments

* feat: add comment parsing to methods and fields

* fix: test

* feat: add protobuf comments to ServiceClient

* fix: solidify codegen method order with TypeNode/MethodArg and Comparable

* fix: clean up tests

* fix: ServiceClient member variables and method calls

* fix: ServiceStubSettings builder type

* fix: ServiceSettings Builder construction

* fix: ServiceStub callable types

* feat: java_gapic_library rule impl

* fix: remove debugging comments

* feat: add gradle assembly Bazel rules

* feat: add java_gapic_test Bazel rule

* fix: use Java packages for resname codegen

* fix: build resnames separately and extract into proto/ dir

* fix: remove debug printf

* feat: add ServiceClient.MethodPagedResponse inner class

* feat: add ServiceClient.MethodPage inner class

* feat: add ServiceClient.MethodFixedSizeCollection innser class

* fix: clean up resname codegen, lower_snake varnames

* fix: init remaining resname tokenVars to null
  • Loading branch information
miraleung authored Sep 19, 2020
1 parent b05d1d8 commit 78d51fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,18 @@ private static List<MethodDefinition> createConstructorMethods(
.setValueExpr(checkNotNullExpr)
.build());
}
// Initialize the rest to null.
ValueExpr nullExpr = ValueExpr.withValue(NullObjectValue.create());
for (String token : getTokenSet(tokenHierarchies)) {
if (tokens.contains(token)) {
continue;
}
bodyExprs.add(
AssignmentExpr.builder()
.setVariableExpr(patternTokenVarExprs.get(token))
.setValueExpr(nullExpr)
.build());
}

if (hasVariants) {
AssignmentExpr pathTemplateAssignExpr =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,24 +245,32 @@ public void generateResourceNameClass_testingSessionOnePattern() {
+ " private FoobarName(Builder builder) {\n"
+ " project = Preconditions.checkNotNull(builder.getProject());\n"
+ " foobar = Preconditions.checkNotNull(builder.getFoobar());\n"
+ " variant = null;\n"
+ " barFoo = null;\n"
+ " pathTemplate = PROJECT_FOOBAR;\n"
+ " }\n"
+ "\n"
+ " private FoobarName(ProjectVariantFoobarBuilder builder) {\n"
+ " project = Preconditions.checkNotNull(builder.getProject());\n"
+ " variant = Preconditions.checkNotNull(builder.getVariant());\n"
+ " foobar = Preconditions.checkNotNull(builder.getFoobar());\n"
+ " barFoo = null;\n"
+ " pathTemplate = PROJECT_VARIANT_FOOBAR;\n"
+ " }\n"
+ "\n"
+ " private FoobarName(FoobarBuilder builder) {\n"
+ " foobar = Preconditions.checkNotNull(builder.getFoobar());\n"
+ " project = null;\n"
+ " variant = null;\n"
+ " barFoo = null;\n"
+ " pathTemplate = FOOBAR;\n"
+ " }\n"
+ "\n"
+ " private FoobarName(BarFooFoobarBuilder builder) {\n"
+ " barFoo = Preconditions.checkNotNull(builder.getBarFoo());\n"
+ " foobar = Preconditions.checkNotNull(builder.getFoobar());\n"
+ " project = null;\n"
+ " variant = null;\n"
+ " pathTemplate = BAR_FOO_FOOBAR;\n"
+ " }\n"
+ "\n"
Expand Down

0 comments on commit 78d51fe

Please sign in to comment.