Search in sources :

Example 1 with Method

use of com.google.api.generator.gapic.model.Method in project gapic-generator-java by googleapis.

the class AbstractServiceStubSettingsClassComposer method createBuilderHelperMethods.

protected List<MethodDefinition> createBuilderHelperMethods(Service service, TypeStore typeStore) {
    List<MethodDefinition> javaMethods = new ArrayList<>();
    final TypeNode builderReturnType = typeStore.get(NESTED_BUILDER_CLASS_NAME);
    // Create the newBuilder(ClientContext) method.
    Function<Expr, NewObjectExpr> newBuilderFn = argExpr -> NewObjectExpr.builder().setType(builderReturnType).setArguments(argExpr).build();
    VariableExpr clientContextVarExpr = VariableExpr.withVariable(Variable.builder().setType(FIXED_TYPESTORE.get("ClientContext")).setName("clientContext").build());
    javaMethods.add(MethodDefinition.builder().setHeaderCommentStatements(SettingsCommentComposer.NEW_BUILDER_METHOD_COMMENT).setScope(ScopeNode.PUBLIC).setIsStatic(true).setReturnType(builderReturnType).setName("newBuilder").setArguments(clientContextVarExpr.toBuilder().setIsDecl(true).build()).setReturnExpr(newBuilderFn.apply(clientContextVarExpr)).build());
    // Create the toBuilder method.
    javaMethods.add(MethodDefinition.builder().setHeaderCommentStatements(SettingsCommentComposer.TO_BUILDER_METHOD_COMMENT).setScope(ScopeNode.PUBLIC).setReturnType(builderReturnType).setName("toBuilder").setReturnExpr(newBuilderFn.apply(ValueExpr.withValue(ThisObjectValue.withType(typeStore.get(ClassNames.getServiceStubClassName(service)))))).build());
    return javaMethods;
}
Also used : Arrays(java.util.Arrays) BatchingDescriptor(com.google.api.gax.rpc.BatchingDescriptor) GapicServiceConfig(com.google.api.generator.gapic.model.GapicServiceConfig) ServerStreamingCallSettings(com.google.api.gax.rpc.ServerStreamingCallSettings) ReferenceConstructorExpr(com.google.api.generator.engine.ast.ReferenceConstructorExpr) StringObjectValue(com.google.api.generator.engine.ast.StringObjectValue) PagedCallSettings(com.google.api.gax.rpc.PagedCallSettings) Empty(com.google.protobuf.Empty) MethodDefinition(com.google.api.generator.engine.ast.MethodDefinition) TypeStore(com.google.api.generator.gapic.composer.store.TypeStore) Method(com.google.api.generator.gapic.model.Method) PrimitiveValue(com.google.api.generator.engine.ast.PrimitiveValue) Stream(com.google.api.generator.gapic.model.Method.Stream) Map(java.util.Map) ConcreteReference(com.google.api.generator.engine.ast.ConcreteReference) PartitionKey(com.google.api.gax.batching.PartitionKey) ApiClientHeaderProvider(com.google.api.gax.rpc.ApiClientHeaderProvider) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) Set(java.util.Set) ScopeNode(com.google.api.generator.engine.ast.ScopeNode) EmptyLineStatement(com.google.api.generator.engine.ast.EmptyLineStatement) ApiFuture(com.google.api.core.ApiFuture) Duration(org.threeten.bp.Duration) LimitExceededBehavior(com.google.api.gax.batching.FlowController.LimitExceededBehavior) GoogleCredentialsProvider(com.google.api.gax.core.GoogleCredentialsProvider) BatchedRequestIssuer(com.google.api.gax.rpc.BatchedRequestIssuer) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) VaporReference(com.google.api.generator.engine.ast.VaporReference) IfStatement(com.google.api.generator.engine.ast.IfStatement) BetaApi(com.google.api.core.BetaApi) TypeNode(com.google.api.generator.engine.ast.TypeNode) ClientContext(com.google.api.gax.rpc.ClientContext) ReturnExpr(com.google.api.generator.engine.ast.ReturnExpr) ArrayList(java.util.ArrayList) RetrySettings(com.google.api.gax.retrying.RetrySettings) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) LinkedHashMap(java.util.LinkedHashMap) Expr(com.google.api.generator.engine.ast.Expr) Lists(com.google.common.collect.Lists) StubSettings(com.google.api.gax.rpc.StubSettings) BatchingCallSettings(com.google.api.gax.rpc.BatchingCallSettings) Nullable(javax.annotation.Nullable) CastExpr(com.google.api.generator.engine.ast.CastExpr) CommentStatement(com.google.api.generator.engine.ast.CommentStatement) IOException(java.io.IOException) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) InstantiatingExecutorProvider(com.google.api.gax.core.InstantiatingExecutorProvider) GapicBatchingSettings(com.google.api.generator.gapic.model.GapicBatchingSettings) AnonymousClassExpr(com.google.api.generator.engine.ast.AnonymousClassExpr) GapicClass(com.google.api.generator.gapic.model.GapicClass) SuperObjectValue(com.google.api.generator.engine.ast.SuperObjectValue) SampleComposerUtil(com.google.api.generator.gapic.composer.samplecode.SampleComposerUtil) Preconditions(com.google.common.base.Preconditions) StatusCode(com.google.api.gax.rpc.StatusCode) MonitoredResourceDescriptor(com.google.api.MonitoredResourceDescriptor) RequestBuilder(com.google.api.gax.batching.RequestBuilder) BiFunction(java.util.function.BiFunction) Reference(com.google.api.generator.engine.ast.Reference) ThisObjectValue(com.google.api.generator.engine.ast.ThisObjectValue) Variable(com.google.api.generator.engine.ast.Variable) Field(com.google.api.generator.gapic.model.Field) Generated(javax.annotation.Generated) StreamingCallSettings(com.google.api.gax.rpc.StreamingCallSettings) ImmutableSet(com.google.common.collect.ImmutableSet) SettingsSampleComposer(com.google.api.generator.gapic.composer.samplecode.SettingsSampleComposer) ImmutableMap(com.google.common.collect.ImmutableMap) PageContext(com.google.api.gax.rpc.PageContext) BatchingSettings(com.google.api.gax.batching.BatchingSettings) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ClassNames(com.google.api.generator.gapic.composer.utils.ClassNames) List(java.util.List) OperationCallSettings(com.google.api.gax.rpc.OperationCallSettings) SampleCodeWriter(com.google.api.generator.gapic.composer.samplecode.SampleCodeWriter) TransportChannelProvider(com.google.api.gax.rpc.TransportChannelProvider) Optional(java.util.Optional) GapicContext(com.google.api.generator.gapic.model.GapicContext) ApiFunction(com.google.api.core.ApiFunction) SettingsCommentComposer(com.google.api.generator.gapic.composer.comment.SettingsCommentComposer) ApiCallContext(com.google.api.gax.rpc.ApiCallContext) FlowControlSettings(com.google.api.gax.batching.FlowControlSettings) ClassDefinition(com.google.api.generator.engine.ast.ClassDefinition) PackageChecker(com.google.api.generator.gapic.composer.utils.PackageChecker) Operation(com.google.longrunning.Operation) Function(java.util.function.Function) PagedListResponseFactory(com.google.api.gax.rpc.PagedListResponseFactory) HashSet(java.util.HashSet) GaxProperties(com.google.api.gax.core.GaxProperties) UnaryCallSettings(com.google.api.gax.rpc.UnaryCallSettings) TernaryExpr(com.google.api.generator.engine.ast.TernaryExpr) ImmutableList(com.google.common.collect.ImmutableList) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Iterator(java.util.Iterator) AnnotationNode(com.google.api.generator.engine.ast.AnnotationNode) Sample(com.google.api.generator.gapic.model.Sample) UnaryCallable(com.google.api.gax.rpc.UnaryCallable) Statement(com.google.api.generator.engine.ast.Statement) Service(com.google.api.generator.gapic.model.Service) OperationTimedPollAlgorithm(com.google.api.gax.longrunning.OperationTimedPollAlgorithm) PagedListDescriptor(com.google.api.gax.rpc.PagedListDescriptor) JavaStyle(com.google.api.generator.gapic.utils.JavaStyle) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) Message(com.google.api.generator.gapic.model.Message) Collections(java.util.Collections) ReferenceConstructorExpr(com.google.api.generator.engine.ast.ReferenceConstructorExpr) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) ReturnExpr(com.google.api.generator.engine.ast.ReturnExpr) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) Expr(com.google.api.generator.engine.ast.Expr) CastExpr(com.google.api.generator.engine.ast.CastExpr) AnonymousClassExpr(com.google.api.generator.engine.ast.AnonymousClassExpr) TernaryExpr(com.google.api.generator.engine.ast.TernaryExpr) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) MethodDefinition(com.google.api.generator.engine.ast.MethodDefinition) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) ArrayList(java.util.ArrayList) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode)

Example 2 with Method

use of com.google.api.generator.gapic.model.Method in project gapic-generator-java by googleapis.

the class AbstractServiceStubSettingsClassComposer method createNestedClassConstructorMethods.

private static List<MethodDefinition> createNestedClassConstructorMethods(Service service, GapicServiceConfig serviceConfig, Map<String, VariableExpr> nestedMethodSettingsMemberVarExprs, TypeStore typeStore) {
    TypeNode builderType = typeStore.get(NESTED_BUILDER_CLASS_NAME);
    List<MethodDefinition> ctorMethods = new ArrayList<>();
    // First argument-less contructor.
    ctorMethods.add(MethodDefinition.constructorBuilder().setScope(ScopeNode.PROTECTED).setReturnType(builderType).setBody(Arrays.asList(ExprStatement.withExpr(ReferenceConstructorExpr.thisBuilder().setType(builderType).setArguments(CastExpr.builder().setType(FIXED_TYPESTORE.get("ClientContext")).setExpr(ValueExpr.createNullExpr()).build()).build()))).build());
    // Second ctor that takes a clientContext argument.
    VariableExpr clientContextVarExpr = VariableExpr.withVariable(Variable.builder().setType(FIXED_TYPESTORE.get("ClientContext")).setName("clientContext").build());
    Reference pagedSettingsBuilderRef = ConcreteReference.withClazz(PagedCallSettings.Builder.class);
    Reference batchingSettingsBuilderRef = ConcreteReference.withClazz(BatchingCallSettings.Builder.class);
    Reference unaryCallSettingsBuilderRef = ConcreteReference.withClazz(UnaryCallSettings.Builder.class);
    Function<TypeNode, Boolean> isUnaryCallSettingsBuilderFn = t -> t.reference().copyAndSetGenerics(ImmutableList.of()).equals(unaryCallSettingsBuilderRef);
    Function<TypeNode, Boolean> isPagedCallSettingsBuilderFn = t -> t.reference().copyAndSetGenerics(ImmutableList.of()).equals(pagedSettingsBuilderRef);
    Function<TypeNode, Boolean> isBatchingCallSettingsBuilderFn = t -> t.reference().copyAndSetGenerics(ImmutableList.of()).equals(batchingSettingsBuilderRef);
    Function<TypeNode, TypeNode> builderToCallSettingsFn = t -> TypeNode.withReference(VaporReference.builder().setName(String.join(DOT, t.reference().enclosingClassNames())).setPakkage(t.reference().pakkage()).build());
    List<Statement> ctorBodyStatements = new ArrayList<>();
    ctorBodyStatements.add(ExprStatement.withExpr(ReferenceConstructorExpr.superBuilder().setType(builderType).setArguments(clientContextVarExpr).build()));
    ctorBodyStatements.add(EMPTY_LINE_STATEMENT);
    ctorBodyStatements.addAll(nestedMethodSettingsMemberVarExprs.entrySet().stream().map(e -> {
        // TODO(miraleung): Extract this into another method.
        // Name is fooBarSettings.
        VariableExpr varExpr = e.getValue();
        TypeNode varType = varExpr.type();
        Preconditions.checkState(e.getKey().endsWith(SETTINGS_LITERAL), String.format("%s expected to end with \"Settings\"", e.getKey()));
        String methodName = getMethodNameFromSettingsVarName(e.getKey());
        if (!isPagedCallSettingsBuilderFn.apply(varType)) {
            if (!isBatchingCallSettingsBuilderFn.apply(varType)) {
                boolean isUnaryCallSettings = isUnaryCallSettingsBuilderFn.apply(varType);
                Expr builderExpr = AssignmentExpr.builder().setVariableExpr(varExpr).setValueExpr(MethodInvocationExpr.builder().setStaticReferenceType(builderToCallSettingsFn.apply(varExpr.type())).setMethodName(isUnaryCallSettings ? "newUnaryCallSettingsBuilder" : "newBuilder").setReturnType(varExpr.type()).build()).build();
                return ExprStatement.withExpr(builderExpr);
            }
            Expr newBatchingSettingsExpr = MethodInvocationExpr.builder().setStaticReferenceType(FIXED_TYPESTORE.get("BatchingSettings")).setMethodName("newBuilder").build();
            newBatchingSettingsExpr = MethodInvocationExpr.builder().setExprReferenceExpr(newBatchingSettingsExpr).setMethodName("build").build();
            String batchingDescVarName = String.format(BATCHING_DESC_PATTERN, JavaStyle.toUpperSnakeCase(methodName));
            Expr batchingSettingsBuilderExpr = MethodInvocationExpr.builder().setStaticReferenceType(builderToCallSettingsFn.apply(varType)).setMethodName("newBuilder").setArguments(VariableExpr.withVariable(Variable.builder().setType(FIXED_TYPESTORE.get("BatchingDescriptor")).setName(batchingDescVarName).build())).build();
            batchingSettingsBuilderExpr = MethodInvocationExpr.builder().setExprReferenceExpr(batchingSettingsBuilderExpr).setMethodName("setBatchingSettings").setArguments(newBatchingSettingsExpr).setReturnType(varType).build();
            Expr builderExpr = AssignmentExpr.builder().setVariableExpr(varExpr).setValueExpr(batchingSettingsBuilderExpr).build();
            return ExprStatement.withExpr(builderExpr);
        }
        String memberVarName = String.format(PAGED_RESPONSE_FACTORY_PATTERN, JavaStyle.toUpperSnakeCase(methodName));
        VariableExpr argVar = VariableExpr.withVariable(Variable.builder().setType(FIXED_TYPESTORE.get("PagedListResponseFactory")).setName(memberVarName).build());
        Expr builderExpr = AssignmentExpr.builder().setVariableExpr(varExpr).setValueExpr(MethodInvocationExpr.builder().setStaticReferenceType(builderToCallSettingsFn.apply(varExpr.type())).setMethodName("newBuilder").setArguments(argVar).setReturnType(varExpr.type()).build()).build();
        return ExprStatement.withExpr(builderExpr);
    }).collect(Collectors.toList()));
    Expr unaryMethodSettingsBuildersAssignExpr = AssignmentExpr.builder().setVariableExpr(NESTED_UNARY_METHOD_SETTINGS_BUILDERS_VAR_EXPR).setValueExpr(MethodInvocationExpr.builder().setStaticReferenceType(FIXED_TYPESTORE.get("ImmutableList")).setGenerics(NESTED_UNARY_METHOD_SETTINGS_BUILDERS_VAR_EXPR.type().reference().generics()).setMethodName("of").setArguments(nestedMethodSettingsMemberVarExprs.values().stream().filter(v -> isUnaryCallSettingsBuilderFn.apply(v.type()) || isPagedCallSettingsBuilderFn.apply(v.type()) || isBatchingCallSettingsBuilderFn.apply(v.type())).collect(Collectors.toList())).setReturnType(NESTED_UNARY_METHOD_SETTINGS_BUILDERS_VAR_EXPR.type()).build()).build();
    ctorBodyStatements.add(EMPTY_LINE_STATEMENT);
    ctorBodyStatements.add(ExprStatement.withExpr(unaryMethodSettingsBuildersAssignExpr));
    ctorBodyStatements.add(ExprStatement.withExpr(MethodInvocationExpr.builder().setMethodName("initDefaults").setArguments(ValueExpr.withValue(ThisObjectValue.withType(builderType))).build()));
    ctorMethods.add(MethodDefinition.constructorBuilder().setScope(ScopeNode.PROTECTED).setReturnType(builderType).setArguments(clientContextVarExpr.toBuilder().setIsDecl(true).build()).setBody(ctorBodyStatements).build());
    // Third constructor that takes a ServiceStubSettings.
    TypeNode outerSettingsType = typeStore.get(ClassNames.getServiceStubSettingsClassName(service));
    VariableExpr settingsVarExpr = VariableExpr.withVariable(Variable.builder().setType(outerSettingsType).setName("settings").build());
    ctorBodyStatements = new ArrayList<>();
    ctorBodyStatements.add(ExprStatement.withExpr(ReferenceConstructorExpr.superBuilder().setType(builderType).setArguments(settingsVarExpr).build()));
    ctorBodyStatements.add(EMPTY_LINE_STATEMENT);
    // TODO(cleanup): Technically this should actually use the outer class's <method>Settings
    // members to avoid decoupling variable names.
    ctorBodyStatements.addAll(nestedMethodSettingsMemberVarExprs.values().stream().map(v -> ExprStatement.withExpr(AssignmentExpr.builder().setVariableExpr(v).setValueExpr(MethodInvocationExpr.builder().setExprReferenceExpr(VariableExpr.builder().setExprReferenceExpr(settingsVarExpr).setVariable(v.variable()).build()).setMethodName("toBuilder").setReturnType(v.type()).build()).build())).collect(Collectors.toList()));
    ctorBodyStatements.add(EMPTY_LINE_STATEMENT);
    ctorBodyStatements.add(ExprStatement.withExpr(unaryMethodSettingsBuildersAssignExpr));
    ctorMethods.add(MethodDefinition.constructorBuilder().setScope(ScopeNode.PROTECTED).setReturnType(builderType).setArguments(settingsVarExpr.toBuilder().setIsDecl(true).build()).setBody(ctorBodyStatements).build());
    return ctorMethods;
}
Also used : Arrays(java.util.Arrays) BatchingDescriptor(com.google.api.gax.rpc.BatchingDescriptor) GapicServiceConfig(com.google.api.generator.gapic.model.GapicServiceConfig) ServerStreamingCallSettings(com.google.api.gax.rpc.ServerStreamingCallSettings) ReferenceConstructorExpr(com.google.api.generator.engine.ast.ReferenceConstructorExpr) StringObjectValue(com.google.api.generator.engine.ast.StringObjectValue) PagedCallSettings(com.google.api.gax.rpc.PagedCallSettings) Empty(com.google.protobuf.Empty) MethodDefinition(com.google.api.generator.engine.ast.MethodDefinition) TypeStore(com.google.api.generator.gapic.composer.store.TypeStore) Method(com.google.api.generator.gapic.model.Method) PrimitiveValue(com.google.api.generator.engine.ast.PrimitiveValue) Stream(com.google.api.generator.gapic.model.Method.Stream) Map(java.util.Map) ConcreteReference(com.google.api.generator.engine.ast.ConcreteReference) PartitionKey(com.google.api.gax.batching.PartitionKey) ApiClientHeaderProvider(com.google.api.gax.rpc.ApiClientHeaderProvider) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) Set(java.util.Set) ScopeNode(com.google.api.generator.engine.ast.ScopeNode) EmptyLineStatement(com.google.api.generator.engine.ast.EmptyLineStatement) ApiFuture(com.google.api.core.ApiFuture) Duration(org.threeten.bp.Duration) LimitExceededBehavior(com.google.api.gax.batching.FlowController.LimitExceededBehavior) GoogleCredentialsProvider(com.google.api.gax.core.GoogleCredentialsProvider) BatchedRequestIssuer(com.google.api.gax.rpc.BatchedRequestIssuer) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) VaporReference(com.google.api.generator.engine.ast.VaporReference) IfStatement(com.google.api.generator.engine.ast.IfStatement) BetaApi(com.google.api.core.BetaApi) TypeNode(com.google.api.generator.engine.ast.TypeNode) ClientContext(com.google.api.gax.rpc.ClientContext) ReturnExpr(com.google.api.generator.engine.ast.ReturnExpr) ArrayList(java.util.ArrayList) RetrySettings(com.google.api.gax.retrying.RetrySettings) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) LinkedHashMap(java.util.LinkedHashMap) Expr(com.google.api.generator.engine.ast.Expr) Lists(com.google.common.collect.Lists) StubSettings(com.google.api.gax.rpc.StubSettings) BatchingCallSettings(com.google.api.gax.rpc.BatchingCallSettings) Nullable(javax.annotation.Nullable) CastExpr(com.google.api.generator.engine.ast.CastExpr) CommentStatement(com.google.api.generator.engine.ast.CommentStatement) IOException(java.io.IOException) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) InstantiatingExecutorProvider(com.google.api.gax.core.InstantiatingExecutorProvider) GapicBatchingSettings(com.google.api.generator.gapic.model.GapicBatchingSettings) AnonymousClassExpr(com.google.api.generator.engine.ast.AnonymousClassExpr) GapicClass(com.google.api.generator.gapic.model.GapicClass) SuperObjectValue(com.google.api.generator.engine.ast.SuperObjectValue) SampleComposerUtil(com.google.api.generator.gapic.composer.samplecode.SampleComposerUtil) Preconditions(com.google.common.base.Preconditions) StatusCode(com.google.api.gax.rpc.StatusCode) MonitoredResourceDescriptor(com.google.api.MonitoredResourceDescriptor) RequestBuilder(com.google.api.gax.batching.RequestBuilder) BiFunction(java.util.function.BiFunction) Reference(com.google.api.generator.engine.ast.Reference) ThisObjectValue(com.google.api.generator.engine.ast.ThisObjectValue) Variable(com.google.api.generator.engine.ast.Variable) Field(com.google.api.generator.gapic.model.Field) Generated(javax.annotation.Generated) StreamingCallSettings(com.google.api.gax.rpc.StreamingCallSettings) ImmutableSet(com.google.common.collect.ImmutableSet) SettingsSampleComposer(com.google.api.generator.gapic.composer.samplecode.SettingsSampleComposer) ImmutableMap(com.google.common.collect.ImmutableMap) PageContext(com.google.api.gax.rpc.PageContext) BatchingSettings(com.google.api.gax.batching.BatchingSettings) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ClassNames(com.google.api.generator.gapic.composer.utils.ClassNames) List(java.util.List) OperationCallSettings(com.google.api.gax.rpc.OperationCallSettings) SampleCodeWriter(com.google.api.generator.gapic.composer.samplecode.SampleCodeWriter) TransportChannelProvider(com.google.api.gax.rpc.TransportChannelProvider) Optional(java.util.Optional) GapicContext(com.google.api.generator.gapic.model.GapicContext) ApiFunction(com.google.api.core.ApiFunction) SettingsCommentComposer(com.google.api.generator.gapic.composer.comment.SettingsCommentComposer) ApiCallContext(com.google.api.gax.rpc.ApiCallContext) FlowControlSettings(com.google.api.gax.batching.FlowControlSettings) ClassDefinition(com.google.api.generator.engine.ast.ClassDefinition) PackageChecker(com.google.api.generator.gapic.composer.utils.PackageChecker) Operation(com.google.longrunning.Operation) Function(java.util.function.Function) PagedListResponseFactory(com.google.api.gax.rpc.PagedListResponseFactory) HashSet(java.util.HashSet) GaxProperties(com.google.api.gax.core.GaxProperties) UnaryCallSettings(com.google.api.gax.rpc.UnaryCallSettings) TernaryExpr(com.google.api.generator.engine.ast.TernaryExpr) ImmutableList(com.google.common.collect.ImmutableList) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Iterator(java.util.Iterator) AnnotationNode(com.google.api.generator.engine.ast.AnnotationNode) Sample(com.google.api.generator.gapic.model.Sample) UnaryCallable(com.google.api.gax.rpc.UnaryCallable) Statement(com.google.api.generator.engine.ast.Statement) Service(com.google.api.generator.gapic.model.Service) OperationTimedPollAlgorithm(com.google.api.gax.longrunning.OperationTimedPollAlgorithm) PagedListDescriptor(com.google.api.gax.rpc.PagedListDescriptor) JavaStyle(com.google.api.generator.gapic.utils.JavaStyle) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) Message(com.google.api.generator.gapic.model.Message) Collections(java.util.Collections) ConcreteReference(com.google.api.generator.engine.ast.ConcreteReference) VaporReference(com.google.api.generator.engine.ast.VaporReference) Reference(com.google.api.generator.engine.ast.Reference) EmptyLineStatement(com.google.api.generator.engine.ast.EmptyLineStatement) IfStatement(com.google.api.generator.engine.ast.IfStatement) CommentStatement(com.google.api.generator.engine.ast.CommentStatement) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) Statement(com.google.api.generator.engine.ast.Statement) ArrayList(java.util.ArrayList) ReferenceConstructorExpr(com.google.api.generator.engine.ast.ReferenceConstructorExpr) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) ReturnExpr(com.google.api.generator.engine.ast.ReturnExpr) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) Expr(com.google.api.generator.engine.ast.Expr) CastExpr(com.google.api.generator.engine.ast.CastExpr) AnonymousClassExpr(com.google.api.generator.engine.ast.AnonymousClassExpr) TernaryExpr(com.google.api.generator.engine.ast.TernaryExpr) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) MethodDefinition(com.google.api.generator.engine.ast.MethodDefinition) UnaryCallSettings(com.google.api.gax.rpc.UnaryCallSettings) PagedCallSettings(com.google.api.gax.rpc.PagedCallSettings) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) BatchingCallSettings(com.google.api.gax.rpc.BatchingCallSettings)

Example 3 with Method

use of com.google.api.generator.gapic.model.Method in project gapic-generator-java by googleapis.

the class AbstractServiceStubSettingsClassComposer method createNestedClassInitDefaultsMethod.

private MethodDefinition createNestedClassInitDefaultsMethod(Service service, @Nullable GapicServiceConfig serviceConfig, TypeStore typeStore) {
    // TODO(miraleung): Robustify this against a null serviceConfig.
    TypeNode builderType = typeStore.get(NESTED_BUILDER_CLASS_NAME);
    VariableExpr builderVarExpr = VariableExpr.withVariable(Variable.builder().setType(builderType).setName("builder").build());
    List<Statement> bodyStatements = new ArrayList<>();
    // Iterate through methods twice to so we can have LRO expressions appear last.
    for (Method method : service.methods()) {
        Method.Stream streamKind = method.stream();
        if (streamKind.equals(Method.Stream.CLIENT) || streamKind.equals(Method.Stream.BIDI)) {
            continue;
        }
        if (!Objects.isNull(serviceConfig) && serviceConfig.hasBatchingSetting(service, method)) {
            Optional<GapicBatchingSettings> batchingSettingOpt = serviceConfig.getBatchingSetting(service, method);
            Preconditions.checkState(batchingSettingOpt.isPresent(), String.format("No batching setting found for service %s, method %s", service.name(), method.name()));
            String settingsGetterMethodName = String.format("%sSettings", JavaStyle.toLowerCamelCase(method.name()));
            bodyStatements.add(ExprStatement.withExpr(RetrySettingsComposer.createBatchingBuilderSettingsExpr(settingsGetterMethodName, batchingSettingOpt.get(), builderVarExpr)));
            bodyStatements.add(EMPTY_LINE_STATEMENT);
        }
        bodyStatements.add(ExprStatement.withExpr(RetrySettingsComposer.createSimpleBuilderSettingsExpr(service, serviceConfig, method, builderVarExpr, NESTED_RETRYABLE_CODE_DEFINITIONS_VAR_EXPR, NESTED_RETRY_PARAM_DEFINITIONS_VAR_EXPR)));
        bodyStatements.add(EMPTY_LINE_STATEMENT);
    }
    for (Method method : service.methods()) {
        if (!method.hasLro()) {
            continue;
        }
        bodyStatements.add(ExprStatement.withExpr(RetrySettingsComposer.createLroSettingsBuilderExpr(service, serviceConfig, method, builderVarExpr, NESTED_RETRYABLE_CODE_DEFINITIONS_VAR_EXPR, NESTED_RETRY_PARAM_DEFINITIONS_VAR_EXPR, getTransportContext().operationResponseTransformerType(), getTransportContext().operationMetadataTransformerType())));
        bodyStatements.add(EMPTY_LINE_STATEMENT);
    }
    return MethodDefinition.builder().setScope(ScopeNode.PRIVATE).setIsStatic(true).setReturnType(builderType).setName("initDefaults").setArguments(builderVarExpr.toBuilder().setIsDecl(true).build()).setBody(bodyStatements).setReturnExpr(builderVarExpr).build();
}
Also used : EmptyLineStatement(com.google.api.generator.engine.ast.EmptyLineStatement) IfStatement(com.google.api.generator.engine.ast.IfStatement) CommentStatement(com.google.api.generator.engine.ast.CommentStatement) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) Statement(com.google.api.generator.engine.ast.Statement) ArrayList(java.util.ArrayList) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) Method(com.google.api.generator.gapic.model.Method) Stream(com.google.api.generator.gapic.model.Method.Stream) GapicBatchingSettings(com.google.api.generator.gapic.model.GapicBatchingSettings)

Example 4 with Method

use of com.google.api.generator.gapic.model.Method in project gapic-generator-java by googleapis.

the class AbstractServiceStubSettingsClassComposer method createPagedListDescriptorAssignExpr.

private static Expr createPagedListDescriptorAssignExpr(VariableExpr pagedListDescVarExpr, Method method, TypeNode repeatedResponseType, String repeatedFieldName, Map<String, Message> messageTypes, TypeStore typeStore) {
    MethodDefinition.Builder methodStarterBuilder = MethodDefinition.builder().setIsOverride(true).setScope(ScopeNode.PUBLIC);
    List<MethodDefinition> anonClassMethods = new ArrayList<>();
    // Create emptyToken method.
    anonClassMethods.add(methodStarterBuilder.setReturnType(TypeNode.STRING).setName("emptyToken").setReturnExpr(ValueExpr.withValue(StringObjectValue.withValue(""))).build());
    // Create injectToken method.
    VariableExpr payloadVarExpr = VariableExpr.withVariable(Variable.builder().setType(method.inputType()).setName("payload").build());
    VariableExpr strTokenVarExpr = VariableExpr.withVariable(Variable.builder().setType(TypeNode.STRING).setName("token").build());
    TypeNode returnType = method.inputType();
    Expr newBuilderExpr = MethodInvocationExpr.builder().setStaticReferenceType(method.inputType()).setMethodName("newBuilder").setArguments(payloadVarExpr).build();
    Expr returnExpr = MethodInvocationExpr.builder().setExprReferenceExpr(newBuilderExpr).setMethodName("setPageToken").setArguments(strTokenVarExpr).build();
    returnExpr = MethodInvocationExpr.builder().setExprReferenceExpr(returnExpr).setMethodName("build").setReturnType(returnType).build();
    anonClassMethods.add(methodStarterBuilder.setReturnType(method.inputType()).setName("injectToken").setArguments(Arrays.asList(payloadVarExpr, strTokenVarExpr).stream().map(v -> v.toBuilder().setIsDecl(true).build()).collect(Collectors.toList())).setReturnExpr(returnExpr).build());
    // Create injectPageSize method.
    VariableExpr pageSizeVarExpr = VariableExpr.withVariable(Variable.builder().setType(TypeNode.INT).setName("pageSize").build());
    // Re-declare for clarity and easier readability.
    returnType = method.inputType();
    returnExpr = MethodInvocationExpr.builder().setExprReferenceExpr(newBuilderExpr).setMethodName("set" + JavaStyle.toUpperCamelCase(method.pageSizeFieldName())).setArguments(pageSizeVarExpr).build();
    returnExpr = MethodInvocationExpr.builder().setExprReferenceExpr(returnExpr).setMethodName("build").setReturnType(returnType).build();
    anonClassMethods.add(methodStarterBuilder.setReturnType(method.inputType()).setName("injectPageSize").setArguments(Arrays.asList(payloadVarExpr, pageSizeVarExpr).stream().map(v -> v.toBuilder().setIsDecl(true).build()).collect(Collectors.toList())).setReturnExpr(returnExpr).build());
    // TODO(miraleung): Test the edge cases where these proto fields aren't present.
    // Create extractPageSize method.
    returnType = TypeNode.INT_OBJECT;
    anonClassMethods.add(methodStarterBuilder.setReturnType(returnType).setName("extractPageSize").setArguments(payloadVarExpr.toBuilder().setIsDecl(true).build()).setReturnExpr(MethodInvocationExpr.builder().setExprReferenceExpr(payloadVarExpr).setMethodName("get" + JavaStyle.toUpperCamelCase(method.pageSizeFieldName())).setReturnType(returnType).build()).build());
    // Create extractNextToken method.
    returnType = TypeNode.STRING;
    payloadVarExpr = VariableExpr.withVariable(Variable.builder().setType(method.outputType()).setName("payload").build());
    anonClassMethods.add(methodStarterBuilder.setReturnType(returnType).setName("extractNextToken").setArguments(payloadVarExpr.toBuilder().setIsDecl(true).build()).setReturnExpr(MethodInvocationExpr.builder().setExprReferenceExpr(payloadVarExpr).setMethodName("getNextPageToken").setReturnType(returnType).build()).build());
    // Create extractResources method.
    returnType = TypeNode.withReference(ConcreteReference.builder().setClazz(Iterable.class).setGenerics(Arrays.asList(repeatedResponseType.reference())).build());
    Expr getResponsesExpr;
    Expr elseExpr;
    Expr thenExpr;
    if (repeatedResponseType.reference() != null && "java.util.Map.Entry".equals(repeatedResponseType.reference().fullName())) {
        getResponsesExpr = MethodInvocationExpr.builder().setExprReferenceExpr(payloadVarExpr).setMethodName(String.format("get%sMap", JavaStyle.toUpperCamelCase(repeatedFieldName))).setReturnType(returnType).build();
        thenExpr = MethodInvocationExpr.builder().setStaticReferenceType(TypeNode.withReference(ConcreteReference.withClazz(Collections.class))).setGenerics(Arrays.asList(repeatedResponseType.reference())).setMethodName("emptySet").setReturnType(returnType).build();
        elseExpr = MethodInvocationExpr.builder().setMethodName("entrySet").setExprReferenceExpr(MethodInvocationExpr.builder().setExprReferenceExpr(payloadVarExpr).setMethodName(String.format("get%sMap", JavaStyle.toUpperCamelCase(repeatedFieldName))).build()).setReturnType(returnType).build();
    } else {
        getResponsesExpr = MethodInvocationExpr.builder().setExprReferenceExpr(payloadVarExpr).setMethodName(String.format("get%sList", JavaStyle.toUpperCamelCase(repeatedFieldName))).setReturnType(returnType).build();
        thenExpr = MethodInvocationExpr.builder().setStaticReferenceType(TypeNode.withReference(ConcreteReference.withClazz(ImmutableList.class))).setGenerics(Arrays.asList(repeatedResponseType.reference())).setMethodName("of").setReturnType(returnType).build();
        elseExpr = getResponsesExpr;
    }
    // While protobufs should not be null, this null-check is needed to protect against NPEs
    // in paged iteration on clients that use legacy HTTP/JSON types, as these clients can
    // actually return null instead of an empty list.
    // Context:
    // Original issue: https://github.com/googleapis/google-cloud-java/issues/3736
    // Relevant discussion where this check was first added:
    // https://github.com/googleapis/google-cloud-java/pull/4499#discussion_r257057409
    Expr conditionExpr = RelationalOperationExpr.equalToWithExprs(getResponsesExpr, ValueExpr.createNullExpr());
    returnExpr = TernaryExpr.builder().setConditionExpr(conditionExpr).setThenExpr(thenExpr).setElseExpr(elseExpr).build();
    anonClassMethods.add(methodStarterBuilder.setReturnType(returnType).setName("extractResources").setArguments(payloadVarExpr.toBuilder().setIsDecl(true).build()).setReturnExpr(returnExpr).build());
    // Create the anonymous class.
    AnonymousClassExpr pagedListDescAnonClassExpr = AnonymousClassExpr.builder().setType(pagedListDescVarExpr.type()).setMethods(anonClassMethods).build();
    // Declare and assign the variable.
    return AssignmentExpr.builder().setVariableExpr(pagedListDescVarExpr.toBuilder().setIsDecl(true).setScope(ScopeNode.PRIVATE).setIsStatic(true).setIsFinal(true).build()).setValueExpr(pagedListDescAnonClassExpr).build();
}
Also used : Arrays(java.util.Arrays) BatchingDescriptor(com.google.api.gax.rpc.BatchingDescriptor) GapicServiceConfig(com.google.api.generator.gapic.model.GapicServiceConfig) ServerStreamingCallSettings(com.google.api.gax.rpc.ServerStreamingCallSettings) ReferenceConstructorExpr(com.google.api.generator.engine.ast.ReferenceConstructorExpr) StringObjectValue(com.google.api.generator.engine.ast.StringObjectValue) PagedCallSettings(com.google.api.gax.rpc.PagedCallSettings) Empty(com.google.protobuf.Empty) MethodDefinition(com.google.api.generator.engine.ast.MethodDefinition) TypeStore(com.google.api.generator.gapic.composer.store.TypeStore) Method(com.google.api.generator.gapic.model.Method) PrimitiveValue(com.google.api.generator.engine.ast.PrimitiveValue) Stream(com.google.api.generator.gapic.model.Method.Stream) Map(java.util.Map) ConcreteReference(com.google.api.generator.engine.ast.ConcreteReference) PartitionKey(com.google.api.gax.batching.PartitionKey) ApiClientHeaderProvider(com.google.api.gax.rpc.ApiClientHeaderProvider) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) Set(java.util.Set) ScopeNode(com.google.api.generator.engine.ast.ScopeNode) EmptyLineStatement(com.google.api.generator.engine.ast.EmptyLineStatement) ApiFuture(com.google.api.core.ApiFuture) Duration(org.threeten.bp.Duration) LimitExceededBehavior(com.google.api.gax.batching.FlowController.LimitExceededBehavior) GoogleCredentialsProvider(com.google.api.gax.core.GoogleCredentialsProvider) BatchedRequestIssuer(com.google.api.gax.rpc.BatchedRequestIssuer) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) VaporReference(com.google.api.generator.engine.ast.VaporReference) IfStatement(com.google.api.generator.engine.ast.IfStatement) BetaApi(com.google.api.core.BetaApi) TypeNode(com.google.api.generator.engine.ast.TypeNode) ClientContext(com.google.api.gax.rpc.ClientContext) ReturnExpr(com.google.api.generator.engine.ast.ReturnExpr) ArrayList(java.util.ArrayList) RetrySettings(com.google.api.gax.retrying.RetrySettings) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) LinkedHashMap(java.util.LinkedHashMap) Expr(com.google.api.generator.engine.ast.Expr) Lists(com.google.common.collect.Lists) StubSettings(com.google.api.gax.rpc.StubSettings) BatchingCallSettings(com.google.api.gax.rpc.BatchingCallSettings) Nullable(javax.annotation.Nullable) CastExpr(com.google.api.generator.engine.ast.CastExpr) CommentStatement(com.google.api.generator.engine.ast.CommentStatement) IOException(java.io.IOException) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) InstantiatingExecutorProvider(com.google.api.gax.core.InstantiatingExecutorProvider) GapicBatchingSettings(com.google.api.generator.gapic.model.GapicBatchingSettings) AnonymousClassExpr(com.google.api.generator.engine.ast.AnonymousClassExpr) GapicClass(com.google.api.generator.gapic.model.GapicClass) SuperObjectValue(com.google.api.generator.engine.ast.SuperObjectValue) SampleComposerUtil(com.google.api.generator.gapic.composer.samplecode.SampleComposerUtil) Preconditions(com.google.common.base.Preconditions) StatusCode(com.google.api.gax.rpc.StatusCode) MonitoredResourceDescriptor(com.google.api.MonitoredResourceDescriptor) RequestBuilder(com.google.api.gax.batching.RequestBuilder) BiFunction(java.util.function.BiFunction) Reference(com.google.api.generator.engine.ast.Reference) ThisObjectValue(com.google.api.generator.engine.ast.ThisObjectValue) Variable(com.google.api.generator.engine.ast.Variable) Field(com.google.api.generator.gapic.model.Field) Generated(javax.annotation.Generated) StreamingCallSettings(com.google.api.gax.rpc.StreamingCallSettings) ImmutableSet(com.google.common.collect.ImmutableSet) SettingsSampleComposer(com.google.api.generator.gapic.composer.samplecode.SettingsSampleComposer) ImmutableMap(com.google.common.collect.ImmutableMap) PageContext(com.google.api.gax.rpc.PageContext) BatchingSettings(com.google.api.gax.batching.BatchingSettings) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ClassNames(com.google.api.generator.gapic.composer.utils.ClassNames) List(java.util.List) OperationCallSettings(com.google.api.gax.rpc.OperationCallSettings) SampleCodeWriter(com.google.api.generator.gapic.composer.samplecode.SampleCodeWriter) TransportChannelProvider(com.google.api.gax.rpc.TransportChannelProvider) Optional(java.util.Optional) GapicContext(com.google.api.generator.gapic.model.GapicContext) ApiFunction(com.google.api.core.ApiFunction) SettingsCommentComposer(com.google.api.generator.gapic.composer.comment.SettingsCommentComposer) ApiCallContext(com.google.api.gax.rpc.ApiCallContext) FlowControlSettings(com.google.api.gax.batching.FlowControlSettings) ClassDefinition(com.google.api.generator.engine.ast.ClassDefinition) PackageChecker(com.google.api.generator.gapic.composer.utils.PackageChecker) Operation(com.google.longrunning.Operation) Function(java.util.function.Function) PagedListResponseFactory(com.google.api.gax.rpc.PagedListResponseFactory) HashSet(java.util.HashSet) GaxProperties(com.google.api.gax.core.GaxProperties) UnaryCallSettings(com.google.api.gax.rpc.UnaryCallSettings) TernaryExpr(com.google.api.generator.engine.ast.TernaryExpr) ImmutableList(com.google.common.collect.ImmutableList) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Iterator(java.util.Iterator) AnnotationNode(com.google.api.generator.engine.ast.AnnotationNode) Sample(com.google.api.generator.gapic.model.Sample) UnaryCallable(com.google.api.gax.rpc.UnaryCallable) Statement(com.google.api.generator.engine.ast.Statement) Service(com.google.api.generator.gapic.model.Service) OperationTimedPollAlgorithm(com.google.api.gax.longrunning.OperationTimedPollAlgorithm) PagedListDescriptor(com.google.api.gax.rpc.PagedListDescriptor) JavaStyle(com.google.api.generator.gapic.utils.JavaStyle) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) Message(com.google.api.generator.gapic.model.Message) Collections(java.util.Collections) ReferenceConstructorExpr(com.google.api.generator.engine.ast.ReferenceConstructorExpr) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) ReturnExpr(com.google.api.generator.engine.ast.ReturnExpr) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) Expr(com.google.api.generator.engine.ast.Expr) CastExpr(com.google.api.generator.engine.ast.CastExpr) AnonymousClassExpr(com.google.api.generator.engine.ast.AnonymousClassExpr) TernaryExpr(com.google.api.generator.engine.ast.TernaryExpr) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) MethodDefinition(com.google.api.generator.engine.ast.MethodDefinition) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) Collections(java.util.Collections) AnonymousClassExpr(com.google.api.generator.engine.ast.AnonymousClassExpr)

Example 5 with Method

use of com.google.api.generator.gapic.model.Method in project gapic-generator-java by googleapis.

the class AbstractTransportServiceStubClassComposer method createCallableClassMembers.

private Map<String, VariableExpr> createCallableClassMembers(Service service, TypeStore typeStore) {
    Map<String, VariableExpr> callableClassMembers = new LinkedHashMap<>();
    // Using a for-loop because the output cardinality is not a 1:1 mapping to the input set.
    for (Method protoMethod : service.methods()) {
        String javaStyleProtoMethodName = JavaStyle.toLowerCamelCase(protoMethod.name());
        String callableName = String.format(CALLABLE_CLASS_MEMBER_PATTERN, javaStyleProtoMethodName);
        callableClassMembers.put(callableName, VariableExpr.withVariable(Variable.builder().setName(callableName).setType(getCallableType(protoMethod)).build()));
        if (protoMethod.hasLro()) {
            callableName = String.format(OPERATION_CALLABLE_CLASS_MEMBER_PATTERN, javaStyleProtoMethodName);
            callableClassMembers.put(callableName, VariableExpr.withVariable(Variable.builder().setName(callableName).setType(TypeNode.withReference(ConcreteReference.builder().setClazz(OperationCallable.class).setGenerics(Arrays.asList(protoMethod.inputType().reference(), protoMethod.lro().responseType().reference(), protoMethod.lro().metadataType().reference())).build())).build()));
        }
        if (protoMethod.isPaged()) {
            callableName = String.format(PAGED_CALLABLE_CLASS_MEMBER_PATTERN, javaStyleProtoMethodName);
            callableClassMembers.put(callableName, VariableExpr.withVariable(Variable.builder().setName(callableName).setType(TypeNode.withReference(getCallableType(protoMethod).reference().copyAndSetGenerics(Arrays.asList(protoMethod.inputType().reference(), typeStore.get(String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, protoMethod.name())).reference())))).build()));
        }
    }
    return callableClassMembers;
}
Also used : OperationCallable(com.google.api.gax.rpc.OperationCallable) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Method(com.google.api.generator.gapic.model.Method) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Method (com.google.api.generator.gapic.model.Method)81 TypeNode (com.google.api.generator.engine.ast.TypeNode)75 Message (com.google.api.generator.gapic.model.Message)71 ResourceName (com.google.api.generator.gapic.model.ResourceName)60 Test (org.junit.Test)44 List (java.util.List)39 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)38 Expr (com.google.api.generator.engine.ast.Expr)37 ArrayList (java.util.ArrayList)36 Service (com.google.api.generator.gapic.model.Service)34 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)33 Arrays (java.util.Arrays)33 Field (com.google.api.generator.gapic.model.Field)32 Collectors (java.util.stream.Collectors)32 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)31 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)31 ValueExpr (com.google.api.generator.engine.ast.ValueExpr)31 Preconditions (com.google.common.base.Preconditions)31 ConcreteReference (com.google.api.generator.engine.ast.ConcreteReference)30 Variable (com.google.api.generator.engine.ast.Variable)30