Search in sources :

Example 1 with InitCodeView

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

the class DynamicLangApiMethodTransformer method generateMethod.

public OptionalArrayMethodView generateMethod(GapicMethodContext context, boolean packageHasMultipleServices) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    OptionalArrayMethodView.Builder apiMethod = OptionalArrayMethodView.newBuilder();
    if (context.getMethodConfig().isPageStreaming()) {
        apiMethod.type(ClientMethodType.PagedOptionalArrayMethod);
        apiMethod.pageStreamingView(pageStreamingTransformer.generateDescriptor(context.getSurfaceInterfaceContext(), method));
    } else {
        apiMethod.type(ClientMethodType.OptionalArrayMethod);
    }
    apiMethod.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    apiMethod.fullyQualifiedApiClassName(namer.getFullyQualifiedApiWrapperClassName(context.getInterfaceConfig()));
    apiMethod.topLevelAliasedApiClassName(namer.getTopLevelAliasedApiClassName((context.getInterfaceConfig()), packageHasMultipleServices));
    apiMethod.versionAliasedApiClassName(namer.getVersionAliasedApiClassName((context.getInterfaceConfig()), packageHasMultipleServices));
    apiMethod.apiVariableName(namer.getApiWrapperVariableName(context.getInterfaceConfig()));
    apiMethod.apiModuleName(namer.getApiWrapperModuleName());
    apiMethod.localPackageName(namer.getLocalPackageName());
    InitCodeOutputType initCodeOutputType = context.getMethodModel().getRequestStreaming() ? InitCodeOutputType.SingleObject : InitCodeOutputType.FieldList;
    InitCodeView initCode = initCodeTransformer.generateInitCode(context.cloneWithEmptyTypeTable(), createInitCodeContext(context, context.getMethodConfig().getRequiredFieldConfigs(), initCodeOutputType));
    apiMethod.initCode(initCode);
    apiMethod.doc(generateMethodDoc(context));
    apiMethod.name(namer.getApiMethodName(method, context.getMethodConfig().getVisibility()));
    apiMethod.requestVariableName(namer.getRequestVariableName(method));
    apiMethod.requestTypeName(namer.getAndSaveTypeName(context.getTypeTable(), context.getMethodModel().getInputType()));
    apiMethod.responseTypeName(namer.getAndSaveTypeName(context.getTypeTable(), context.getMethodModel().getOutputType()));
    apiMethod.hasReturnValue(!ServiceMessages.s_isEmptyType(context.getMethod().getOutputType()));
    apiMethod.key(namer.getMethodKey(method));
    apiMethod.grpcMethodName(namer.getGrpcMethodName(method));
    apiMethod.rerouteToGrpcInterface(context.getMethodConfig().getRerouteToGrpcInterface());
    apiMethod.stubName(namer.getStubName(context.getTargetInterface()));
    apiMethod.methodParams(apiMethodParamTransformer.generateMethodParams(context));
    Iterable<FieldConfig> filteredFieldConfigs = removePageTokenFieldConfig(context, context.getMethodConfig().getOptionalFieldConfigs());
    List<RequestObjectParamView> requiredParams = generateRequestObjectParams(context, context.getMethodConfig().getRequiredFieldConfigs());
    List<RequestObjectParamView> optionalParams = generateRequestObjectParams(context, context.getMethodConfig().getOptionalFieldConfigs());
    List<RequestObjectParamView> optionalParamsNoPageToken = generateRequestObjectParams(context, filteredFieldConfigs);
    apiMethod.requiredRequestObjectParams(requiredParams);
    apiMethod.optionalRequestObjectParams(optionalParams);
    apiMethod.optionalRequestObjectParamsNoPageToken(optionalParamsNoPageToken);
    apiMethod.hasRequestParameters(!requiredParams.isEmpty() || !optionalParamsNoPageToken.isEmpty());
    apiMethod.hasRequiredParameters(!requiredParams.isEmpty());
    GrpcStreamingType grpcStreamingType = context.getMethodConfig().getGrpcStreamingType();
    apiMethod.grpcStreamingType(grpcStreamingType);
    apiMethod.isSingularRequestMethod(grpcStreamingType.equals(GrpcStreamingType.NonStreaming) || grpcStreamingType.equals(GrpcStreamingType.ServerStreaming));
    apiMethod.packageName(namer.getPackageName());
    apiMethod.packageHasMultipleServices(packageHasMultipleServices);
    apiMethod.packageServiceName(namer.getPackageServiceName(context.getInterfaceConfig()));
    apiMethod.apiVersion(namer.getApiWrapperModuleVersion());
    apiMethod.longRunningView(context.getMethodConfig().isLongRunningOperation() ? lroTransformer.generateDetailView(context) : null);
    apiMethod.oneofParams(context.getMethodConfig().getOneofNames(namer));
    apiMethod.headerRequestParams(headerRequestParamTransformer.generateHeaderRequestParams(context));
    return apiMethod.build();
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) OptionalArrayMethodView(com.google.api.codegen.viewmodel.OptionalArrayMethodView) FieldConfig(com.google.api.codegen.config.FieldConfig) GrpcStreamingType(com.google.api.codegen.config.GrpcStreamingConfig.GrpcStreamingType) RequestObjectParamView(com.google.api.codegen.viewmodel.RequestObjectParamView) InitCodeOutputType(com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType) InitCodeView(com.google.api.codegen.viewmodel.InitCodeView)

Example 2 with InitCodeView

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

the class StaticLangApiMethodTransformer method setRequestObjectMethodFields.

private void setRequestObjectMethodFields(MethodContext context, String callableMethodName, Synchronicity sync, List<ParamWithSimpleDoc> additionalParams, StaticLangApiMethodView.Builder methodViewBuilder) {
    MethodModel method = context.getMethodModel();
    SurfaceNamer namer = context.getNamer();
    List<ParamDocView> paramDocs = new ArrayList<>();
    paramDocs.addAll(getRequestObjectParamDocs(context));
    paramDocs.addAll(ParamWithSimpleDoc.asParamDocViews(additionalParams));
    methodViewBuilder.doc(ApiMethodDocView.newBuilder().mainDocLines(namer.getDocLines(method, context.getMethodConfig())).paramDocs(paramDocs).throwsDocLines(namer.getThrowsDocLines(context.getMethodConfig())).returnsDocLines(namer.getReturnDocLines(context.getSurfaceInterfaceContext(), context, sync)).build());
    InitCodeView initCode = initCodeTransformer.generateInitCode(context.cloneWithEmptyTypeTable(), createInitCodeContext(context, context.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject));
    methodViewBuilder.initCode(initCode);
    methodViewBuilder.methodParams(new ArrayList<RequestObjectParamView>());
    methodViewBuilder.requestObjectParams(new ArrayList<RequestObjectParamView>());
    methodViewBuilder.pathTemplateChecks(new ArrayList<PathTemplateCheckView>());
    RequestObjectMethodDetailView.Builder detailBuilder = RequestObjectMethodDetailView.newBuilder();
    if (context.getMethodConfig().hasRequestObjectMethod()) {
        detailBuilder.accessModifier(context.getNamer().getVisiblityKeyword(context.getMethodConfig().getVisibility()));
    } else {
        detailBuilder.accessModifier(context.getNamer().getPrivateAccessModifier());
    }
    detailBuilder.callableMethodName(callableMethodName);
    methodViewBuilder.requestObjectMethod(detailBuilder.build());
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) PathTemplateCheckView(com.google.api.codegen.viewmodel.PathTemplateCheckView) ArrayList(java.util.ArrayList) SimpleParamDocView(com.google.api.codegen.viewmodel.SimpleParamDocView) ParamDocView(com.google.api.codegen.viewmodel.ParamDocView) RequestObjectParamView(com.google.api.codegen.viewmodel.RequestObjectParamView) RequestObjectMethodDetailView(com.google.api.codegen.viewmodel.RequestObjectMethodDetailView) InitCodeView(com.google.api.codegen.viewmodel.InitCodeView)

Example 3 with InitCodeView

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

the class TestCaseTransformer method createTestCaseView.

public TestCaseView createTestCaseView(MethodContext methodContext, SymbolTable testNameTable, InitCodeContext initCodeContext, ClientMethodType clientMethodType, Synchronicity synchronicity, InitCodeContext requestObjectInitCodeContext) {
    MethodModel method = methodContext.getMethodModel();
    MethodConfig methodConfig = methodContext.getMethodConfig();
    SurfaceNamer namer = methodContext.getNamer();
    ImportTypeTable typeTable = methodContext.getTypeTable();
    String clientMethodName;
    String responseTypeName;
    String callerResponseTypeName;
    String fullyQualifiedResponseTypeName = methodContext.getMethodModel().getOutputTypeName(typeTable).getFullName();
    if (methodConfig.isPageStreaming()) {
        clientMethodName = namer.getApiMethodName(method, methodConfig.getVisibility());
        responseTypeName = namer.getAndSavePagedResponseTypeName(methodContext, methodConfig.getPageStreaming().getResourcesFieldConfig());
        callerResponseTypeName = namer.getAndSaveCallerPagedResponseTypeName(methodContext, methodConfig.getPageStreaming().getResourcesFieldConfig());
    } else if (methodConfig.isLongRunningOperation()) {
        clientMethodName = namer.getLroApiMethodName(method, methodConfig.getVisibility());
        responseTypeName = methodContext.getTypeTable().getAndSaveNicknameFor(methodConfig.getLongRunningConfig().getReturnType());
        callerResponseTypeName = responseTypeName;
        fullyQualifiedResponseTypeName = methodContext.getTypeTable().getFullNameFor(methodConfig.getLongRunningConfig().getReturnType());
    } else if (clientMethodType == ClientMethodType.CallableMethod) {
        clientMethodName = namer.getCallableMethodName(method);
        responseTypeName = method.getAndSaveResponseTypeName(typeTable, namer);
        callerResponseTypeName = responseTypeName;
    } else {
        clientMethodName = synchronicity == Synchronicity.Sync ? namer.getApiMethodName(method, methodConfig.getVisibility()) : namer.getAsyncApiMethodName(method, methodConfig.getVisibility());
        responseTypeName = method.getAndSaveResponseTypeName(typeTable, namer);
        callerResponseTypeName = responseTypeName;
    }
    InitCodeView initCode = initCodeTransformer.generateInitCode(methodContext, initCodeContext);
    InitCodeView requestObjectInitCode = requestObjectInitCodeContext != null ? initCodeTransformer.generateInitCode(methodContext, requestObjectInitCodeContext) : null;
    boolean hasRequestParameters = initCode.lines().size() > 0;
    boolean hasReturnValue = !method.isOutputTypeEmpty();
    if (methodConfig.isLongRunningOperation()) {
        hasReturnValue = !methodConfig.getLongRunningConfig().getReturnType().isEmptyType();
    }
    InitCodeContext responseInitCodeContext = createResponseInitCodeContext(methodContext, initCodeContext.symbolTable());
    MockRpcResponseView mockRpcResponseView = createMockResponseView(methodContext, responseInitCodeContext);
    GrpcStreamingView grpcStreamingView = null;
    if (methodConfig.isGrpcStreaming()) {
        String resourceTypeName = null;
        String resourcesFieldGetterName = null;
        if (methodConfig.getGrpcStreaming().hasResourceField()) {
            FieldModel resourcesField = methodConfig.getGrpcStreaming().getResourcesField();
            resourceTypeName = methodContext.getTypeTable().getAndSaveNicknameForElementType(resourcesField);
            resourcesFieldGetterName = namer.getFieldGetFunctionName(resourcesField, Name.from(resourcesField.getSimpleName()));
        }
        grpcStreamingView = GrpcStreamingView.newBuilder().resourceTypeName(resourceTypeName).resourcesFieldGetterName(resourcesFieldGetterName).requestInitCodeList(createGrpcStreamingInitCodeViews(methodContext, initCodeContext, initCode)).responseInitCodeList(createGrpcStreamingInitCodeViews(methodContext, responseInitCodeContext, mockRpcResponseView.initCode())).build();
    }
    return TestCaseView.newBuilder().asserts(initCodeTransformer.generateRequestAssertViews(methodContext, initCodeContext)).clientMethodType(clientMethodType).grpcStreamingType(methodConfig.getGrpcStreamingType()).hasRequestParameters(hasRequestParameters).hasReturnValue(hasReturnValue).initCode(initCode).requestObjectInitCode(requestObjectInitCode).mockResponse(mockRpcResponseView).mockServiceVarName(namer.getMockServiceVarName(methodContext.getTargetInterface())).name(synchronicity == Synchronicity.Sync ? namer.getTestCaseName(testNameTable, method) : namer.getAsyncTestCaseName(testNameTable, method)).nameWithException(namer.getExceptionTestCaseName(testNameTable, method)).pageStreamingResponseViews(createPageStreamingResponseViews(methodContext)).grpcStreamingView(grpcStreamingView).requestTypeName(method.getAndSaveRequestTypeName(typeTable, namer)).responseTypeName(responseTypeName).callerResponseTypeName(callerResponseTypeName).fullyQualifiedRequestTypeName(method.getInputTypeName(typeTable).getFullName()).fullyQualifiedResponseTypeName(fullyQualifiedResponseTypeName).serviceConstructorName(namer.getApiWrapperClassConstructorName(methodContext.getInterfaceConfig())).fullyQualifiedServiceClassName(namer.getFullyQualifiedApiWrapperClassName(methodContext.getInterfaceConfig())).fullyQualifiedAliasedServiceClassName(namer.getTopLevelAliasedApiClassName((methodContext.getInterfaceConfig()), packageHasMultipleServices)).clientMethodName(clientMethodName).mockGrpcStubTypeName(namer.getMockGrpcServiceImplName(methodContext.getTargetInterface())).createStubFunctionName(namer.getCreateStubFunctionName(methodContext.getTargetInterface())).grpcStubCallString(namer.getGrpcStubCallString(methodContext.getTargetInterface(), method)).clientHasDefaultInstance(methodContext.getInterfaceConfig().hasDefaultInstance()).methodDescriptor(getMethodDescriptorName(methodContext)).grpcMethodName(synchronicity == Synchronicity.Sync ? namer.getGrpcMethodName(method) : namer.getAsyncGrpcMethodName(method)).build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) MethodModel(com.google.api.codegen.config.MethodModel) MockRpcResponseView(com.google.api.codegen.viewmodel.testing.MockRpcResponseView) GrpcStreamingView(com.google.api.codegen.viewmodel.testing.GrpcStreamingView) FieldModel(com.google.api.codegen.config.FieldModel) InitCodeContext(com.google.api.codegen.metacode.InitCodeContext) InitCodeView(com.google.api.codegen.viewmodel.InitCodeView)

Example 4 with InitCodeView

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

the class TestCaseTransformer method createMockResponseView.

private MockRpcResponseView createMockResponseView(MethodContext methodContext, InitCodeContext responseInitCodeContext) {
    methodContext = methodContext.getSurfaceInterfaceContext().asRequestMethodContext(methodContext.getMethodModel());
    InitCodeView initCodeView = initCodeTransformer.generateInitCode(methodContext, responseInitCodeContext);
    String typeName = methodContext.getMethodModel().getAndSaveResponseTypeName(methodContext.getTypeTable(), methodContext.getNamer());
    return MockRpcResponseView.newBuilder().typeName(typeName).initCode(initCodeView).build();
}
Also used : InitCodeView(com.google.api.codegen.viewmodel.InitCodeView)

Example 5 with InitCodeView

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

the class CSharpGapicSmokeTestTransformer method createSmokeTestCaseApiMethodView.

private StaticLangApiMethodView createSmokeTestCaseApiMethodView(GapicInterfaceContext context, MethodContext methodContext) {
    SurfaceNamer namer = context.getNamer();
    MethodConfig methodConfig = methodContext.getMethodConfig();
    StaticLangApiMethodView.Builder apiMethodView;
    if (methodConfig.isPageStreaming()) {
        apiMethodView = apiMethodTransformer.generatePagedFlattenedMethod(methodContext).toBuilder();
        FieldConfig resourceFieldConfig = methodContext.getMethodConfig().getPageStreaming().getResourcesFieldConfig();
        String callerResponseTypeName = namer.getAndSaveCallerPagedResponseTypeName(methodContext, resourceFieldConfig);
        apiMethodView.responseTypeName(callerResponseTypeName);
    } else if (methodConfig.isLongRunningOperation()) {
        ArrayList<ParamWithSimpleDoc> emptyParams = new ArrayList<ParamWithSimpleDoc>();
        apiMethodView = apiMethodTransformer.generateOperationFlattenedMethod(methodContext, emptyParams).toBuilder();
    } else {
        apiMethodView = apiMethodTransformer.generateFlattenedMethod(methodContext).toBuilder();
    }
    InitCodeTransformer initCodeTransformer = new InitCodeTransformer();
    InitCodeView initCodeView = initCodeTransformer.generateInitCode(methodContext, testCaseTransformer.createSmokeTestInitContext(methodContext));
    apiMethodView.initCode(initCodeView);
    return apiMethodView.build();
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) ParamWithSimpleDoc(com.google.api.codegen.transformer.ParamWithSimpleDoc) FieldConfig(com.google.api.codegen.config.FieldConfig) ArrayList(java.util.ArrayList) InitCodeTransformer(com.google.api.codegen.transformer.InitCodeTransformer) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) InitCodeView(com.google.api.codegen.viewmodel.InitCodeView)

Aggregations

InitCodeView (com.google.api.codegen.viewmodel.InitCodeView)13 InitCodeTransformer (com.google.api.codegen.transformer.InitCodeTransformer)7 OptionalArrayMethodView (com.google.api.codegen.viewmodel.OptionalArrayMethodView)7 DynamicLangApiMethodTransformer (com.google.api.codegen.transformer.DynamicLangApiMethodTransformer)6 MethodConfig (com.google.api.codegen.config.MethodConfig)3 MethodModel (com.google.api.codegen.config.MethodModel)3 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)3 FieldConfig (com.google.api.codegen.config.FieldConfig)2 RequestObjectParamView (com.google.api.codegen.viewmodel.RequestObjectParamView)2 ArrayList (java.util.ArrayList)2 FieldModel (com.google.api.codegen.config.FieldModel)1 GrpcStreamingType (com.google.api.codegen.config.GrpcStreamingConfig.GrpcStreamingType)1 InitCodeContext (com.google.api.codegen.metacode.InitCodeContext)1 InitCodeOutputType (com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)1 ParamWithSimpleDoc (com.google.api.codegen.transformer.ParamWithSimpleDoc)1 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)1 TestCaseTransformer (com.google.api.codegen.transformer.TestCaseTransformer)1 ParamDocView (com.google.api.codegen.viewmodel.ParamDocView)1 PathTemplateCheckView (com.google.api.codegen.viewmodel.PathTemplateCheckView)1 RequestObjectMethodDetailView (com.google.api.codegen.viewmodel.RequestObjectMethodDetailView)1