Search in sources :

Example 21 with TypeNode

use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.

the class AbstractServiceSettingsClassComposer method createNestedBuilderCreatorMethods.

protected List<MethodDefinition> createNestedBuilderCreatorMethods(Service service, TypeStore typeStore, String newBuilderMethodName, String createDefaultMethodName) {
    MethodInvocationExpr ctorArg = MethodInvocationExpr.builder().setStaticReferenceType(typeStore.get(ClassNames.getServiceStubSettingsClassName(service))).setMethodName(newBuilderMethodName).build();
    TypeNode builderType = typeStore.get(BUILDER_CLASS_NAME);
    return ImmutableList.of(MethodDefinition.builder().setScope(ScopeNode.PRIVATE).setIsStatic(true).setReturnType(builderType).setName(createDefaultMethodName).setReturnExpr(NewObjectExpr.builder().setType(builderType).setArguments(ctorArg).build()).build());
}
Also used : MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode)

Example 22 with TypeNode

use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.

the class AbstractServiceSettingsClassComposer method createConstructorMethod.

private static MethodDefinition createConstructorMethod(Service service, TypeStore typeStore) {
    VariableExpr settingsBuilderVarExpr = VariableExpr.withVariable(Variable.builder().setName("settingsBuilder").setType(typeStore.get(BUILDER_CLASS_NAME)).build());
    TypeNode thisClassType = typeStore.get(ClassNames.getServiceSettingsClassName(service));
    return MethodDefinition.constructorBuilder().setScope(ScopeNode.PROTECTED).setReturnType(thisClassType).setArguments(Arrays.asList(settingsBuilderVarExpr.toBuilder().setIsDecl(true).build())).setThrowsExceptions(Arrays.asList(FIXED_TYPESTORE.get("IOException"))).setBody(Arrays.asList(ExprStatement.withExpr(ReferenceConstructorExpr.superBuilder().setType(FIXED_TYPESTORE.get("ClientSettings")).setArguments(settingsBuilderVarExpr).build()))).build();
}
Also used : VariableExpr(com.google.api.generator.engine.ast.VariableExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode)

Example 23 with TypeNode

use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.

the class AbstractServiceSettingsClassComposer method createCreatorMethod.

private static MethodDefinition createCreatorMethod(Service service, TypeStore typeStore) {
    TypeNode stubClassType = typeStore.get(ClassNames.getServiceStubSettingsClassName(service));
    VariableExpr stubVarExpr = VariableExpr.withVariable(Variable.builder().setName("stub").setType(stubClassType).build());
    TypeNode thisClassType = typeStore.get(ClassNames.getServiceSettingsClassName(service));
    MethodInvocationExpr stubBuilderMethodExpr = MethodInvocationExpr.builder().setExprReferenceExpr(stubVarExpr).setMethodName("toBuilder").build();
    TypeNode stubBuilderType = TypeNode.withReference(VaporReference.builder().setName("Builder").setEnclosingClassNames(ClassNames.getServiceSettingsClassName(service)).setPakkage(service.pakkage()).build());
    Expr returnMethodExpr = NewObjectExpr.builder().setType(stubBuilderType).setArguments(stubBuilderMethodExpr).build();
    returnMethodExpr = MethodInvocationExpr.builder().setExprReferenceExpr(returnMethodExpr).setMethodName("build").setReturnType(thisClassType).build();
    return MethodDefinition.builder().setScope(ScopeNode.PUBLIC).setIsStatic(true).setIsFinal(true).setReturnType(thisClassType).setName("create").setArguments(Arrays.asList(stubVarExpr.toBuilder().setIsDecl(true).build())).setThrowsExceptions(Arrays.asList(FIXED_TYPESTORE.get("IOException"))).setReturnExpr(returnMethodExpr).build();
}
Also used : ReferenceConstructorExpr(com.google.api.generator.engine.ast.ReferenceConstructorExpr) ValueExpr(com.google.api.generator.engine.ast.ValueExpr) NewObjectExpr(com.google.api.generator.engine.ast.NewObjectExpr) Expr(com.google.api.generator.engine.ast.Expr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) CastExpr(com.google.api.generator.engine.ast.CastExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) MethodInvocationExpr(com.google.api.generator.engine.ast.MethodInvocationExpr) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode)

Example 24 with TypeNode

use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.

the class AbstractServiceStubClassComposer method createCallableGetterHelper.

private MethodDefinition createCallableGetterHelper(Method method, TypeStore typeStore, boolean isLroCallable, boolean isPaged) {
    TypeNode returnType;
    switch(method.stream()) {
        case CLIENT:
            returnType = typeStore.get("ClientStreamingCallable");
            break;
        case SERVER:
            returnType = typeStore.get("ServerStreamingCallable");
            break;
        case BIDI:
            returnType = typeStore.get("BidiStreamingCallable");
            break;
        case NONE:
        // Fall through.
        default:
            returnType = typeStore.get(isLroCallable ? "OperationCallable" : "UnaryCallable");
    }
    String methodName = String.format("%s%sCallable", JavaStyle.toLowerCamelCase(method.name()), (isLroCallable ? "Operation" : isPaged ? "Paged" : ""));
    List<Reference> genericRefs = new ArrayList<>();
    genericRefs.add(method.inputType().reference());
    if (method.hasLro() && isLroCallable) {
        genericRefs.add(method.lro().responseType().reference());
        genericRefs.add(method.lro().metadataType().reference());
    } else if (isPaged) {
        genericRefs.add(typeStore.get(String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, method.name())).reference());
    } else {
        genericRefs.add(method.outputType().reference());
    }
    List<AnnotationNode> annotations = method.isDeprecated() ? Arrays.asList(AnnotationNode.withType(TypeNode.DEPRECATED)) : Collections.emptyList();
    returnType = TypeNode.withReference(returnType.reference().copyAndSetGenerics(genericRefs));
    return createCallableGetterMethodDefinition(returnType, methodName, annotations, typeStore);
}
Also used : AnnotationNode(com.google.api.generator.engine.ast.AnnotationNode) Reference(com.google.api.generator.engine.ast.Reference) ConcreteReference(com.google.api.generator.engine.ast.ConcreteReference) ArrayList(java.util.ArrayList) TypeNode(com.google.api.generator.engine.ast.TypeNode)

Example 25 with TypeNode

use of com.google.api.generator.engine.ast.TypeNode in project gapic-generator-java by googleapis.

the class AbstractServiceStubClassComposer method createClassMethods.

private List<MethodDefinition> createClassMethods(Service service, Map<String, Message> messageTypes, TypeStore typeStore) {
    List<MethodDefinition> methods = new ArrayList<>();
    if (service.hasStandardLroMethods()) {
        TypeNode operationsStubType = service.operationServiceStubType();
        methods.addAll(createOperationsStubGetters(typeStore, operationsStubType));
    }
    if (service.operationPollingMethod() != null) {
        methods.addAll(createLongRunningClientGetters(typeStore));
    }
    methods.addAll(createCallableGetters(service, messageTypes, typeStore));
    methods.addAll(createBackgroundResourceMethodOverrides());
    return methods;
}
Also used : MethodDefinition(com.google.api.generator.engine.ast.MethodDefinition) ArrayList(java.util.ArrayList) TypeNode(com.google.api.generator.engine.ast.TypeNode)

Aggregations

TypeNode (com.google.api.generator.engine.ast.TypeNode)232 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)119 MethodInvocationExpr (com.google.api.generator.engine.ast.MethodInvocationExpr)111 Test (org.junit.Test)103 AssignmentExpr (com.google.api.generator.engine.ast.AssignmentExpr)84 Message (com.google.api.generator.gapic.model.Message)81 ArrayList (java.util.ArrayList)81 Expr (com.google.api.generator.engine.ast.Expr)77 ValueExpr (com.google.api.generator.engine.ast.ValueExpr)77 Method (com.google.api.generator.gapic.model.Method)72 NewObjectExpr (com.google.api.generator.engine.ast.NewObjectExpr)68 ResourceName (com.google.api.generator.gapic.model.ResourceName)65 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)64 List (java.util.List)63 ConcreteReference (com.google.api.generator.engine.ast.ConcreteReference)61 MethodDefinition (com.google.api.generator.engine.ast.MethodDefinition)59 Variable (com.google.api.generator.engine.ast.Variable)55 Statement (com.google.api.generator.engine.ast.Statement)53 Collectors (java.util.stream.Collectors)46 RelationalOperationExpr (com.google.api.generator.engine.ast.RelationalOperationExpr)45