Skip to content

Commit

Permalink
[ggj][codegen] fix: robustify name-based var-retrieval in GrpcService…
Browse files Browse the repository at this point in the history
…Stub (#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
  • Loading branch information
miraleung authored Nov 25, 2020
1 parent ade36dc commit e0e1dea
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -836,10 +836,24 @@ private static Expr createCallableInitExpr(
}
String javaStyleMethodName = callableVarName.substring(0, callableVarName.length() - sublength);
List<Expr> 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))
Expand All @@ -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))
Expand Down

0 comments on commit e0e1dea

Please sign in to comment.