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();
}
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;
}
Aggregations