Search in sources :

Example 16 with InterfaceContext

use of com.google.api.codegen.config.InterfaceContext in project toolkit by googleapis.

the class JavaApiMethodTransformer method generateGrpcStreamingMethods.

private List<StaticLangApiMethodView> generateGrpcStreamingMethods(MethodContext methodContext, @Nullable SampleContext sampleContext) {
    List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
    InterfaceContext interfaceContext = methodContext.getSurfaceInterfaceContext();
    List<CallingForm> callingForms;
    ImportTypeTable typeTable = interfaceContext.getImportTypeTable();
    MethodConfig methodConfig = methodContext.getMethodConfig();
    switch(methodConfig.getGrpcStreamingType()) {
        case BidiStreaming:
            typeTable.saveNicknameFor("com.google.api.gax.rpc.BidiStreamingCallable");
            callingForms = Collections.singletonList(CallingForm.CallableStreamingBidi);
            break;
        case ClientStreaming:
            typeTable.saveNicknameFor("com.google.api.gax.rpc.ClientStreamingCallable");
            callingForms = Collections.singletonList(CallingForm.CallableStreamingClient);
            break;
        case ServerStreaming:
            typeTable.saveNicknameFor("com.google.api.gax.rpc.ServerStreamingCallable");
            callingForms = Collections.singletonList(CallingForm.CallableStreamingServer);
            break;
        default:
            throw new IllegalArgumentException("Invalid streaming type: " + methodConfig.getGrpcStreamingType());
    }
    apiMethods.add(generateCallableMethod(methodContext.withCallingForms(callingForms), sampleContext));
    return apiMethods;
}
Also used : MethodConfig(com.google.api.codegen.config.MethodConfig) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) CallingForm(com.google.api.codegen.viewmodel.CallingForm) ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) ArrayList(java.util.ArrayList) InterfaceContext(com.google.api.codegen.config.InterfaceContext)

Example 17 with InterfaceContext

use of com.google.api.codegen.config.InterfaceContext in project toolkit by googleapis.

the class JavaSurfaceTransformer method generateStubInterface.

private StaticLangStubInterfaceView generateStubInterface(InterfaceContext context, GapicProductConfig productConfig) {
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    addStubInterfaceImports(context);
    // Stub class has different default package name from methods classes.
    InterfaceContext apiMethodsContext = context.withNewTypeTable(context.getNamer().getRootPackageName());
    List<StaticLangApiMethodView> methods = javaApiMethodTransformer.generateApiMethods(apiMethodsContext);
    for (TypeAlias alias : apiMethodsContext.getImportTypeTable().getTypeTable().getAllImports().values()) {
        context.getImportTypeTable().getAndSaveNicknameFor(alias);
    }
    StaticLangStubInterfaceView.Builder stubInterface = StaticLangStubInterfaceView.newBuilder();
    stubInterface.doc(serviceTransformer.generateServiceDoc(context, null, productConfig));
    String name = context.getNamer().getApiStubInterfaceName(context.getInterfaceConfig());
    stubInterface.releaseLevelAnnotation(context.getNamer().getReleaseAnnotation(productConfig.getReleaseLevel()));
    stubInterface.name(name);
    stubInterface.callableMethods(filterIncludeCallableMethods(methods));
    stubInterface.hasLongRunningOperations(interfaceConfig.hasLongRunningOperations());
    return stubInterface.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) StaticLangStubInterfaceView(com.google.api.codegen.viewmodel.StaticLangStubInterfaceView) TypeAlias(com.google.api.codegen.util.TypeAlias) InterfaceContext(com.google.api.codegen.config.InterfaceContext)

Example 18 with InterfaceContext

use of com.google.api.codegen.config.InterfaceContext in project toolkit by googleapis.

the class JavaSurfaceTestTransformer method transform.

@Override
public List<ViewModel> transform(ApiModelT model, GapicProductConfig productConfig) {
    SurfaceNamer namer = surfaceTransformer.createSurfaceNamer(productConfig);
    List<ViewModel> views = 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);
        views.add(createUnitTestFileView(context));
        if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
            context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable.cloneEmpty());
            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);
        views.add(createMockServiceImplFileView(context));
        context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable.cloneEmpty());
        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.config.InterfaceContext) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Aggregations

InterfaceContext (com.google.api.codegen.config.InterfaceContext)18 ArrayList (java.util.ArrayList)13 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)11 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)10 ViewModel (com.google.api.codegen.viewmodel.ViewModel)10 MethodContext (com.google.api.codegen.config.MethodContext)9 SampleContext (com.google.api.codegen.config.SampleContext)8 ImmutableList (com.google.common.collect.ImmutableList)8 List (java.util.List)8 MethodModel (com.google.api.codegen.config.MethodModel)7 CallingForm (com.google.api.codegen.viewmodel.CallingForm)7 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)6 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)6 InitCodeOutputType (com.google.api.codegen.metacode.InitCodeContext.InitCodeOutputType)6 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)5 MethodConfig (com.google.api.codegen.config.MethodConfig)5 SampleConfig (com.google.api.codegen.config.SampleConfig)5 GapicCodePathMapper (com.google.api.codegen.gapic.GapicCodePathMapper)5 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)5 HashMap (java.util.HashMap)5