From 6249d65c14ab56007280886dcea046488f6f1d05 Mon Sep 17 00:00:00 2001 From: Mira Leung Date: Thu, 29 Jul 2021 09:59:04 -0700 Subject: [PATCH] demo: Structure for HttpJsonServiceStubClassComposer DO NOT SUBMIT --- WORKSPACE | 14 ++++++- .../HttpJsonServiceStubClassComposer.java | 41 ++++++++++++++++++- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 7468b3246d..84d7af54e9 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -34,10 +34,20 @@ jvm_maven_import_external( # over the generator dependencies. _gax_java_version = "1.65.1" +""" +local_repository( + name = "com_google_api_gax_java", + path = "/usr/local/google/home/miraleung/dev/gax-java", +) +""" + +__temp_gax_java_hash = "4a4d7127305d26245acb94d6e3db974403ad1d47" + http_archive( name = "com_google_api_gax_java", - strip_prefix = "gax-java-%s" % _gax_java_version, - urls = ["https://github.com/googleapis/gax-java/archive/v%s.zip" % _gax_java_version], + strip_prefix = "gax-java-%s" % __temp_gax_java_hash, #_gax_java_version, + urls = ["https://github.com/googleapis/gax-java/archive/%s.zip" % __temp_gax_java_hash], + #urls = ["https://github.com/googleapis/gax-java/archive/v%s.zip" % _gax_java_version], ) load("@com_google_api_gax_java//:repository_rules.bzl", "com_google_api_gax_java_properties") diff --git a/src/main/java/com/google/api/generator/gapic/composer/rest/HttpJsonServiceStubClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/rest/HttpJsonServiceStubClassComposer.java index 1dbae8e302..a5eb9dbaca 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/rest/HttpJsonServiceStubClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/rest/HttpJsonServiceStubClassComposer.java @@ -20,6 +20,8 @@ import com.google.api.gax.httpjson.FieldsExtractor; import com.google.api.gax.httpjson.HttpJsonCallSettings; import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.OperationSnapshot; +import com.google.api.gax.httpjson.OperationSnapshotFactory; import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; import com.google.api.gax.httpjson.ProtoMessageResponseParser; import com.google.api.gax.httpjson.ProtoRestSerializer; @@ -115,6 +117,10 @@ protected Statement createMethodDescriptorVariableDecl( expr = methodMaker.apply("setRequestFormatter", getRequestFormatterExpr(protoMethod)).apply(expr); expr = methodMaker.apply("setResponseParser", setResponseParserExpr(protoMethod)).apply(expr); + expr = + methodMaker + .apply("setOperationSnapshotFactory", setOperationSnapshotFactoryExpr(protoMethod)) + .apply(expr); expr = MethodInvocationExpr.builder() @@ -126,8 +132,7 @@ protected Statement createMethodDescriptorVariableDecl( return ExprStatement.withExpr( AssignmentExpr.builder() .setVariableExpr( - methodDescriptorVarExpr - .toBuilder() + methodDescriptorVarExpr.toBuilder() .setIsDecl(true) .setScope(ScopeNode.PRIVATE) .setIsStatic(true) @@ -327,6 +332,38 @@ private List getRequestFormatterExpr(Method protoMethod) { return Collections.singletonList(expr); } + private List setOperationSnapshotFactoryExpr(Method protoMethod) { + TypeNode anonClassType = + TypeNode.withReference( + ConcreteReference.builder() + .setClazz(OperationSnapshotFactory.class) + .setGenerics( + protoMethod.inputType().reference(), protoMethod.outputType().reference()) + .build()); + + VariableExpr requestVarExpr = + VariableExpr.withVariable( + Variable.builder().setType(protoMethod.inputType()).setName("request").build()); + VariableExpr responseVarExpr = + VariableExpr.withVariable( + Variable.builder().setType(protoMethod.outputType()).setName("response").build()); + + MethodDefinition createMethod = + MethodDefinition.builder() + .setScope(ScopeNode.PUBLIC) + .setReturnType( + TypeNode.withReference( + ConcreteReference.builder().setClazz(OperationSnapshot.class))) + .setName("create") + .setArguments( + requestVarExpr.toBuilder().setIsDecl(true).build(), + responseVarExpr.toBuilder().setIsDecl(true).build()) + .setReturnExpr(ValueExpr.createNullExpr()) + .build(); + return Arrays.asList( + AnonymousClassExpr.builder().setType(anonClassType).setMethods(createMethod).build()); + } + private List setResponseParserExpr(Method protoMethod) { BiFunction, Function> methodMaker = getMethodMaker();