Search in sources :

Example 16 with ImportTypeTable

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

the class JavaSurfaceTestTransformer method addMockServiceImports.

private void addMockServiceImports(InterfaceContext context) {
    ImportTypeTable typeTable = context.getImportTypeTable();
    typeTable.saveNicknameFor("java.util.List");
    typeTable.saveNicknameFor("com.google.api.core.BetaApi");
    typeTable.saveNicknameFor("com.google.api.gax.grpc.testing.MockGrpcService");
    if (context.getProductConfig().getTransportProtocol().equals(TransportProtocol.GRPC)) {
        typeTable.saveNicknameFor("com.google.protobuf.AbstractMessage");
        typeTable.saveNicknameFor("io.grpc.ServerServiceDefinition");
    }
}
Also used : ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable)

Example 17 with ImportTypeTable

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

the class JavaSurfaceTestTransformer method addGrpcStreamingTestImports.

private void addGrpcStreamingTestImports(InterfaceContext context, GrpcStreamingType streamingType) {
    ImportTypeTable typeTable = context.getImportTypeTable();
    if (context.getProductConfig().getTransportProtocol().equals(TransportProtocol.GRPC)) {
        typeTable.saveNicknameFor("com.google.api.gax.grpc.testing.MockStreamObserver");
        typeTable.saveNicknameFor("com.google.api.gax.rpc.ApiStreamObserver");
        switch(streamingType) {
            case BidiStreaming:
                typeTable.saveNicknameFor("com.google.api.gax.rpc.BidiStreamingCallable");
                break;
            case ClientStreaming:
                typeTable.saveNicknameFor("com.google.api.gax.rpc.ClientStreamingCallable");
                break;
            case ServerStreaming:
                typeTable.saveNicknameFor("com.google.api.gax.rpc.ServerStreamingCallable");
                break;
            default:
                throw new IllegalArgumentException("Invalid streaming type: " + streamingType);
        }
    }
}
Also used : ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable)

Example 18 with ImportTypeTable

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

the class PhpSampleImportTransformer method addOutputImports.

@Override
protected void addOutputImports(MethodContext context, OutputContext outputContext) {
    ImportTypeTable typeTable = context.getTypeTable();
    outputContext.stringFormattedVariableTypes().stream().filter(TypeModel::isEnum).forEach(type -> typeTable.getAndSaveNicknameFor(type));
}
Also used : ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable)

Example 19 with ImportTypeTable

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

the class JavaSurfaceTestTransformer method transform.

@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
    SurfaceNamer namer = surfaceTransformer.createSurfaceNamer(productConfig);
    boolean enableStringFormatFunctions = productConfig.getResourceNameMessageConfigs().isEmpty();
    List<ViewModel> views = new ArrayList<>();
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        ImportTypeTable typeTable = surfaceTransformer.createTypeTable(productConfig.getPackageName());
        InterfaceContext context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable, enableStringFormatFunctions);
        views.add(createUnitTestFileView(context));
        if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
            context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable.cloneEmpty(), enableStringFormatFunctions);
            views.add(createSmokeTestClassView(context));
        }
    }
    for (InterfaceModel apiInterface : mockServiceTransformer.getGrpcInterfacesToMock(model, productConfig)) {
        ImportTypeTable typeTable = surfaceTransformer.createTypeTable(productConfig.getPackageName());
        InterfaceContext context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable, enableStringFormatFunctions);
        views.add(createMockServiceImplFileView(context));
        context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable.cloneEmpty(), enableStringFormatFunctions);
        views.add(createMockServiceView(context));
    }
    return views;
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) ArrayList(java.util.ArrayList) ViewModel(com.google.api.codegen.viewmodel.ViewModel) InterfaceContext(com.google.api.codegen.transformer.InterfaceContext) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 20 with ImportTypeTable

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

the class CSharpSurfaceNamer method getAndSaveAsyncPagedResponseTypeName.

@Override
public String getAndSaveAsyncPagedResponseTypeName(MethodContext methodContext, FieldConfig resourceFieldConfig) {
    ImportTypeTable typeTable = methodContext.getTypeTable();
    String inputTypeName = methodContext.getMethodModel().getAndSaveRequestTypeName(methodContext.getTypeTable(), methodContext.getNamer());
    String outputTypeName = methodContext.getMethodModel().getAndSaveResponseTypeName(methodContext.getTypeTable(), methodContext.getNamer());
    String resourceTypeName = getResourceTypeName(typeTable, resourceFieldConfig);
    return typeTable.getAndSaveNicknameForContainer("Google.Api.Gax.PagedAsyncEnumerable", inputTypeName, outputTypeName, resourceTypeName);
}
Also used : ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable)

Aggregations

ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)33 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)8 MethodModel (com.google.api.codegen.config.MethodModel)5 ArrayList (java.util.ArrayList)5 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)3 InterfaceContext (com.google.api.codegen.config.InterfaceContext)3 InterfaceModel (com.google.api.codegen.config.InterfaceModel)3 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)3 ViewModel (com.google.api.codegen.viewmodel.ViewModel)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 MethodConfig (com.google.api.codegen.config.MethodConfig)2 TypeModel (com.google.api.codegen.config.TypeModel)2 OutputTransformer (com.google.api.codegen.transformer.OutputTransformer)2 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)1 InitCodeNode (com.google.api.codegen.metacode.InitCodeNode)1 InterfaceContext (com.google.api.codegen.transformer.InterfaceContext)1 MethodContext (com.google.api.codegen.transformer.MethodContext)1 TypeName (com.google.api.codegen.util.TypeName)1 CallingForm (com.google.api.codegen.viewmodel.CallingForm)1 PackageInfoView (com.google.api.codegen.viewmodel.PackageInfoView)1