Search in sources :

Example 26 with SurfaceNamer

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

the class JavaSurfaceTransformer method generateRpcStubClass.

private StaticLangRpcStubView generateRpcStubClass(InterfaceContext context, GapicProductConfig productConfig) {
    SurfaceNamer namer = context.getNamer();
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    addRpcStubImports(context);
    // Stub class has different default package name from method, request, and resource classes.
    InterfaceContext apiMethodsContext = context.withNewTypeTable(context.getNamer().getRootPackageName());
    List<StaticLangApiMethodView> methods = generateApiMethods(apiMethodsContext);
    StaticLangRpcStubView.Builder stubClass = StaticLangRpcStubView.newBuilder();
    stubClass.doc(serviceTransformer.generateServiceDoc(context, null, productConfig));
    String name = namer.getApiRpcStubClassName(interfaceConfig.getInterfaceModel(), productConfig.getTransportProtocol());
    stubClass.releaseLevelAnnotation(namer.getReleaseAnnotation(ReleaseLevel.BETA));
    stubClass.name(name);
    stubClass.parentName(namer.getApiStubInterfaceName(interfaceConfig));
    stubClass.settingsClassName(getAndSaveNicknameForRootType(apiMethodsContext, namer.getApiSettingsClassName(interfaceConfig)));
    stubClass.stubSettingsClassName(getAndSaveNicknameForStubType(apiMethodsContext, namer.getApiStubSettingsClassName(interfaceConfig)));
    stubClass.callableFactoryClassName(getAndSaveNicknameForStubType(apiMethodsContext, namer.getCallableFactoryClassName(interfaceConfig, productConfig.getTransportProtocol())));
    stubClass.methodDescriptors(apiCallableTransformer.generateMethodDescriptors(apiMethodsContext));
    stubClass.apiCallables(apiCallableTransformer.generateStaticLangApiCallables(apiMethodsContext));
    stubClass.callableMethods(filterIncludeCallableMethods(methods));
    stubClass.hasDefaultInstance(interfaceConfig.hasDefaultInstance());
    stubClass.hasLongRunningOperations(interfaceConfig.hasLongRunningOperations());
    for (TypeAlias alias : apiMethodsContext.getImportTypeTable().getTypeTable().getAllImports().values()) {
        context.getImportTypeTable().getAndSaveNicknameFor(alias);
    }
    return stubClass.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) StaticLangApiMethodView(com.google.api.codegen.viewmodel.StaticLangApiMethodView) TypeAlias(com.google.api.codegen.util.TypeAlias) InterfaceContext(com.google.api.codegen.transformer.InterfaceContext) StaticLangRpcStubView(com.google.api.codegen.viewmodel.StaticLangRpcStubView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 27 with SurfaceNamer

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

the class JavaSurfaceTransformer method getAndSaveNicknameForRootType.

private String getAndSaveNicknameForRootType(InterfaceContext context, String nickname) {
    SurfaceNamer namer = context.getNamer();
    ImportTypeTable typeTable = context.getImportTypeTable();
    String fullyQualifiedTypeName = namer.getRootPackageName() + "." + nickname;
    return typeTable.getAndSaveNicknameFor(fullyQualifiedTypeName);
}
Also used : ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 28 with SurfaceNamer

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

the class JavaSurfaceTransformer method generateSettingsDoc.

private SettingsDocView generateSettingsDoc(InterfaceContext context, StaticLangApiMethodView exampleApiMethod, GapicProductConfig productConfig, String settingsClassName, String apiClassName) {
    SurfaceNamer namer = context.getNamer();
    SettingsDocView.Builder settingsDoc = SettingsDocView.newBuilder();
    ApiModel model = context.getApiModel();
    settingsDoc.serviceAddress(model.getServiceAddress());
    settingsDoc.servicePort(model.getServicePort());
    settingsDoc.transportProtocol(productConfig.getTransportProtocol());
    settingsDoc.exampleApiMethodName(exampleApiMethod.name());
    settingsDoc.exampleApiMethodSettingsGetter(exampleApiMethod.settingsGetterName());
    settingsDoc.apiClassName(apiClassName);
    settingsDoc.settingsVarName(namer.getApiSettingsVariableName(context.getInterfaceConfig()));
    settingsDoc.settingsClassName(settingsClassName);
    settingsDoc.settingsBuilderVarName(namer.getApiSettingsBuilderVarName(context.getInterfaceConfig()));
    settingsDoc.hasDefaultInstance(context.getInterfaceConfig().hasDefaultInstance());
    return settingsDoc.build();
}
Also used : SettingsDocView(com.google.api.codegen.viewmodel.SettingsDocView) ApiModel(com.google.api.codegen.config.ApiModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 29 with SurfaceNamer

use of com.google.api.codegen.transformer.SurfaceNamer 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)

Example 30 with SurfaceNamer

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

the class NodeJSGapicSurfaceDocTransformer method generateDoc.

private ViewModel generateDoc(ProtoFile file, GapicProductConfig productConfig) {
    ModelTypeTable typeTable = new ModelTypeTable(new JSTypeTable(productConfig.getPackageName()), new NodeJSModelTypeNameConverter(productConfig.getPackageName()));
    // Use file path for package name to get file-specific package instead of package for the API.
    SurfaceNamer namer = new NodeJSSurfaceNamer(productConfig.getPackageName(), NodeJSUtils.isGcloud(productConfig));
    JSCommentReformatter commentReformatter = new JSCommentReformatter();
    GrpcDocView.Builder doc = GrpcDocView.newBuilder();
    doc.templateFileName(DOC_TEMPLATE_FILENAME);
    doc.outputPath(getOutputPath(namer, file));
    doc.fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer));
    doc.elementDocs(grpcElementDocTransformer.generateElementDocs(typeTable, namer, file));
    return doc.build();
}
Also used : JSTypeTable(com.google.api.codegen.util.js.JSTypeTable) JSCommentReformatter(com.google.api.codegen.util.js.JSCommentReformatter) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) GrpcDocView(com.google.api.codegen.viewmodel.GrpcDocView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Aggregations

SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)91 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)22 InterfaceModel (com.google.api.codegen.config.InterfaceModel)18 ImmutableList (com.google.common.collect.ImmutableList)16 ViewModel (com.google.api.codegen.viewmodel.ViewModel)14 ArrayList (java.util.ArrayList)14 GapicInterfaceContext (com.google.api.codegen.transformer.GapicInterfaceContext)13 MethodModel (com.google.api.codegen.config.MethodModel)12 FileHeaderView (com.google.api.codegen.viewmodel.FileHeaderView)10 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)10 MethodConfig (com.google.api.codegen.config.MethodConfig)9 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)9 ApiModel (com.google.api.codegen.config.ApiModel)8 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)8 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)8 SmokeTestClassView (com.google.api.codegen.viewmodel.testing.SmokeTestClassView)8 FieldConfig (com.google.api.codegen.config.FieldConfig)6 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)6 ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)5 PackageMetadataNamer (com.google.api.codegen.transformer.PackageMetadataNamer)5