Search in sources :

Example 16 with InterfaceConfig

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

the class PathTemplateTransformer method generatePathTemplateGetterFunctions.

public List<PathTemplateGetterFunctionView> generatePathTemplateGetterFunctions(GapicInterfaceContext context) {
    List<PathTemplateGetterFunctionView> functions = new ArrayList<>();
    SurfaceNamer namer = context.getNamer();
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    for (SingleResourceNameConfig resourceNameConfig : getSingleResourceNameConfigsUsedByInterface(context)) {
        PathTemplateGetterFunctionView.Builder function = PathTemplateGetterFunctionView.newBuilder().name(namer.getPathTemplateNameGetter(interfaceConfig, resourceNameConfig)).resourceName(namer.getPathTemplateResourcePhraseName(resourceNameConfig)).entityName(namer.getEntityName(resourceNameConfig)).pathTemplateName(namer.getPathTemplateName(interfaceConfig, resourceNameConfig)).pattern(resourceNameConfig.getNamePattern());
        functions.add(function.build());
    }
    return functions;
}
Also used : PathTemplateGetterFunctionView(com.google.api.codegen.viewmodel.PathTemplateGetterFunctionView) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) ArrayList(java.util.ArrayList) SingleResourceNameConfig(com.google.api.codegen.config.SingleResourceNameConfig)

Example 17 with InterfaceConfig

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

the class ServiceTransformer method generateServiceDoc.

public ServiceDocView generateServiceDoc(InterfaceContext context, ApiMethodView exampleApiMethod, GapicProductConfig productConfig) {
    SurfaceNamer namer = context.getNamer();
    ServiceDocView.Builder serviceDoc = ServiceDocView.newBuilder();
    ImmutableList.Builder<String> docLines = ImmutableList.builder();
    docLines.addAll(namer.getDocLines(context.getInterfaceDescription()));
    InterfaceConfig conf = context.getInterfaceConfig();
    if (!conf.getManualDoc().isEmpty()) {
        docLines.add("");
        docLines.addAll(namer.getDocLines(conf.getManualDoc()));
    }
    List<String> lines = docLines.build();
    serviceDoc.lines(lines);
    if (lines.isEmpty()) {
        serviceDoc.firstLine("");
        serviceDoc.remainingLines(ImmutableList.<String>of());
    } else {
        serviceDoc.firstLine(lines.get(0));
        serviceDoc.remainingLines(lines.subList(1, lines.size()));
    }
    serviceDoc.exampleApiMethod(exampleApiMethod);
    serviceDoc.apiVarName(namer.getApiWrapperVariableName(context.getInterfaceConfig()));
    serviceDoc.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    serviceDoc.settingsVarName(namer.getApiSettingsVariableName(context.getInterfaceConfig()));
    serviceDoc.settingsClassName(namer.getApiSettingsClassName(context.getInterfaceConfig()));
    serviceDoc.hasDefaultInstance(context.getInterfaceConfig().hasDefaultInstance());
    serviceDoc.serviceTitle(context.serviceTitle());
    serviceDoc.defaultTransportProviderBuilder(namer.getDefaultTransportProviderBuilder(productConfig.getTransportProtocol()));
    serviceDoc.defaultChannelProviderBuilder(namer.getDefaultChannelProviderBuilder(productConfig.getTransportProtocol()));
    return serviceDoc.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) ServiceDocView(com.google.api.codegen.viewmodel.ServiceDocView) ImmutableList(com.google.common.collect.ImmutableList)

Example 18 with InterfaceConfig

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

the class JavaSurfaceTransformer method addStubInterfaceImports.

private void addStubInterfaceImports(InterfaceContext context) {
    ImportTypeTable typeTable = context.getImportTypeTable();
    typeTable.saveNicknameFor("com.google.api.core.BetaApi");
    typeTable.saveNicknameFor("com.google.api.gax.core.BackgroundResource");
    typeTable.saveNicknameFor("com.google.api.gax.rpc.UnaryCallable");
    typeTable.saveNicknameFor("javax.annotation.Generated");
    typeTable.saveNicknameFor("java.lang.Void");
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    if (interfaceConfig.hasLongRunningOperations()) {
        typeTable.saveNicknameFor("com.google.longrunning.Operation");
        typeTable.saveNicknameFor("com.google.longrunning.stub.OperationsStub");
    }
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable)

Example 19 with InterfaceConfig

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

the class JavaSurfaceTransformer method addSettingsImports.

private void addSettingsImports(InterfaceContext context) {
    ImportTypeTable typeTable = context.getImportTypeTable();
    typeTable.saveNicknameFor("com.google.api.core.ApiFunction");
    typeTable.saveNicknameFor("com.google.api.core.BetaApi");
    typeTable.saveNicknameFor("com.google.api.gax.core.CredentialsProvider");
    typeTable.saveNicknameFor("com.google.api.gax.core.ExecutorProvider");
    typeTable.saveNicknameFor("com.google.api.gax.core.GaxProperties");
    typeTable.saveNicknameFor("com.google.api.gax.core.GoogleCredentialsProvider");
    typeTable.saveNicknameFor("com.google.api.gax.core.InstantiatingExecutorProvider");
    typeTable.saveNicknameFor("com.google.api.gax.retrying.RetrySettings");
    typeTable.saveNicknameFor("com.google.api.gax.rpc.ApiClientHeaderProvider");
    typeTable.saveNicknameFor("com.google.api.gax.rpc.ClientContext");
    typeTable.saveNicknameFor("com.google.api.gax.rpc.ClientSettings");
    typeTable.saveNicknameFor("com.google.api.gax.rpc.StubSettings");
    typeTable.saveNicknameFor("com.google.api.gax.rpc.HeaderProvider");
    typeTable.saveNicknameFor("com.google.api.gax.rpc.StatusCode");
    typeTable.saveNicknameFor("com.google.api.gax.rpc.TransportChannelProvider");
    typeTable.saveNicknameFor("com.google.api.gax.rpc.UnaryCallSettings");
    typeTable.saveNicknameFor("com.google.auth.Credentials");
    typeTable.saveNicknameFor("com.google.common.collect.ImmutableList");
    typeTable.saveNicknameFor("com.google.common.collect.ImmutableMap");
    typeTable.saveNicknameFor("com.google.common.collect.ImmutableSet");
    typeTable.saveNicknameFor("com.google.common.collect.Lists");
    typeTable.saveNicknameFor("com.google.common.collect.Sets");
    typeTable.saveNicknameFor("java.io.IOException");
    typeTable.saveNicknameFor("java.util.List");
    typeTable.saveNicknameFor("java.util.concurrent.ScheduledExecutorService");
    typeTable.saveNicknameFor("javax.annotation.Generated");
    typeTable.saveNicknameFor("org.threeten.bp.Duration");
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    if (interfaceConfig.hasPageStreamingMethods()) {
        typeTable.saveNicknameFor("com.google.api.core.ApiFuture");
        typeTable.saveNicknameFor("com.google.api.gax.rpc.ApiCallContext");
        typeTable.saveNicknameFor("com.google.api.gax.rpc.PageContext");
        typeTable.saveNicknameFor("com.google.api.gax.rpc.PagedCallSettings");
        typeTable.saveNicknameFor("com.google.api.gax.rpc.PagedListDescriptor");
        typeTable.saveNicknameFor("com.google.api.gax.rpc.PagedListResponseFactory");
        typeTable.saveNicknameFor("com.google.api.gax.rpc.UnaryCallable");
    }
    if (interfaceConfig.hasBatchingMethods()) {
        typeTable.saveNicknameFor("com.google.api.gax.batching.BatchingSettings");
        typeTable.saveNicknameFor("com.google.api.gax.batching.FlowController");
        typeTable.saveNicknameFor("com.google.api.gax.batching.FlowController.LimitExceededBehavior");
        typeTable.saveNicknameFor("com.google.api.gax.batching.FlowControlSettings");
        typeTable.saveNicknameFor("com.google.api.gax.batching.PartitionKey");
        typeTable.saveNicknameFor("com.google.api.gax.batching.RequestBuilder");
        typeTable.saveNicknameFor("com.google.api.gax.rpc.BatchedRequestIssuer");
        typeTable.saveNicknameFor("com.google.api.gax.rpc.BatchingCallSettings");
        typeTable.saveNicknameFor("com.google.api.gax.rpc.BatchingDescriptor");
        typeTable.saveNicknameFor("java.util.ArrayList");
        typeTable.saveNicknameFor("java.util.Collection");
    }
    if (interfaceConfig.hasGrpcStreamingMethods(GrpcStreamingType.ServerStreaming)) {
        typeTable.saveNicknameFor("com.google.api.gax.rpc.ServerStreamingCallSettings");
    }
    if (interfaceConfig.hasGrpcStreamingMethods(GrpcStreamingType.ClientStreaming) || interfaceConfig.hasGrpcStreamingMethods(GrpcStreamingType.BidiStreaming)) {
        typeTable.saveNicknameFor("com.google.api.gax.rpc.StreamingCallSettings");
    }
    if (interfaceConfig.hasLongRunningOperations()) {
        typeTable.saveNicknameFor("com.google.api.gax.longrunning.OperationSnapshot");
        typeTable.saveNicknameFor("com.google.api.gax.rpc.OperationCallSettings");
        typeTable.saveNicknameFor("com.google.longrunning.Operation");
        typeTable.saveNicknameFor("com.google.api.gax.longrunning.OperationTimedPollAlgorithm");
    }
    switch(context.getProductConfig().getTransportProtocol()) {
        case GRPC:
            typeTable.saveNicknameFor("com.google.api.gax.grpc.GrpcTransportChannel");
            typeTable.saveNicknameFor("com.google.api.gax.grpc.InstantiatingGrpcChannelProvider");
            if (interfaceConfig.hasLongRunningOperations()) {
                typeTable.saveNicknameFor("com.google.api.gax.grpc.ProtoOperationTransformers");
            }
            typeTable.saveNicknameFor("com.google.api.gax.grpc.GaxGrpcProperties");
            break;
        case HTTP:
            typeTable.saveNicknameFor("com.google.api.gax.httpjson.HttpJsonTransportChannel");
            typeTable.saveNicknameFor("com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider");
            typeTable.saveNicknameFor("com.google.api.gax.httpjson.GaxHttpJsonProperties");
            typeTable.saveNicknameFor("java.lang.Void");
            break;
    }
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) ImportTypeTable(com.google.api.codegen.transformer.ImportTypeTable)

Example 20 with InterfaceConfig

use of com.google.api.codegen.config.InterfaceConfig 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 = 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(packageMetadataConfig.releaseLevel(TargetLanguage.JAVA)));
    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.transformer.InterfaceContext)

Aggregations

InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)23 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)7 ImmutableList (com.google.common.collect.ImmutableList)5 InterfaceModel (com.google.api.codegen.config.InterfaceModel)4 SingleResourceNameConfig (com.google.api.codegen.config.SingleResourceNameConfig)4 GapicInterfaceConfig (com.google.api.codegen.config.GapicInterfaceConfig)3 MethodConfig (com.google.api.codegen.config.MethodConfig)3 ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)3 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)3 Interface (com.google.api.tools.framework.model.Interface)3 ArrayList (java.util.ArrayList)3 ApiModel (com.google.api.codegen.config.ApiModel)2 GapicMethodConfig (com.google.api.codegen.config.GapicMethodConfig)2 ProtoInterfaceModel (com.google.api.codegen.config.ProtoInterfaceModel)2 InterfaceContext (com.google.api.codegen.transformer.InterfaceContext)2 TypeAlias (com.google.api.codegen.util.TypeAlias)2 StaticLangSettingsView (com.google.api.codegen.viewmodel.StaticLangSettingsView)2 HashSet (java.util.HashSet)2 InterfaceView (com.google.api.codegen.InterfaceView)1 ServiceMessages (com.google.api.codegen.ServiceMessages)1