Search in sources :

Example 1 with GrpcStubView

use of com.google.api.codegen.viewmodel.GrpcStubView in project toolkit by googleapis.

the class GrpcStubTransformer method generateGrpcStub.

GrpcStubView generateGrpcStub(InterfaceContext context, InterfaceModel targetInterface, List<MethodModel> methods) {
    SurfaceNamer namer = context.getNamer();
    GrpcStubView.Builder stub = GrpcStubView.newBuilder();
    stub.name(namer.getStubName(targetInterface));
    stub.fullyQualifiedType(namer.getFullyQualifiedStubType(targetInterface));
    stub.createStubFunctionName(namer.getCreateStubFunctionName(targetInterface));
    String grpcClientTypeName = namer.getAndSaveNicknameForGrpcClientTypeName(context.getImportTypeTable(), targetInterface);
    stub.grpcClientTypeName(grpcClientTypeName);
    stub.grpcClientVariableName(namer.getGrpcClientVariableName(targetInterface));
    stub.grpcClientImportName(namer.getGrpcClientImportName(targetInterface));
    List<String> methodNames = new ArrayList<>();
    for (MethodModel method : methods) {
        methodNames.add(namer.getApiMethodName(method, context.getMethodConfig(method).getVisibility()));
    }
    stub.methodNames(methodNames);
    stub.stubMethodsArrayName(namer.getStubMethodsArrayName(targetInterface));
    stub.namespace(namer.getNamespace(targetInterface));
    stub.protoFileName(targetInterface.getFileSimpleName());
    return stub.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) ArrayList(java.util.ArrayList) GrpcStubView(com.google.api.codegen.viewmodel.GrpcStubView)

Example 2 with GrpcStubView

use of com.google.api.codegen.viewmodel.GrpcStubView in project toolkit by googleapis.

the class GrpcStubTransformer method generateGrpcStubs.

public List<GrpcStubView> generateGrpcStubs(InterfaceContext context) {
    List<GrpcStubView> stubs = new ArrayList<>();
    Map<String, InterfaceModel> interfaces = new TreeMap<>();
    Map<String, List<MethodModel>> methods = new TreeMap<>();
    for (MethodModel method : context.getSupportedMethods()) {
        InterfaceModel targetInterface = context.asRequestMethodContext(method).getTargetInterface();
        interfaces.put(targetInterface.getFullName(), targetInterface);
        if (methods.containsKey(targetInterface.getFullName())) {
            methods.get(targetInterface.getFullName()).add(method);
        } else {
            methods.put(targetInterface.getFullName(), new ArrayList<>(Arrays.asList(method)));
        }
    }
    for (Map.Entry<String, InterfaceModel> entry : interfaces.entrySet()) {
        InterfaceModel apiInterface = entry.getValue();
        stubs.add(generateGrpcStub(context, apiInterface, methods.get(entry.getKey())));
    }
    return stubs;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) ArrayList(java.util.ArrayList) GrpcStubView(com.google.api.codegen.viewmodel.GrpcStubView) TreeMap(java.util.TreeMap) InterfaceModel(com.google.api.codegen.config.InterfaceModel) List(java.util.List) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Map(java.util.Map)

Aggregations

MethodModel (com.google.api.codegen.config.MethodModel)2 GrpcStubView (com.google.api.codegen.viewmodel.GrpcStubView)2 ArrayList (java.util.ArrayList)2 InterfaceModel (com.google.api.codegen.config.InterfaceModel)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1