Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -126,8 +132,7 @@ protected Statement createMethodDescriptorVariableDecl(
return ExprStatement.withExpr(
AssignmentExpr.builder()
.setVariableExpr(
methodDescriptorVarExpr
.toBuilder()
methodDescriptorVarExpr.toBuilder()
.setIsDecl(true)
.setScope(ScopeNode.PRIVATE)
.setIsStatic(true)
Expand Down Expand Up @@ -327,6 +332,38 @@ private List<Expr> getRequestFormatterExpr(Method protoMethod) {
return Collections.singletonList(expr);
}

private List<Expr> 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<Expr> setResponseParserExpr(Method protoMethod) {
BiFunction<String, List<Expr>, Function<MethodInvocationExpr, MethodInvocationExpr>>
methodMaker = getMethodMaker();
Expand Down