Search in sources :

Example 1 with GapicMethodContext

use of com.google.api.codegen.transformer.GapicMethodContext in project toolkit by googleapis.

the class CSharpGapicClientTransformer method generateApiMethods.

private List<StaticLangApiMethodView> generateApiMethods(GapicInterfaceContext context) {
    List<ParamWithSimpleDoc> pagedMethodAdditionalParams = new ImmutableList.Builder<ParamWithSimpleDoc>().addAll(csharpCommonTransformer.pagedMethodAdditionalParams()).addAll(csharpCommonTransformer.callSettingsParam()).build();
    List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
    for (MethodModel method : csharpCommonTransformer.getSupportedMethods(context)) {
        MethodConfig methodConfig = context.getMethodConfig(method);
        MethodContext requestMethodContext = context.asRequestMethodContext(method);
        if (methodConfig.isGrpcStreaming()) {
            // Only for protobuf-based APIs.
            apiMethods.add(apiMethodTransformer.generateGrpcStreamingRequestObjectMethod(requestMethodContext));
        } else if (methodConfig.isLongRunningOperation()) {
            // Only for protobuf-based APIs.
            GapicMethodContext gapicMethodContext = (GapicMethodContext) requestMethodContext;
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    GapicMethodContext methodContext = context.asFlattenedMethodContext(requestMethodContext.getMethodModel(), flatteningGroup);
                    apiMethods.add(apiMethodTransformer.generateAsyncOperationFlattenedMethod(methodContext, csharpCommonTransformer.callSettingsParam(), ClientMethodType.AsyncOperationFlattenedCallSettingsMethod, true));
                    apiMethods.add(apiMethodTransformer.generateAsyncOperationFlattenedMethod(methodContext, csharpCommonTransformer.cancellationTokenParam(), ClientMethodType.AsyncOperationFlattenedCancellationMethod, true));
                    apiMethods.add(apiMethodTransformer.generateOperationFlattenedMethod(methodContext, csharpCommonTransformer.callSettingsParam()));
                }
            }
            apiMethods.add(apiMethodTransformer.generateAsyncOperationRequestObjectMethod(requestMethodContext, csharpCommonTransformer.callSettingsParam(), true));
            apiMethods.add(apiMethodTransformer.generateOperationRequestObjectMethod(gapicMethodContext, csharpCommonTransformer.callSettingsParam()));
        } else if (methodConfig.isPageStreaming()) {
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    GapicMethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup);
                    apiMethods.add(apiMethodTransformer.generatePagedFlattenedAsyncMethod(methodContext, pagedMethodAdditionalParams));
                    apiMethods.add(apiMethodTransformer.generatePagedFlattenedMethod(methodContext, pagedMethodAdditionalParams));
                }
            }
            apiMethods.add(apiMethodTransformer.generatePagedRequestObjectAsyncMethod(requestMethodContext, csharpCommonTransformer.callSettingsParam()));
            apiMethods.add(apiMethodTransformer.generatePagedRequestObjectMethod(requestMethodContext, csharpCommonTransformer.callSettingsParam()));
        } else {
            if (methodConfig.isFlattening()) {
                for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
                    GapicMethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup);
                    apiMethods.add(apiMethodTransformer.generateFlattenedAsyncMethod(methodContext, csharpCommonTransformer.callSettingsParam(), ClientMethodType.FlattenedAsyncCallSettingsMethod));
                    apiMethods.add(apiMethodTransformer.generateFlattenedAsyncMethod(methodContext, csharpCommonTransformer.cancellationTokenParam(), ClientMethodType.FlattenedAsyncCancellationTokenMethod));
                    apiMethods.add(apiMethodTransformer.generateFlattenedMethod(methodContext, csharpCommonTransformer.callSettingsParam()));
                }
            }
            apiMethods.add(apiMethodTransformer.generateRequestObjectAsyncMethod(requestMethodContext, csharpCommonTransformer.callSettingsParam(), ClientMethodType.AsyncRequestObjectCallSettingsMethod));
            apiMethods.add(apiMethodTransformer.generateRequestObjectAsyncMethod(requestMethodContext, csharpCommonTransformer.cancellationTokenParam(), ClientMethodType.AsyncRequestObjectCancellationMethod));
            apiMethods.add(apiMethodTransformer.generateRequestObjectMethod(requestMethodContext, csharpCommonTransformer.callSettingsParam()));
        }
    }
    return apiMethods;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) ParamWithSimpleDoc(com.google.api.codegen.transformer.ParamWithSimpleDoc) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) MethodContext(com.google.api.codegen.transformer.MethodContext) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig)

Aggregations

FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)1 MethodConfig (com.google.api.codegen.config.MethodConfig)1 MethodModel (com.google.api.codegen.config.MethodModel)1 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)1 MethodContext (com.google.api.codegen.transformer.MethodContext)1 ParamWithSimpleDoc (com.google.api.codegen.transformer.ParamWithSimpleDoc)1 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1