From e0e1dead4caab8bdf88a78bb9ab48a3573eceae6 Mon Sep 17 00:00:00 2001 From: Mira Leung Date: Tue, 24 Nov 2020 17:19:49 -0800 Subject: [PATCH] [ggj][codegen] fix: robustify name-based var-retrieval in GrpcServiceStub (#567) * fix: handle wildcard-typed resrefs when parsing methods * fix: support older type-only resrefs w/o a service prefix * feat: allow example/library to lack the grpc_config file * fix: robustify name-based var-retrieval in GrpcServiceStub --- .../composer/GrpcServiceStubClassComposer.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/google/api/generator/gapic/composer/GrpcServiceStubClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/GrpcServiceStubClassComposer.java index 93f506c824..a8628a4131 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/GrpcServiceStubClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/GrpcServiceStubClassComposer.java @@ -836,10 +836,24 @@ private static Expr createCallableInitExpr( } String javaStyleMethodName = callableVarName.substring(0, callableVarName.length() - sublength); List creatorMethodArgVarExprs = null; + Expr transportSettingsVarExpr = + javaStyleMethodNameToTransportSettingsVarExprs.get(javaStyleMethodName); + if (transportSettingsVarExpr == null && isOperation) { + // Try again, in case the name dtection above was inaccurate. + isOperation = false; + sublength = CALLABLE_NAME.length(); + javaStyleMethodName = callableVarName.substring(0, callableVarName.length() - sublength); + transportSettingsVarExpr = + javaStyleMethodNameToTransportSettingsVarExprs.get(javaStyleMethodName); + } + Preconditions.checkNotNull( + transportSettingsVarExpr, + String.format( + "No transport settings variable found for method name %s", javaStyleMethodName)); if (isOperation) { creatorMethodArgVarExprs = Arrays.asList( - javaStyleMethodNameToTransportSettingsVarExprs.get(javaStyleMethodName), + transportSettingsVarExpr, MethodInvocationExpr.builder() .setExprReferenceExpr(settingsVarExpr) .setMethodName(String.format("%sOperationSettings", javaStyleMethodName)) @@ -849,7 +863,7 @@ private static Expr createCallableInitExpr( } else { creatorMethodArgVarExprs = Arrays.asList( - javaStyleMethodNameToTransportSettingsVarExprs.get(javaStyleMethodName), + transportSettingsVarExpr, MethodInvocationExpr.builder() .setExprReferenceExpr(settingsVarExpr) .setMethodName(String.format("%sSettings", javaStyleMethodName))