use of com.google.api.codegen.config.InterfaceContext in project toolkit by googleapis.
the class JavaApiMethodTransformer method generateGrpcStreamingMethods.
private List<StaticLangApiMethodView> generateGrpcStreamingMethods(MethodContext methodContext, @Nullable SampleContext sampleContext) {
List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
InterfaceContext interfaceContext = methodContext.getSurfaceInterfaceContext();
List<CallingForm> callingForms;
ImportTypeTable typeTable = interfaceContext.getImportTypeTable();
MethodConfig methodConfig = methodContext.getMethodConfig();
switch(methodConfig.getGrpcStreamingType()) {
case BidiStreaming:
typeTable.saveNicknameFor("com.google.api.gax.rpc.BidiStreamingCallable");
callingForms = Collections.singletonList(CallingForm.CallableStreamingBidi);
break;
case ClientStreaming:
typeTable.saveNicknameFor("com.google.api.gax.rpc.ClientStreamingCallable");
callingForms = Collections.singletonList(CallingForm.CallableStreamingClient);
break;
case ServerStreaming:
typeTable.saveNicknameFor("com.google.api.gax.rpc.ServerStreamingCallable");
callingForms = Collections.singletonList(CallingForm.CallableStreamingServer);
break;
default:
throw new IllegalArgumentException("Invalid streaming type: " + methodConfig.getGrpcStreamingType());
}
apiMethods.add(generateCallableMethod(methodContext.withCallingForms(callingForms), sampleContext));
return apiMethods;
}
use of com.google.api.codegen.config.InterfaceContext in project toolkit by googleapis.
the class JavaSurfaceTransformer method generateStubInterface.
private StaticLangStubInterfaceView generateStubInterface(InterfaceContext context, GapicProductConfig productConfig) {
InterfaceConfig interfaceConfig = context.getInterfaceConfig();
addStubInterfaceImports(context);
// Stub class has different default package name from methods classes.
InterfaceContext apiMethodsContext = context.withNewTypeTable(context.getNamer().getRootPackageName());
List<StaticLangApiMethodView> methods = javaApiMethodTransformer.generateApiMethods(apiMethodsContext);
for (TypeAlias alias : apiMethodsContext.getImportTypeTable().getTypeTable().getAllImports().values()) {
context.getImportTypeTable().getAndSaveNicknameFor(alias);
}
StaticLangStubInterfaceView.Builder stubInterface = StaticLangStubInterfaceView.newBuilder();
stubInterface.doc(serviceTransformer.generateServiceDoc(context, null, productConfig));
String name = context.getNamer().getApiStubInterfaceName(context.getInterfaceConfig());
stubInterface.releaseLevelAnnotation(context.getNamer().getReleaseAnnotation(productConfig.getReleaseLevel()));
stubInterface.name(name);
stubInterface.callableMethods(filterIncludeCallableMethods(methods));
stubInterface.hasLongRunningOperations(interfaceConfig.hasLongRunningOperations());
return stubInterface.build();
}
use of com.google.api.codegen.config.InterfaceContext in project toolkit by googleapis.
the class JavaSurfaceTestTransformer method transform.
@Override
public List<ViewModel> transform(ApiModelT model, GapicProductConfig productConfig) {
SurfaceNamer namer = surfaceTransformer.createSurfaceNamer(productConfig);
List<ViewModel> views = new ArrayList<>();
for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
if (!productConfig.hasInterfaceConfig(apiInterface)) {
continue;
}
ImportTypeTable typeTable = surfaceTransformer.createTypeTable(productConfig.getPackageName());
InterfaceContext context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable);
views.add(createUnitTestFileView(context));
if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable.cloneEmpty());
views.add(createSmokeTestClassView(context));
}
}
for (InterfaceModel apiInterface : mockServiceTransformer.getGrpcInterfacesToMock(model, productConfig)) {
ImportTypeTable typeTable = surfaceTransformer.createTypeTable(productConfig.getPackageName());
InterfaceContext context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable);
views.add(createMockServiceImplFileView(context));
context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable.cloneEmpty());
views.add(createMockServiceView(context));
}
return views;
}
Aggregations