Search in sources :

Example 6 with BetaApi

use of com.google.api.core.BetaApi in project gapic-generator-java by googleapis.

the class AbstractServiceStubSettingsClassComposer method createNestedClassSettingsBuilderGetterMethods.

private static List<MethodDefinition> createNestedClassSettingsBuilderGetterMethods(Map<String, VariableExpr> nestedMethodSettingsMemberVarExprs, Set<String> nestedDeprecatedSettingVarNames) {
    Reference operationCallSettingsBuilderRef = ConcreteReference.withClazz(OperationCallSettings.Builder.class);
    Function<TypeNode, Boolean> isOperationCallSettingsBuilderFn = t -> t.reference().copyAndSetGenerics(ImmutableList.of()).equals(operationCallSettingsBuilderRef);
    AnnotationNode lroBetaAnnotation = AnnotationNode.builder().setType(FIXED_TYPESTORE.get("BetaApi")).setDescription("The surface for use by generated code is not stable yet and may change in the" + " future.").build();
    AnnotationNode deprecatedAnnotation = AnnotationNode.withType(TypeNode.DEPRECATED);
    List<MethodDefinition> javaMethods = new ArrayList<>();
    for (Map.Entry<String, VariableExpr> settingsVarEntry : nestedMethodSettingsMemberVarExprs.entrySet()) {
        String varName = settingsVarEntry.getKey();
        VariableExpr settingsVarExpr = settingsVarEntry.getValue();
        boolean isOperationCallSettings = isOperationCallSettingsBuilderFn.apply(settingsVarExpr.type());
        List<AnnotationNode> annotations = new ArrayList<>();
        if (isOperationCallSettings) {
            annotations.add(lroBetaAnnotation);
        }
        boolean isDeprecated = nestedDeprecatedSettingVarNames.contains(varName);
        if (isDeprecated) {
            annotations.add(deprecatedAnnotation);
        }
        javaMethods.add(MethodDefinition.builder().setHeaderCommentStatements(SettingsCommentComposer.createCallSettingsBuilderGetterComment(getMethodNameFromSettingsVarName(varName), isDeprecated)).setAnnotations(annotations).setScope(ScopeNode.PUBLIC).setReturnType(settingsVarExpr.type()).setName(settingsVarExpr.variable().identifier().name()).setReturnExpr(settingsVarExpr).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) ConcreteReference(com.google.api.generator.engine.ast.ConcreteReference) VaporReference(com.google.api.generator.engine.ast.VaporReference) Reference(com.google.api.generator.engine.ast.Reference) ArrayList(java.util.ArrayList) OperationCallSettings(com.google.api.gax.rpc.OperationCallSettings) AnnotationNode(com.google.api.generator.engine.ast.AnnotationNode) MethodDefinition(com.google.api.generator.engine.ast.MethodDefinition) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 7 with BetaApi

use of com.google.api.core.BetaApi in project gapic-generator-java by googleapis.

the class ResourceNameHelperClassComposer method createOfOrFormatMethodHelper.

private static List<MethodDefinition> createOfOrFormatMethodHelper(ResourceName resourceName, Map<String, VariableExpr> patternTokenVarExprs, List<List<String>> tokenHierarchies, TypeStore typeStore, boolean isFormatMethod) {
    List<MethodDefinition> javaMethods = new ArrayList<>();
    String methodNameFormat = isFormatMethod ? "format%s" : "of%s";
    String newBuilderMethodNameFormat = "new%s";
    String setMethodNameFormat = "set%s";
    String buildMethodName = "build";
    String toStringMethodName = "toString";
    AnnotationNode betaAnnotation = AnnotationNode.builder().setType(FIXED_TYPESTORE.get("BetaApi")).setDescription(String.format("The static %s methods are not stable yet and may be changed in the future.", isFormatMethod ? "format" : "create")).build();
    List<AnnotationNode> annotations = Arrays.asList(betaAnnotation);
    TypeNode thisClassType = typeStore.get(getThisClassName(resourceName));
    TypeNode returnType = isFormatMethod ? TypeNode.STRING : thisClassType;
    // Create the newBuilder and variation methods here.
    // Variation example: newProjectLocationAutoscalingPolicyBuilder().
    boolean hasVariants = tokenHierarchies.size() > 1;
    for (int i = 0; i < tokenHierarchies.size(); i++) {
        List<String> tokens = tokenHierarchies.get(i);
        // PubSub special-case handling.
        if (tokens.contains(ResourceNameConstants.DELETED_TOPIC_LITERAL)) {
            Expr deletedTopicStringValExpr = ValueExpr.withValue(StringObjectValue.withValue(ResourceNameConstants.DELETED_TOPIC_LITERAL));
            // Simply return `new TopicName("_deleted-topic_")` or the string value itself.
            javaMethods.add(MethodDefinition.builder().setScope(ScopeNode.PUBLIC).setIsStatic(true).setAnnotations(annotations).setReturnType(returnType).setName(String.format(methodNameFormat, concatToUpperCamelCaseName(tokens) + "Name")).setReturnExpr(returnType.equals(TypeNode.STRING) ? deletedTopicStringValExpr : NewObjectExpr.builder().setType(returnType).setArguments(deletedTopicStringValExpr).build()).build());
            continue;
        }
        String builderMethodName = String.format(newBuilderMethodNameFormat, getBuilderTypeName(tokenHierarchies, i));
        MethodInvocationExpr returnExpr = MethodInvocationExpr.builder().setMethodName(builderMethodName).build();
        for (String token : tokens) {
            String javaTokenVarName = JavaStyle.toLowerCamelCase(token);
            returnExpr = MethodInvocationExpr.builder().setExprReferenceExpr(returnExpr).setMethodName(String.format(setMethodNameFormat, JavaStyle.toUpperCamelCase(token))).setArguments(Arrays.asList(VariableExpr.withVariable(Variable.builder().setName(javaTokenVarName).setType(TypeNode.STRING).build()))).build();
        }
        returnExpr = MethodInvocationExpr.builder().setExprReferenceExpr(returnExpr).setMethodName(buildMethodName).setReturnType(thisClassType).build();
        if (isFormatMethod) {
            returnExpr = MethodInvocationExpr.builder().setExprReferenceExpr(returnExpr).setMethodName(toStringMethodName).setReturnType(TypeNode.STRING).build();
        }
        List<VariableExpr> methodArgs = tokens.stream().map(t -> patternTokenVarExprs.get(t).toBuilder().setIsDecl(true).build()).collect(Collectors.toList());
        javaMethods.add(MethodDefinition.builder().setScope(ScopeNode.PUBLIC).setIsStatic(true).setAnnotations(i == 0 ? Collections.emptyList() : annotations).setReturnType(returnType).setName(String.format(methodNameFormat, i == 0 ? "" : concatToUpperCamelCaseName(tokens) + "Name")).setArguments(methodArgs).setReturnExpr(returnExpr).build());
        if (i == 0 && hasVariants) {
            javaMethods.add(MethodDefinition.builder().setScope(ScopeNode.PUBLIC).setIsStatic(true).setAnnotations(annotations).setReturnType(returnType).setName(String.format(methodNameFormat, concatToUpperCamelCaseName(tokenHierarchies.get(i)) + "Name")).setArguments(methodArgs).setReturnExpr(returnExpr).build());
        }
    }
    return javaMethods;
}
Also used : Arrays(java.util.Arrays) Reference(com.google.api.generator.engine.ast.Reference) PathTemplate(com.google.api.pathtemplate.PathTemplate) ThisObjectValue(com.google.api.generator.engine.ast.ThisObjectValue) Variable(com.google.api.generator.engine.ast.Variable) StringObjectValue(com.google.api.generator.engine.ast.StringObjectValue) LogicalOperationExpr(com.google.api.generator.engine.ast.LogicalOperationExpr) Generated(javax.annotation.Generated) MethodDefinition(com.google.api.generator.engine.ast.MethodDefinition) TypeStore(com.google.api.generator.gapic.composer.store.TypeStore) PrimitiveValue(com.google.api.generator.engine.ast.PrimitiveValue) CommentComposer(com.google.api.generator.gapic.composer.comment.CommentComposer) Map(java.util.Map) ConcreteReference(com.google.api.generator.engine.ast.ConcreteReference) ImmutableMap(com.google.common.collect.ImmutableMap) ForStatement(com.google.api.generator.engine.ast.ForStatement) Set(java.util.Set) ScopeNode(com.google.api.generator.engine.ast.ScopeNode) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ResourceNameConstants(com.google.api.generator.gapic.utils.ResourceNameConstants) List(java.util.List) GapicContext(com.google.api.generator.gapic.model.GapicContext) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) IfStatement(com.google.api.generator.engine.ast.IfStatement) BetaApi(com.google.api.core.BetaApi) TypeNode(com.google.api.generator.engine.ast.TypeNode) ClassDefinition(com.google.api.generator.engine.ast.ClassDefinition) ReturnExpr(com.google.api.generator.engine.ast.ReturnExpr) HashMap(java.util.HashMap) JavaDocComment(com.google.api.generator.engine.ast.JavaDocComment) Function(java.util.function.Function) ArrayList(java.util.ArrayList) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) Expr(com.google.api.generator.engine.ast.Expr) TernaryExpr(com.google.api.generator.engine.ast.TernaryExpr) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) SynchronizedStatement(com.google.api.generator.engine.ast.SynchronizedStatement) ValidationException(com.google.api.pathtemplate.ValidationException) LinkedHashSet(java.util.LinkedHashSet) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Iterator(java.util.Iterator) CastExpr(com.google.api.generator.engine.ast.CastExpr) CommentStatement(com.google.api.generator.engine.ast.CommentStatement) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) AnnotationNode(com.google.api.generator.engine.ast.AnnotationNode) GapicClass(com.google.api.generator.gapic.model.GapicClass) ResourceName(com.google.api.generator.gapic.model.ResourceName) Statement(com.google.api.generator.engine.ast.Statement) JavaStyle(com.google.api.generator.gapic.utils.JavaStyle) AssignmentOperationExpr(com.google.api.generator.engine.ast.AssignmentOperationExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) ArrayList(java.util.ArrayList) LogicalOperationExpr(com.google.api.generator.engine.ast.LogicalOperationExpr) 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) 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) CastExpr(com.google.api.generator.engine.ast.CastExpr) AssignmentOperationExpr(com.google.api.generator.engine.ast.AssignmentOperationExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) AnnotationNode(com.google.api.generator.engine.ast.AnnotationNode) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) MethodDefinition(com.google.api.generator.engine.ast.MethodDefinition) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode)

Example 8 with BetaApi

use of com.google.api.core.BetaApi in project gapic-generator-java by googleapis.

the class ResourceNameHelperClassComposer method createNestedBuilderClass.

private static ClassDefinition createNestedBuilderClass(TypeNode outerClassType, List<String> tokens, VariableExpr templateFinalVarExpr, String resourceNamePattern, TypeStore typeStore, boolean hasVariants, boolean isDefaultClass) {
    String className = isDefaultClass ? "Builder" : getBuilderTypeName(tokens);
    // Class member declarations.
    List<VariableExpr> classMemberVarExprs = tokens.stream().map(t -> VariableExpr.withVariable(Variable.builder().setName(JavaStyle.toLowerCamelCase(t)).setType(TypeNode.STRING).build())).collect(Collectors.toList());
    List<Statement> classMemberDecls = classMemberVarExprs.stream().map(v -> ExprStatement.withExpr(v.toBuilder().setIsDecl(true).setScope(ScopeNode.PRIVATE).build())).collect(Collectors.toList());
    // Constructor.
    List<MethodDefinition> nestedClassMethods = new ArrayList<>();
    TypeNode thisClassType = typeStore.get(className);
    MethodDefinition ctor = MethodDefinition.constructorBuilder().setScope(ScopeNode.PROTECTED).setReturnType(thisClassType).build();
    nestedClassMethods.add(ctor);
    // Getters and setters.
    List<MethodDefinition> getterMethods = new ArrayList<>();
    List<MethodDefinition> setterMethods = new ArrayList<>();
    ValueExpr thisExpr = ValueExpr.withValue(ThisObjectValue.withType(thisClassType));
    for (int i = 0; i < tokens.size(); i++) {
        String token = tokens.get(i);
        String upperCamelTokenName = JavaStyle.toUpperCamelCase(token);
        VariableExpr currClassTokenVarExpr = classMemberVarExprs.get(i);
        // Getter.
        MethodDefinition getterMethod = MethodDefinition.builder().setScope(ScopeNode.PUBLIC).setReturnType(TypeNode.STRING).setName(String.format("get%s", upperCamelTokenName)).setReturnExpr(currClassTokenVarExpr).build();
        getterMethods.add(getterMethod);
        // Setter.
        VariableExpr tokenArgVarExpr = currClassTokenVarExpr;
        AssignmentExpr fieldAssignExpr = AssignmentExpr.builder().setVariableExpr(currClassTokenVarExpr.toBuilder().setExprReferenceExpr(thisExpr).build()).setValueExpr(tokenArgVarExpr).build();
        MethodDefinition setterMethod = MethodDefinition.builder().setScope(ScopeNode.PUBLIC).setReturnType(thisClassType).setName(String.format("set%s", upperCamelTokenName)).setArguments(classMemberVarExprs.get(i).toBuilder().setIsDecl(true).build()).setBody(Arrays.asList(ExprStatement.withExpr(fieldAssignExpr))).setReturnExpr(thisExpr).build();
        setterMethods.add(setterMethod);
    }
    nestedClassMethods.addAll(getterMethods);
    nestedClassMethods.addAll(setterMethods);
    // Private builder constructor method.
    if (isDefaultClass) {
        VariableExpr outerClassVarExpr = VariableExpr.withVariable(Variable.builder().setName(JavaStyle.toLowerCamelCase(outerClassType.reference().name())).setType(outerClassType).build());
        List<Expr> builderCtorBodyExprs = new ArrayList<>();
        if (hasVariants) {
            // TODO(miraleung): Use eq operator instead.
            MethodInvocationExpr equalsCheckExpr = MethodInvocationExpr.builder().setStaticReferenceType(FIXED_TYPESTORE.get("Objects")).setMethodName("equals").setArguments(FIXED_CLASS_VARS.get("pathTemplate").toBuilder().setExprReferenceExpr(outerClassVarExpr).build(), templateFinalVarExpr).build();
            builderCtorBodyExprs.add(MethodInvocationExpr.builder().setStaticReferenceType(FIXED_TYPESTORE.get("Preconditions")).setMethodName("checkArgument").setArguments(equalsCheckExpr, ValueExpr.withValue(StringObjectValue.withValue(String.format("toBuilder is only supported when %s has the pattern of %s", outerClassType.reference().name(), resourceNamePattern)))).build());
        }
        for (VariableExpr memberVarExpr : classMemberVarExprs) {
            VariableExpr currClassTokenVarExpr = memberVarExpr.toBuilder().setExprReferenceExpr(thisExpr).build();
            builderCtorBodyExprs.add(AssignmentExpr.builder().setVariableExpr(currClassTokenVarExpr).setValueExpr(currClassTokenVarExpr.toBuilder().setExprReferenceExpr(outerClassVarExpr).build()).build());
        }
        MethodDefinition fromOuterTypeCtor = MethodDefinition.constructorBuilder().setScope(ScopeNode.PRIVATE).setReturnType(thisClassType).setArguments(outerClassVarExpr.toBuilder().setIsDecl(true).build()).setBody(builderCtorBodyExprs.stream().map(e -> ExprStatement.withExpr(e)).collect(Collectors.toList())).build();
        nestedClassMethods.add(fromOuterTypeCtor);
    }
    // Last build() method.
    MethodDefinition buildMethod = MethodDefinition.builder().setScope(ScopeNode.PUBLIC).setReturnType(outerClassType).setName("build").setReturnExpr(NewObjectExpr.builder().setType(outerClassType).setArguments(thisExpr).build()).build();
    nestedClassMethods.add(buildMethod);
    // Return the class.
    AnnotationNode betaAnnotation = AnnotationNode.builder().setType(FIXED_TYPESTORE.get("BetaApi")).setDescription("The per-pattern Builders are not stable yet and may be changed in the future.").build();
    List<AnnotationNode> classAnnotations = isDefaultClass ? Collections.emptyList() : Arrays.asList(betaAnnotation);
    return ClassDefinition.builder().setHeaderCommentStatements(CommentStatement.withComment(JavaDocComment.withComment(String.format(BUILDER_CLASS_HEADER_PATTERN, resourceNamePattern)))).setAnnotations(classAnnotations).setIsNested(true).setScope(ScopeNode.PUBLIC).setIsStatic(true).setName(className).setStatements(classMemberDecls).setMethods(nestedClassMethods).build();
}
Also used : Arrays(java.util.Arrays) Reference(com.google.api.generator.engine.ast.Reference) PathTemplate(com.google.api.pathtemplate.PathTemplate) ThisObjectValue(com.google.api.generator.engine.ast.ThisObjectValue) Variable(com.google.api.generator.engine.ast.Variable) StringObjectValue(com.google.api.generator.engine.ast.StringObjectValue) LogicalOperationExpr(com.google.api.generator.engine.ast.LogicalOperationExpr) Generated(javax.annotation.Generated) MethodDefinition(com.google.api.generator.engine.ast.MethodDefinition) TypeStore(com.google.api.generator.gapic.composer.store.TypeStore) PrimitiveValue(com.google.api.generator.engine.ast.PrimitiveValue) CommentComposer(com.google.api.generator.gapic.composer.comment.CommentComposer) Map(java.util.Map) ConcreteReference(com.google.api.generator.engine.ast.ConcreteReference) ImmutableMap(com.google.common.collect.ImmutableMap) ForStatement(com.google.api.generator.engine.ast.ForStatement) Set(java.util.Set) ScopeNode(com.google.api.generator.engine.ast.ScopeNode) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ResourceNameConstants(com.google.api.generator.gapic.utils.ResourceNameConstants) List(java.util.List) GapicContext(com.google.api.generator.gapic.model.GapicContext) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) IfStatement(com.google.api.generator.engine.ast.IfStatement) BetaApi(com.google.api.core.BetaApi) TypeNode(com.google.api.generator.engine.ast.TypeNode) ClassDefinition(com.google.api.generator.engine.ast.ClassDefinition) ReturnExpr(com.google.api.generator.engine.ast.ReturnExpr) HashMap(java.util.HashMap) JavaDocComment(com.google.api.generator.engine.ast.JavaDocComment) Function(java.util.function.Function) ArrayList(java.util.ArrayList) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) Expr(com.google.api.generator.engine.ast.Expr) TernaryExpr(com.google.api.generator.engine.ast.TernaryExpr) RelationalOperationExpr(com.google.api.generator.engine.ast.RelationalOperationExpr) SynchronizedStatement(com.google.api.generator.engine.ast.SynchronizedStatement) ValidationException(com.google.api.pathtemplate.ValidationException) LinkedHashSet(java.util.LinkedHashSet) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) Iterator(java.util.Iterator) CastExpr(com.google.api.generator.engine.ast.CastExpr) CommentStatement(com.google.api.generator.engine.ast.CommentStatement) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) AnnotationNode(com.google.api.generator.engine.ast.AnnotationNode) GapicClass(com.google.api.generator.gapic.model.GapicClass) ResourceName(com.google.api.generator.gapic.model.ResourceName) Statement(com.google.api.generator.engine.ast.Statement) JavaStyle(com.google.api.generator.gapic.utils.JavaStyle) AssignmentOperationExpr(com.google.api.generator.engine.ast.AssignmentOperationExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) ForStatement(com.google.api.generator.engine.ast.ForStatement) IfStatement(com.google.api.generator.engine.ast.IfStatement) SynchronizedStatement(com.google.api.generator.engine.ast.SynchronizedStatement) 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) AssignmentExpr(com.google.api.generator.engine.ast.AssignmentExpr) LogicalOperationExpr(com.google.api.generator.engine.ast.LogicalOperationExpr) 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) 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) CastExpr(com.google.api.generator.engine.ast.CastExpr) AssignmentOperationExpr(com.google.api.generator.engine.ast.AssignmentOperationExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) ThrowExpr(com.google.api.generator.engine.ast.ThrowExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) AnnotationNode(com.google.api.generator.engine.ast.AnnotationNode) MethodDefinition(com.google.api.generator.engine.ast.MethodDefinition) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode)

Example 9 with BetaApi

use of com.google.api.core.BetaApi in project gax-java by googleapis.

the class GrpcClientCalls method eagerFutureUnaryCall.

/**
 * A work-alike of {@link io.grpc.stub.ClientCalls#futureUnaryCall(ClientCall, Object)}.
 *
 * <p>The only difference is that unlike grpc-stub's implementation. This implementation doesn't
 * wait for trailers to resolve a unary RPC. This can save milliseconds when the server is
 * overloaded.
 */
@BetaApi
static <RequestT, ResponseT> ApiFuture<ResponseT> eagerFutureUnaryCall(ClientCall<RequestT, ResponseT> clientCall, RequestT request) {
    // Start the call
    GrpcFuture<ResponseT> future = new GrpcFuture<>(clientCall);
    clientCall.start(new EagerFutureListener<>(future), new Metadata());
    // Send the request
    try {
        clientCall.sendMessage(request);
        clientCall.halfClose();
        // Request an extra message to detect misconfigured servers
        clientCall.request(2);
    } catch (Throwable sendError) {
        // Cancel if anything goes wrong
        try {
            clientCall.cancel(null, sendError);
        } catch (Throwable cancelError) {
            LOGGER.log(Level.SEVERE, "Error encountered while closing it", sendError);
        }
        throw sendError;
    }
    return future;
}
Also used : Metadata(io.grpc.Metadata) BetaApi(com.google.api.core.BetaApi)

Example 10 with BetaApi

use of com.google.api.core.BetaApi in project java-bigquery by googleapis.

the class ConnectionImpl method executeSelect.

/**
 * This method executes a SQL SELECT query
 *
 * @param sql SQL SELECT statement
 * @return BigQueryResult containing the output of the query
 * @throws BigQuerySQLException
 */
@BetaApi
@Override
public BigQueryResult executeSelect(String sql) throws BigQuerySQLException {
    try {
        // use jobs.query if all the properties of connectionSettings are supported
        if (isFastQuerySupported()) {
            String projectId = bigQueryOptions.getProjectId();
            QueryRequest queryRequest = createQueryRequest(connectionSettings, sql, null, null);
            return queryRpc(projectId, queryRequest, false);
        }
        // use jobs.insert otherwise
        com.google.api.services.bigquery.model.Job queryJob = createQueryJob(sql, connectionSettings, null, null);
        JobId jobId = JobId.fromPb(queryJob.getJobReference());
        GetQueryResultsResponse firstPage = getQueryResultsFirstPage(jobId);
        return getResultSet(firstPage, jobId, sql, false);
    } catch (BigQueryException e) {
        throw new BigQuerySQLException(e.getMessage(), e, e.getErrors());
    }
}
Also used : QueryRequest(com.google.api.services.bigquery.model.QueryRequest) GetQueryResultsResponse(com.google.api.services.bigquery.model.GetQueryResultsResponse) BetaApi(com.google.api.core.BetaApi)

Aggregations

BetaApi (com.google.api.core.BetaApi)11 AnnotationNode (com.google.api.generator.engine.ast.AnnotationNode)5 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)5 CastExpr (com.google.api.generator.engine.ast.CastExpr)5 ClassDefinition (com.google.api.generator.engine.ast.ClassDefinition)5 CommentStatement (com.google.api.generator.engine.ast.CommentStatement)5 ConcreteReference (com.google.api.generator.engine.ast.ConcreteReference)5 Expr (com.google.api.generator.engine.ast.Expr)5 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)5 MethodDefinition (com.google.api.generator.engine.ast.MethodDefinition)5 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)5 NewObjectExpr (com.google.api.generator.engine.ast.NewObjectExpr)5 PrimitiveValue (com.google.api.generator.engine.ast.PrimitiveValue)5 Reference (com.google.api.generator.engine.ast.Reference)5 RelationalOperationExpr (com.google.api.generator.engine.ast.RelationalOperationExpr)5 ScopeNode (com.google.api.generator.engine.ast.ScopeNode)5 Statement (com.google.api.generator.engine.ast.Statement)5 TernaryExpr (com.google.api.generator.engine.ast.TernaryExpr)5 ThisObjectValue (com.google.api.generator.engine.ast.ThisObjectValue)5 TypeNode (com.google.api.generator.engine.ast.TypeNode)5