Search in sources :

Example 36 with StaticLangApiMethodView

use of com.google.api.codegen.viewmodel.StaticLangApiMethodView 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 = 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 : TargetLanguage(com.google.api.codegen.TargetLanguage) Arrays(java.util.Arrays) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) ApiCallableView(com.google.api.codegen.viewmodel.ApiCallableView) StaticLangApiView(com.google.api.codegen.viewmodel.StaticLangApiView) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) StaticLangApiMethodTransformer(com.google.api.codegen.transformer.StaticLangApiMethodTransformer) MethodContext(com.google.api.codegen.transformer.MethodContext) BatchingTransformer(com.google.api.codegen.transformer.BatchingTransformer) ViewModel(com.google.api.codegen.viewmodel.ViewModel) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) ApiCallSettingsView(com.google.api.codegen.viewmodel.ApiCallSettingsView) Splitter(com.google.common.base.Splitter) CSharpTypeTable(com.google.api.codegen.util.csharp.CSharpTypeTable) GapicCodePathMapper(com.google.api.codegen.gapic.GapicCodePathMapper) PackageMetadataTransformer(com.google.api.codegen.transformer.PackageMetadataTransformer) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) Set(java.util.Set) FileHeaderTransformer(com.google.api.codegen.transformer.FileHeaderTransformer) PackageInfoView(com.google.api.codegen.viewmodel.PackageInfoView) 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) ModelToViewTransformer(com.google.api.codegen.transformer.ModelToViewTransformer) ApiCallableImplType(com.google.api.codegen.viewmodel.ApiCallableImplType) StandardImportSectionTransformer(com.google.api.codegen.transformer.StandardImportSectionTransformer) PackageMetadataView(com.google.api.codegen.viewmodel.metadata.PackageMetadataView) PackageMetadataConfig(com.google.api.codegen.config.PackageMetadataConfig) 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) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig) PackageMetadataNamer(com.google.api.codegen.transformer.PackageMetadataNamer) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) MethodModel(com.google.api.codegen.config.MethodModel) ParamWithSimpleDoc(com.google.api.codegen.transformer.ParamWithSimpleDoc) MethodConfig(com.google.api.codegen.config.MethodConfig) StaticLangSettingsView(com.google.api.codegen.viewmodel.StaticLangSettingsView) File(java.io.File) StaticLangResourceNamesView(com.google.api.codegen.viewmodel.StaticLangResourceNamesView) GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ApiModel(com.google.api.codegen.config.ApiModel) ServiceDocView(com.google.api.codegen.viewmodel.ServiceDocView) RetryDefinitionsTransformer(com.google.api.codegen.transformer.RetryDefinitionsTransformer) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) Model(com.google.api.tools.framework.model.Model) ModifyMethodView(com.google.api.codegen.viewmodel.ModifyMethodView) 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)

Example 37 with StaticLangApiMethodView

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

the class CSharpGapicSnippetsTransformer method generateRequestAsyncMethod.

private StaticLangApiMethodSnippetView generateRequestAsyncMethod(MethodContext methodContext) {
    SurfaceNamer namer = methodContext.getNamer();
    StaticLangApiMethodView method = apiMethodTransformer.generateRequestObjectAsyncMethod(methodContext);
    String callerResponseTypeName = methodContext.getTypeTable().getAndSaveNicknameFor(namer.getStaticLangCallerAsyncReturnTypeName(methodContext));
    return StaticLangApiMethodSnippetView.newBuilder().method(method).snippetMethodName(method.name() + "_RequestObject").callerResponseTypeName(callerResponseTypeName).apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())).apiVariableName(method.apiVariableName()).build();
}
Also used : StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 38 with StaticLangApiMethodView

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

the class CSharpGapicSnippetsTransformer method generatePagedRequestMethod.

private StaticLangApiMethodSnippetView generatePagedRequestMethod(MethodContext methodContext) {
    StaticLangApiMethodView method = apiMethodTransformer.generatePagedRequestObjectMethod(methodContext, csharpCommonTransformer.pagedMethodAdditionalParams());
    SurfaceNamer namer = methodContext.getNamer();
    PageStreamingConfig pageStreaming = methodContext.getMethodConfig().getPageStreaming();
    FieldConfig resourceFieldConfig = pageStreaming.getResourcesFieldConfig();
    String callerResponseTypeName = namer.getAndSaveCallerPagedResponseTypeName(methodContext, resourceFieldConfig);
    return StaticLangApiMethodSnippetView.newBuilder().method(method).snippetMethodName(method.name() + "_RequestObject").callerResponseTypeName(callerResponseTypeName).apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())).apiVariableName(method.apiVariableName()).build();
}
Also used : StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) FieldConfig(com.google.api.codegen.config.FieldConfig) PageStreamingConfig(com.google.api.codegen.config.PageStreamingConfig) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 39 with StaticLangApiMethodView

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

the class CSharpGapicSnippetsTransformer method generatePagedRequestAsyncMethod.

private StaticLangApiMethodSnippetView generatePagedRequestAsyncMethod(MethodContext methodContext) {
    StaticLangApiMethodView method = apiMethodTransformer.generatePagedRequestObjectAsyncMethod(methodContext, csharpCommonTransformer.pagedMethodAdditionalParams());
    SurfaceNamer namer = methodContext.getNamer();
    PageStreamingConfig pageStreaming = methodContext.getMethodConfig().getPageStreaming();
    FieldConfig resourceFieldConfig = pageStreaming.getResourcesFieldConfig();
    String callerResponseTypeName = namer.getAndSaveCallerAsyncPagedResponseTypeName(methodContext, resourceFieldConfig);
    return StaticLangApiMethodSnippetView.newBuilder().method(method).snippetMethodName(method.name() + "_RequestObject").callerResponseTypeName(callerResponseTypeName).apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())).apiVariableName(method.apiVariableName()).build();
}
Also used : StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) FieldConfig(com.google.api.codegen.config.FieldConfig) PageStreamingConfig(com.google.api.codegen.config.PageStreamingConfig) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 40 with StaticLangApiMethodView

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

the class CSharpGapicSnippetsTransformer method generateOperationRequestMethod.

private StaticLangApiMethodSnippetView generateOperationRequestMethod(MethodContext methodContext) {
    SurfaceNamer namer = methodContext.getNamer();
    StaticLangApiMethodView method = apiMethodTransformer.generateOperationRequestObjectMethod(methodContext);
    String callerResponseTypeName = method.operationMethod().clientReturnTypeName();
    return StaticLangApiMethodSnippetView.newBuilder().method(method).snippetMethodName(method.name() + "_RequestObject").callerResponseTypeName(callerResponseTypeName).apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())).apiVariableName(method.apiVariableName()).build();
}
Also used : StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Aggregations

StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)45 MethodModel (com.google.api.codegen.config.MethodModel)23 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)22 Builder (com.google.api.codegen.viewmodel.StaticLangApiMethodView.Builder)17 FieldConfig (com.google.api.codegen.config.FieldConfig)6 MethodConfig (com.google.api.codegen.config.MethodConfig)6 MethodContext (com.google.api.codegen.transformer.MethodContext)6 ArrayList (java.util.ArrayList)6 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)5 PageStreamingConfig (com.google.api.codegen.config.PageStreamingConfig)5 TypeModel (com.google.api.codegen.config.TypeModel)5 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)4 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)4 InterfaceContext (com.google.api.codegen.transformer.InterfaceContext)3 ParamWithSimpleDoc (com.google.api.codegen.transformer.ParamWithSimpleDoc)3 StaticLangApiView (com.google.api.codegen.viewmodel.StaticLangApiView)3 ApiModel (com.google.api.codegen.config.ApiModel)2 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)2 InterfaceModel (com.google.api.codegen.config.InterfaceModel)2 ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)2