Search in sources :

Example 1 with StaticLangApiView

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;
}
Also used : StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) StaticLangStubInterfaceView(com.google.api.codegen.viewmodel.StaticLangStubInterfaceView) ArrayList(java.util.ArrayList) PackageInfoView(com.google.api.codegen.viewmodel.PackageInfoView) ViewModel(com.google.api.codegen.viewmodel.ViewModel) InterfaceContext(com.google.api.codegen.config.InterfaceContext) ServiceDocView(com.google.api.codegen.viewmodel.ServiceDocView) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) StaticLangSettingsView(com.google.api.codegen.viewmodel.StaticLangSettingsView) StaticLangStubSettingsView(com.google.api.codegen.viewmodel.StaticLangStubSettingsView) StaticLangRpcStubView(com.google.api.codegen.viewmodel.StaticLangRpcStubView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) StaticLangApiView(com.google.api.codegen.viewmodel.StaticLangApiView)

Example 2 with StaticLangApiView

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();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) ApiMethodView(com.google.api.codegen.viewmodel.ApiMethodView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) StaticLangApiView(com.google.api.codegen.viewmodel.StaticLangApiView)

Example 3 with StaticLangApiView

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();
}
Also used : Arrays(java.util.Arrays) ListMultimap(com.google.common.collect.ListMultimap) RetryCodesDefinitionView(com.google.api.codegen.viewmodel.RetryCodesDefinitionView) ApiCallableView(com.google.api.codegen.viewmodel.ApiCallableView) StaticLangApiView(com.google.api.codegen.viewmodel.StaticLangApiView) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) StaticLangApiMethodTransformer(com.google.api.codegen.transformer.StaticLangApiMethodTransformer) MethodContext(com.google.api.codegen.config.MethodContext) BatchingTransformer(com.google.api.codegen.transformer.BatchingTransformer) ViewModel(com.google.api.codegen.viewmodel.ViewModel) Map(java.util.Map) ResourceProtoFieldView(com.google.api.codegen.viewmodel.ResourceProtoFieldView) ApiCallSettingsView(com.google.api.codegen.viewmodel.ApiCallSettingsView) ResourceNameType(com.google.api.codegen.config.ResourceNameType) ResourceProtoView(com.google.api.codegen.viewmodel.ResourceProtoView) CSharpTypeTable(com.google.api.codegen.util.csharp.CSharpTypeTable) GapicCodePathMapper(com.google.api.codegen.gapic.GapicCodePathMapper) ResourceNameView(com.google.api.codegen.viewmodel.ResourceNameView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) Collection(java.util.Collection) Set(java.util.Set) FileHeaderTransformer(com.google.api.codegen.transformer.FileHeaderTransformer) Collectors(java.util.stream.Collectors) Name(com.google.api.codegen.util.Name) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) List(java.util.List) ApiCallableTransformer(com.google.api.codegen.transformer.ApiCallableTransformer) InterfaceModel(com.google.api.codegen.config.InterfaceModel) SettingsDocView(com.google.api.codegen.viewmodel.SettingsDocView) Entry(java.util.Map.Entry) ModelToViewTransformer(com.google.api.codegen.transformer.ModelToViewTransformer) ResourceNameSingleView(com.google.api.codegen.viewmodel.ResourceNameSingleView) ApiCallableImplType(com.google.api.codegen.viewmodel.ApiCallableImplType) StandardImportSectionTransformer(com.google.api.codegen.transformer.StandardImportSectionTransformer) FieldModel(com.google.api.codegen.config.FieldModel) GrpcStreamingType(com.google.api.codegen.config.GrpcStreamingConfig.GrpcStreamingType) PageStreamingTransformer(com.google.api.codegen.transformer.PageStreamingTransformer) ServiceTransformer(com.google.api.codegen.transformer.ServiceTransformer) PathTemplateTransformer(com.google.api.codegen.transformer.PathTemplateTransformer) StaticLangApiAndSettingsFileView(com.google.api.codegen.viewmodel.StaticLangApiAndSettingsFileView) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MethodModel(com.google.api.codegen.config.MethodModel) MethodConfig(com.google.api.codegen.config.MethodConfig) CSharpAliasMode(com.google.api.codegen.util.csharp.CSharpAliasMode) StaticLangSettingsView(com.google.api.codegen.viewmodel.StaticLangSettingsView) ResourceNameMessageConfigs(com.google.api.codegen.config.ResourceNameMessageConfigs) ResourceNameConfig(com.google.api.codegen.config.ResourceNameConfig) File(java.io.File) StaticLangResourceNamesView(com.google.api.codegen.viewmodel.StaticLangResourceNamesView) GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) ApiModel(com.google.api.codegen.config.ApiModel) ProductServiceConfig(com.google.api.codegen.config.ProductServiceConfig) RetryDefinitionsTransformer(com.google.api.codegen.transformer.RetryDefinitionsTransformer) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) Comparator(java.util.Comparator) Collections(java.util.Collections) ModifyMethodView(com.google.api.codegen.viewmodel.ModifyMethodView) FieldConfig(com.google.api.codegen.config.FieldConfig) ClientMethodType(com.google.api.codegen.viewmodel.ClientMethodType) ApiCallableView(com.google.api.codegen.viewmodel.ApiCallableView) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) ArrayList(java.util.ArrayList) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) StaticLangApiView(com.google.api.codegen.viewmodel.StaticLangApiView)

Aggregations

SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)3 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)3 StaticLangApiView (com.google.api.codegen.viewmodel.StaticLangApiView)3 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)2 InterfaceModel (com.google.api.codegen.config.InterfaceModel)2 ApiModel (com.google.api.codegen.config.ApiModel)1 FieldConfig (com.google.api.codegen.config.FieldConfig)1 FieldModel (com.google.api.codegen.config.FieldModel)1 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)1 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)1 GrpcStreamingType (com.google.api.codegen.config.GrpcStreamingConfig.GrpcStreamingType)1 InterfaceContext (com.google.api.codegen.config.InterfaceContext)1 MethodConfig (com.google.api.codegen.config.MethodConfig)1 MethodContext (com.google.api.codegen.config.MethodContext)1 MethodModel (com.google.api.codegen.config.MethodModel)1 ProductServiceConfig (com.google.api.codegen.config.ProductServiceConfig)1 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)1 ResourceNameConfig (com.google.api.codegen.config.ResourceNameConfig)1 ResourceNameMessageConfigs (com.google.api.codegen.config.ResourceNameMessageConfigs)1 ResourceNameType (com.google.api.codegen.config.ResourceNameType)1