Skip to content

Commit

Permalink
[ggj][codegen] fix: ServiceStubSettings paged descriptor rep. field g…
Browse files Browse the repository at this point in the history
…etter name (#330)

* 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

* fix: ServiceStubSettings paged descriptor rep. field getter name
  • Loading branch information
miraleung authored Sep 19, 2020
1 parent 78d51fe commit 7ff5375
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ private static List<Expr> createPagingStaticAssignExprs(
"No method found for message type %s for method %s among %s",
pagedResponseMessageKey, method.name(), messageTypes.keySet()));
TypeNode repeatedResponseType = null;
String repeatedFieldName = null;
for (Field field : pagedResponseMessage.fields()) {
Preconditions.checkState(
field != null,
Expand All @@ -360,6 +361,7 @@ private static List<Expr> createPagingStaticAssignExprs(
!field.type().reference().generics().isEmpty(),
String.format("No generics found for field reference %s", field.type().reference()));
repeatedResponseType = TypeNode.withReference(field.type().reference().generics().get(0));
repeatedFieldName = field.name();
}
}
Preconditions.checkNotNull(
Expand Down Expand Up @@ -387,7 +389,12 @@ private static List<Expr> createPagingStaticAssignExprs(

descExprs.add(
createPagedListDescriptorAssignExpr(
pagedListDescVarExpr, method, repeatedResponseType, types));
pagedListDescVarExpr,
method,
repeatedResponseType,
repeatedFieldName,
messageTypes,
types));
factoryExprs.add(
createPagedListResponseFactoryAssignExpr(
pagedListDescVarExpr, method, repeatedResponseType, types));
Expand All @@ -401,6 +408,8 @@ private static Expr createPagedListDescriptorAssignExpr(
VariableExpr pagedListDescVarExpr,
Method method,
TypeNode repeatedResponseType,
String repeatedFieldName,
Map<String, Message> messageTypes,
Map<String, TypeNode> types) {
MethodDefinition.Builder methodStarterBuilder =
MethodDefinition.builder().setIsOverride(true).setScope(ScopeNode.PUBLIC);
Expand Down Expand Up @@ -524,7 +533,8 @@ private static Expr createPagedListDescriptorAssignExpr(
Expr getResponsesListExpr =
MethodInvocationExpr.builder()
.setExprReferenceExpr(payloadVarExpr)
.setMethodName("getResponsesList")
.setMethodName(
String.format("get%sList", JavaStyle.toUpperCamelCase(repeatedFieldName)))
.setReturnType(returnType)
.build();
Expr conditionExpr =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -878,9 +878,9 @@ private static List<Service> parseServices(
+ " @Override\n"
+ " public Iterable<LogEntry> extractResources(ListLogEntriesResponse"
+ " payload) {\n"
+ " return Objects.isNull(payload.getResponsesList())\n"
+ " return Objects.isNull(payload.getEntriesList())\n"
+ " ? ImmutableList.<LogEntry>of()\n"
+ " : payload.getResponsesList();\n"
+ " : payload.getEntriesList();\n"
+ " }\n"
+ " };\n"
+ " private static final PagedListDescriptor<\n"
Expand Down Expand Up @@ -928,9 +928,9 @@ private static List<Service> parseServices(
+ " @Override\n"
+ " public Iterable<MonitoredResourceDescriptor> extractResources(\n"
+ " ListMonitoredResourceDescriptorsResponse payload) {\n"
+ " return Objects.isNull(payload.getResponsesList())\n"
+ " return Objects.isNull(payload.getResourceDescriptorsList())\n"
+ " ? ImmutableList.<MonitoredResourceDescriptor>of()\n"
+ " : payload.getResponsesList();\n"
+ " : payload.getResourceDescriptorsList();\n"
+ " }\n"
+ " };\n"
+ " private static final PagedListDescriptor<ListLogsRequest, ListLogsResponse,"
Expand Down Expand Up @@ -968,9 +968,9 @@ private static List<Service> parseServices(
+ "\n"
+ " @Override\n"
+ " public Iterable<String> extractResources(ListLogsResponse payload) {\n"
+ " return Objects.isNull(payload.getResponsesList())\n"
+ " return Objects.isNull(payload.getLogNamesList())\n"
+ " ? ImmutableList.<String>of()\n"
+ " : payload.getResponsesList();\n"
+ " : payload.getLogNamesList();\n"
+ " }\n"
+ " };\n"
+ " private static final PagedListResponseFactory<\n"
Expand Down Expand Up @@ -1617,9 +1617,9 @@ private static List<Service> parseServices(
+ "\n"
+ " @Override\n"
+ " public Iterable<Topic> extractResources(ListTopicsResponse payload) {\n"
+ " return Objects.isNull(payload.getResponsesList())\n"
+ " return Objects.isNull(payload.getTopicsList())\n"
+ " ? ImmutableList.<Topic>of()\n"
+ " : payload.getResponsesList();\n"
+ " : payload.getTopicsList();\n"
+ " }\n"
+ " };\n"
+ " private static final PagedListDescriptor<\n"
Expand Down Expand Up @@ -1662,9 +1662,9 @@ private static List<Service> parseServices(
+ " @Override\n"
+ " public Iterable<String> extractResources(ListTopicSubscriptionsResponse"
+ " payload) {\n"
+ " return Objects.isNull(payload.getResponsesList())\n"
+ " return Objects.isNull(payload.getSubscriptionsList())\n"
+ " ? ImmutableList.<String>of()\n"
+ " : payload.getResponsesList();\n"
+ " : payload.getSubscriptionsList();\n"
+ " }\n"
+ " };\n"
+ " private static final PagedListDescriptor<\n"
Expand Down Expand Up @@ -1704,9 +1704,9 @@ private static List<Service> parseServices(
+ " @Override\n"
+ " public Iterable<String> extractResources(ListTopicSnapshotsResponse"
+ " payload) {\n"
+ " return Objects.isNull(payload.getResponsesList())\n"
+ " return Objects.isNull(payload.getSnapshotsList())\n"
+ " ? ImmutableList.<String>of()\n"
+ " : payload.getResponsesList();\n"
+ " : payload.getSnapshotsList();\n"
+ " }\n"
+ " };\n"
+ " private static final PagedListResponseFactory<\n"
Expand Down

0 comments on commit 7ff5375

Please sign in to comment.