Search in sources :

Example 1 with StaticLangStubSettingsView

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

the class JavaSurfaceTransformer method transform.

public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceDocs = new ArrayList<>();
    SurfaceNamer namer = surfaceTransformer.createSurfaceNamer(productConfig);
    List<ServiceDocView> serviceDocs = new ArrayList<>();
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        boolean enableStringFormatFunctions = productConfig.getResourceNameMessageConfigs().isEmpty();
        ImportTypeTable typeTable = surfaceTransformer.createTypeTable(productConfig.getPackageName());
        InterfaceContext context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable, enableStringFormatFunctions);
        StaticLangFileView<StaticLangApiView> apiFile = generateApiFile(context, productConfig);
        surfaceDocs.add(apiFile);
        serviceDocs.add(apiFile.classView().doc());
        StaticLangApiMethodView exampleApiMethod = getExampleApiMethod(apiFile.classView().apiMethods());
        context = context.withNewTypeTable(namer.getStubPackageName());
        StaticLangFileView<StaticLangStubSettingsView> stubSettingsFile = generateStubSettingsFile(context, productConfig, exampleApiMethod);
        context = context.withNewTypeTable(namer.getRootPackageName());
        StaticLangFileView<StaticLangSettingsView> settingsFile = generateSettingsFile(context, productConfig, exampleApiMethod, stubSettingsFile.classView());
        surfaceDocs.add(settingsFile);
        surfaceDocs.add(stubSettingsFile);
        context = context.withNewTypeTable(namer.getStubPackageName());
        StaticLangFileView<StaticLangStubInterfaceView> stubInterfaceFile = generateStubInterfaceFile(context, productConfig);
        surfaceDocs.add(stubInterfaceFile);
        context = context.withNewTypeTable(namer.getStubPackageName());
        StaticLangFileView<StaticLangRpcStubView> grpcStubFile = generateRpcStubClassFile(context, productConfig);
        surfaceDocs.add(grpcStubFile);
        surfaceDocs.add(generateCallableFactoryClassFile(context, productConfig));
    }
    PackageInfoView packageInfo = generatePackageInfo(model, productConfig, namer, serviceDocs);
    surfaceDocs.add(packageInfo);
    return surfaceDocs;
}
Also used : StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) StaticLangStubInterfaceView(com.google.api.codegen.viewmodel.StaticLangStubInterfaceView) ArrayList(java.util.ArrayList) PackageInfoView(com.google.api.codegen.viewmodel.PackageInfoView) ViewModel(com.google.api.codegen.viewmodel.ViewModel) InterfaceContext(com.google.api.codegen.transformer.InterfaceContext) ServiceDocView(com.google.api.codegen.viewmodel.ServiceDocView) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) StaticLangSettingsView(com.google.api.codegen.viewmodel.StaticLangSettingsView) StaticLangStubSettingsView(com.google.api.codegen.viewmodel.StaticLangStubSettingsView) StaticLangRpcStubView(com.google.api.codegen.viewmodel.StaticLangRpcStubView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) StaticLangApiView(com.google.api.codegen.viewmodel.StaticLangApiView)

Example 2 with StaticLangStubSettingsView

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

the class JavaSurfaceTransformer method generateStubSettingsClass.

private StaticLangStubSettingsView generateStubSettingsClass(InterfaceContext context, GapicProductConfig productConfig, StaticLangApiMethodView exampleApiMethod) {
    addSettingsImports(context);
    SurfaceNamer namer = context.getNamer();
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    ApiModel model = context.getApiModel();
    StaticLangStubSettingsView.Builder xsettingsClass = StaticLangStubSettingsView.newBuilder();
    xsettingsClass.releaseLevelAnnotation(context.getNamer().getReleaseAnnotation(packageMetadataConfig.releaseLevel(TargetLanguage.JAVA)));
    xsettingsClass.doc(generateSettingsDoc(context, exampleApiMethod, productConfig, context.getNamer().getApiStubSettingsClassName(interfaceConfig), namer.getApiStubInterfaceName(context.getInterfaceConfig())));
    String name = namer.getApiStubSettingsClassName(context.getInterfaceConfig());
    xsettingsClass.name(name);
    xsettingsClass.serviceAddress(model.getServiceAddress());
    xsettingsClass.servicePort(model.getServicePort());
    xsettingsClass.authScopes(model.getAuthScopes());
    if (productConfig.getTransportProtocol().equals(TransportProtocol.HTTP)) {
        xsettingsClass.useDefaultServicePortInEndpoint(false);
    }
    xsettingsClass.transportProtocol(productConfig.getTransportProtocol());
    xsettingsClass.rpcTransportName(namer.getTransportClassName(productConfig.getTransportProtocol()));
    xsettingsClass.transportNameGetter(namer.getTransporNameGetMethod(productConfig.getTransportProtocol()));
    xsettingsClass.defaultTransportProviderBuilder(namer.getDefaultTransportProviderBuilder(productConfig.getTransportProtocol()));
    xsettingsClass.transportProvider(namer.getTransportProvider(productConfig.getTransportProtocol()));
    xsettingsClass.instantiatingChannelProvider(namer.getInstantiatingChannelProvider(productConfig.getTransportProtocol()));
    List<ApiCallSettingsView> apiCallSettings = apiCallableTransformer.generateCallSettings(context);
    xsettingsClass.callSettings(apiCallSettings);
    xsettingsClass.pageStreamingDescriptors(pageStreamingTransformer.generateDescriptorClasses(context));
    xsettingsClass.pagedListResponseFactories(pageStreamingTransformer.generateFactoryClasses(context));
    xsettingsClass.batchingDescriptors(batchingTransformer.generateDescriptorClasses(context));
    xsettingsClass.retryCodesDefinitions(retryDefinitionsTransformer.generateRetryCodesDefinitions(context));
    xsettingsClass.retryParamsDefinitions(retryDefinitionsTransformer.generateRetryParamsDefinitions(context));
    xsettingsClass.transportProtocol(productConfig.getTransportProtocol());
    xsettingsClass.hasDefaultServiceAddress(interfaceConfig.hasDefaultServiceAddress());
    xsettingsClass.hasDefaultServiceScopes(interfaceConfig.hasDefaultServiceScopes());
    xsettingsClass.hasDefaultInstance(interfaceConfig.hasDefaultInstance());
    xsettingsClass.stubInterfaceName(getAndSaveNicknameForStubType(context, namer.getApiStubInterfaceName(interfaceConfig)));
    xsettingsClass.rpcStubClassName(getAndSaveNicknameForStubType(context, namer.getApiRpcStubClassName(interfaceConfig.getInterfaceModel(), productConfig.getTransportProtocol())));
    return xsettingsClass.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) ApiModel(com.google.api.codegen.config.ApiModel) StaticLangStubSettingsView(com.google.api.codegen.viewmodel.StaticLangStubSettingsView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ApiCallSettingsView(com.google.api.codegen.viewmodel.ApiCallSettingsView)

Aggregations

SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)2 StaticLangStubSettingsView (com.google.api.codegen.viewmodel.StaticLangStubSettingsView)2 ApiModel (com.google.api.codegen.config.ApiModel)1 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)1 InterfaceModel (com.google.api.codegen.config.InterfaceModel)1 ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)1 InterfaceContext (com.google.api.codegen.transformer.InterfaceContext)1 ApiCallSettingsView (com.google.api.codegen.viewmodel.ApiCallSettingsView)1 PackageInfoView (com.google.api.codegen.viewmodel.PackageInfoView)1 ServiceDocView (com.google.api.codegen.viewmodel.ServiceDocView)1 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)1 StaticLangApiView (com.google.api.codegen.viewmodel.StaticLangApiView)1 StaticLangRpcStubView (com.google.api.codegen.viewmodel.StaticLangRpcStubView)1 StaticLangSettingsView (com.google.api.codegen.viewmodel.StaticLangSettingsView)1 StaticLangStubInterfaceView (com.google.api.codegen.viewmodel.StaticLangStubInterfaceView)1 ViewModel (com.google.api.codegen.viewmodel.ViewModel)1 ArrayList (java.util.ArrayList)1