Search in sources :

Example 1 with ProtoUtils

use of io.grpc.protobuf.ProtoUtils in project gapic-generator-java by googleapis.

the class GrpcServiceStubClassComposer method createMethodDescriptorVariableDecl.

@Override
protected Statement createMethodDescriptorVariableDecl(Service service, Method protoMethod, VariableExpr methodDescriptorVarExpr, Map<String, Message> messageTypes) {
    MethodInvocationExpr methodDescriptorMaker = MethodInvocationExpr.builder().setMethodName("newBuilder").setStaticReferenceType(FIXED_GRPC_TYPE_STORE.get("MethodDescriptor")).setGenerics(methodDescriptorVarExpr.variable().type().reference().generics()).build();
    BiFunction<String, Expr, Function<MethodInvocationExpr, MethodInvocationExpr>> methodMakerFn = (mName, argExpr) -> m -> MethodInvocationExpr.builder().setMethodName(mName).setArguments(Arrays.asList(argExpr)).setExprReferenceExpr(m).build();
    methodDescriptorMaker = methodMakerFn.apply("setType", getMethodDescriptorMethodTypeExpr(protoMethod)).apply(methodDescriptorMaker);
    String codeMethodNameArg = getProtoRpcFullMethodName(service, protoMethod);
    methodDescriptorMaker = methodMakerFn.apply("setFullMethodName", ValueExpr.withValue(StringObjectValue.withValue(codeMethodNameArg))).apply(methodDescriptorMaker);
    Function<MethodInvocationExpr, MethodInvocationExpr> protoUtilsMarshallerFn = m -> MethodInvocationExpr.builder().setStaticReferenceType(FIXED_GRPC_TYPE_STORE.get("ProtoUtils")).setMethodName("marshaller").setArguments(Arrays.asList(m)).build();
    MethodInvocationExpr methodInvocationArg = MethodInvocationExpr.builder().setMethodName("getDefaultInstance").setStaticReferenceType(protoMethod.inputType()).build();
    methodDescriptorMaker = methodMakerFn.apply("setRequestMarshaller", protoUtilsMarshallerFn.apply(methodInvocationArg)).apply(methodDescriptorMaker);
    methodInvocationArg = MethodInvocationExpr.builder().setMethodName("getDefaultInstance").setStaticReferenceType(protoMethod.outputType()).build();
    methodDescriptorMaker = methodMakerFn.apply("setResponseMarshaller", protoUtilsMarshallerFn.apply(methodInvocationArg)).apply(methodDescriptorMaker);
    methodDescriptorMaker = MethodInvocationExpr.builder().setMethodName("build").setExprReferenceExpr(methodDescriptorMaker).setReturnType(methodDescriptorVarExpr.type()).build();
    return ExprStatement.withExpr(AssignmentExpr.builder().setVariableExpr(methodDescriptorVarExpr.toBuilder().setIsDecl(true).setScope(ScopeNode.PRIVATE).setIsStatic(true).setIsFinal(true).build()).setValueExpr(methodDescriptorMaker).build());
}
Also used : AbstractTransportServiceStubClassComposer(com.google.api.generator.gapic.composer.common.AbstractTransportServiceStubClassComposer) IfStatement(com.google.api.generator.engine.ast.IfStatement) Arrays(java.util.Arrays) TypeNode(com.google.api.generator.engine.ast.TypeNode) EnumRefExpr(com.google.api.generator.engine.ast.EnumRefExpr) GrpcStubCallableFactory(com.google.api.gax.grpc.GrpcStubCallableFactory) BiFunction(java.util.function.BiFunction) PathTemplate(com.google.api.pathtemplate.PathTemplate) Variable(com.google.api.generator.engine.ast.Variable) Function(java.util.function.Function) StringObjectValue(com.google.api.generator.engine.ast.StringObjectValue) ArrayList(java.util.ArrayList) HttpBinding(com.google.api.generator.gapic.model.HttpBindings.HttpBinding) HashSet(java.util.HashSet) LogicalOperationExpr(com.google.api.generator.engine.ast.LogicalOperationExpr) Expr(com.google.api.generator.engine.ast.Expr) TypeStore(com.google.api.generator.gapic.composer.store.TypeStore) Method(com.google.api.generator.gapic.model.Method) ImmutableList(com.google.common.collect.ImmutableList) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) Map(java.util.Map) MethodDescriptor(io.grpc.MethodDescriptor) Splitter(com.google.common.base.Splitter) ProtoUtils(io.grpc.protobuf.ProtoUtils) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) ConcreteReference(com.google.api.generator.engine.ast.ConcreteReference) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) ScopeNode(com.google.api.generator.engine.ast.ScopeNode) RequestParamsBuilder(com.google.api.gax.rpc.RequestParamsBuilder) Statement(com.google.api.generator.engine.ast.Statement) Service(com.google.api.generator.gapic.model.Service) List(java.util.List) GrpcCallSettings(com.google.api.gax.grpc.GrpcCallSettings) LambdaExpr(com.google.api.generator.engine.ast.LambdaExpr) JavaStyle(com.google.api.generator.gapic.utils.JavaStyle) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) GrpcOperationsStub(com.google.longrunning.stub.GrpcOperationsStub) Message(com.google.api.generator.gapic.model.Message) RoutingHeaderParam(com.google.api.generator.gapic.model.RoutingHeaderRule.RoutingHeaderParam) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) BiFunction(java.util.function.BiFunction) Function(java.util.function.Function) EnumRefExpr(com.google.api.generator.engine.ast.EnumRefExpr) LogicalOperationExpr(com.google.api.generator.engine.ast.LogicalOperationExpr) Expr(com.google.api.generator.engine.ast.Expr) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) LambdaExpr(com.google.api.generator.engine.ast.LambdaExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr)

Aggregations

GrpcCallSettings (com.google.api.gax.grpc.GrpcCallSettings)1 GrpcStubCallableFactory (com.google.api.gax.grpc.GrpcStubCallableFactory)1 RequestParamsBuilder (com.google.api.gax.rpc.RequestParamsBuilder)1 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)1 ConcreteReference (com.google.api.generator.engine.ast.ConcreteReference)1 EnumRefExpr (com.google.api.generator.engine.ast.EnumRefExpr)1 Expr (com.google.api.generator.engine.ast.Expr)1 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)1 IfStatement (com.google.api.generator.engine.ast.IfStatement)1 LambdaExpr (com.google.api.generator.engine.ast.LambdaExpr)1 LogicalOperationExpr (com.google.api.generator.engine.ast.LogicalOperationExpr)1 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)1 RelationalOperationExpr (com.google.api.generator.engine.ast.RelationalOperationExpr)1 ScopeNode (com.google.api.generator.engine.ast.ScopeNode)1 Statement (com.google.api.generator.engine.ast.Statement)1 StringObjectValue (com.google.api.generator.engine.ast.StringObjectValue)1 TypeNode (com.google.api.generator.engine.ast.TypeNode)1 ValueExpr (com.google.api.generator.engine.ast.ValueExpr)1 Variable (com.google.api.generator.engine.ast.Variable)1 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)1