use of com.google.api.codegen.viewmodel.StaticLangApiView in project toolkit by googleapis.
the class JavaSurfaceTransformer method transform.
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
List<ViewModel> surfaceDocs = new ArrayList<>();
SurfaceNamer namer = surfaceTransformer.createSurfaceNamer(productConfig);
List<ServiceDocView> serviceDocs = 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);
StaticLangFileView<StaticLangApiView> apiFile = generateApiFile(context, productConfig);
surfaceDocs.add(apiFile);
serviceDocs.add(apiFile.classView().doc());
StaticLangApiMethodView exampleApiMethod = getExampleApiMethod(apiFile.classView().apiMethods());
context = context.withNewTypeTable(namer.getStubPackageName());
StaticLangFileView<StaticLangStubSettingsView> stubSettingsFile = generateStubSettingsFile(context, productConfig, exampleApiMethod);
context = context.withNewTypeTable(namer.getRootPackageName());
StaticLangFileView<StaticLangSettingsView> settingsFile = generateSettingsFile(context, productConfig, exampleApiMethod, stubSettingsFile.classView());
surfaceDocs.add(settingsFile);
surfaceDocs.add(stubSettingsFile);
context = context.withNewTypeTable(namer.getStubPackageName());
StaticLangFileView<StaticLangStubInterfaceView> stubInterfaceFile = generateStubInterfaceFile(context, productConfig);
surfaceDocs.add(stubInterfaceFile);
context = context.withNewTypeTable(namer.getStubPackageName());
StaticLangFileView<StaticLangRpcStubView> grpcStubFile = generateRpcStubClassFile(context, productConfig);
surfaceDocs.add(grpcStubFile);
surfaceDocs.add(generateCallableFactoryClassFile(context, productConfig));
}
PackageInfoView packageInfo = generatePackageInfo(model, productConfig, namer, serviceDocs);
surfaceDocs.add(packageInfo);
return surfaceDocs;
}
use of com.google.api.codegen.viewmodel.StaticLangApiView in project toolkit by googleapis.
the class JavaSurfaceTransformer method generateApiClass.
private StaticLangApiView generateApiClass(InterfaceContext context, GapicProductConfig productConfig) {
SurfaceNamer namer = context.getNamer();
InterfaceConfig interfaceConfig = context.getInterfaceConfig();
addApiImports(context);
List<StaticLangApiMethodView> methods = javaApiMethodTransformer.generateApiMethods(context);
StaticLangApiView.Builder xapiClass = StaticLangApiView.newBuilder();
ApiMethodView exampleApiMethod = getExampleApiMethod(methods);
xapiClass.doc(serviceTransformer.generateServiceDoc(context, exampleApiMethod, productConfig));
String name = context.getNamer().getApiWrapperClassName(context.getInterfaceConfig());
xapiClass.releaseLevelAnnotation(namer.getReleaseAnnotation(productConfig.getReleaseLevel()));
xapiClass.name(name);
xapiClass.settingsClassName(namer.getApiSettingsClassName(interfaceConfig));
xapiClass.stubInterfaceName(getAndSaveNicknameForStubType(context, namer.getApiStubInterfaceName(interfaceConfig)));
xapiClass.stubSettingsClassName(getAndSaveNicknameForStubType(context, namer.getApiStubSettingsClassName(interfaceConfig)));
xapiClass.apiCallableMembers(apiCallableTransformer.generateStaticLangApiCallables(context));
xapiClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context));
xapiClass.formatResourceFunctions(pathTemplateTransformer.generateFormatResourceFunctions(context));
xapiClass.parseResourceFunctions(pathTemplateTransformer.generateParseResourceFunctions(context));
xapiClass.apiMethods(methods);
xapiClass.hasDefaultInstance(interfaceConfig.hasDefaultInstance());
xapiClass.hasLongRunningOperations(interfaceConfig.hasLongRunningOperations());
xapiClass.pagedResponseViews(generatePagedResponseWrappers(context));
return xapiClass.build();
}
use of com.google.api.codegen.viewmodel.StaticLangApiView in project toolkit by googleapis.
the class CSharpGapicClientTransformer method generateApiClass.
private StaticLangApiView generateApiClass(GapicInterfaceContext context) {
SurfaceNamer namer = context.getNamer();
StaticLangApiView.Builder apiClass = StaticLangApiView.newBuilder();
List<StaticLangApiMethodView> methods = apiMethodTransformer.generateApiMethods(context);
apiClass.doc(serviceTransformer.generateServiceDoc(context, null, context.getProductConfig()));
apiClass.name(namer.getApiWrapperClassName(context.getInterfaceConfig()));
apiClass.implName(namer.getApiWrapperClassImplName(context.getInterfaceConfig()));
apiClass.grpcServiceName(namer.getGrpcContainerTypeName(context.getInterfaceModel()));
String grpcTypeName = namer.getGrpcServiceClassName(context.getInterfaceModel());
int dotIndex = grpcTypeName.indexOf('.');
apiClass.grpcTypeNameOuter(grpcTypeName.substring(0, dotIndex));
apiClass.grpcTypeNameInner(grpcTypeName.substring(dotIndex + 1, grpcTypeName.length()));
apiClass.settingsClassName(context.getNamer().getApiSettingsClassName(context.getInterfaceConfig()));
List<ApiCallableView> callables = new ArrayList<>();
for (ApiCallableView call : apiCallableTransformer.generateStaticLangApiCallables(context)) {
if (call.type() == ApiCallableImplType.SimpleApiCallable || call.type() == ApiCallableImplType.BatchingApiCallable || call.type() == ApiCallableImplType.BidiStreamingApiCallable || call.type() == ApiCallableImplType.ServerStreamingApiCallable) {
callables.add(call);
}
}
apiClass.apiCallableMembers(callables);
apiClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context));
apiClass.formatResourceFunctions(pathTemplateTransformer.generateFormatResourceFunctions(context));
apiClass.parseResourceFunctions(pathTemplateTransformer.generateParseResourceFunctions(context));
apiClass.apiMethods(methods);
List<StaticLangApiMethodView> methodsImpl = new ArrayList<>();
for (StaticLangApiMethodView method : methods) {
if (methodTypeHasImpl(method.type())) {
methodsImpl.add(method);
}
}
apiClass.apiMethodsImpl(methodsImpl);
apiClass.hasDefaultInstance(context.getInterfaceConfig().hasDefaultInstance());
apiClass.hasLongRunningOperations(context.getInterfaceConfig().hasLongRunningOperations());
apiClass.reroutedGrpcClients(csharpCommonTransformer.generateReroutedGrpcView(context));
apiClass.modifyMethods(generateModifyMethods(context));
apiClass.apiHasUnaryMethod(methods.stream().anyMatch(m -> m.grpcStreamingType() == GrpcStreamingType.NonStreaming));
apiClass.apiHasServerStreamingMethod(methods.stream().anyMatch(m -> m.grpcStreamingType() == GrpcStreamingType.ServerStreaming));
apiClass.apiHasClientStreamingMethod(methods.stream().anyMatch(m -> m.grpcStreamingType() == GrpcStreamingType.ClientStreaming));
apiClass.apiHasBidiStreamingMethod(methods.stream().anyMatch(m -> m.grpcStreamingType() == GrpcStreamingType.BidiStreaming));
return apiClass.build();
}
Aggregations