Search in sources :

Example 1 with StubCommentComposer

use of com.google.api.generator.gapic.composer.comment.StubCommentComposer in project gapic-generator-java by googleapis.

the class AbstractTransportServiceStubClassComposer method generate.

@Override
public GapicClass generate(GapicContext context, Service service) {
    String pakkage = service.pakkage() + ".stub";
    TypeStore typeStore = createDynamicTypes(service, pakkage);
    String className = getTransportContext().classNames().getTransportServiceStubClassName(service);
    GapicClass.Kind kind = Kind.STUB;
    Map<String, VariableExpr> protoMethodNameToDescriptorVarExprs = createProtoMethodNameToDescriptorClassMembers(service, getTransportContext().methodDescriptorClass());
    Map<String, VariableExpr> callableClassMemberVarExprs = createCallableClassMembers(service, typeStore);
    Map<String, VariableExpr> classMemberVarExprs = new LinkedHashMap<>();
    classMemberVarExprs.put(BACKGROUND_RESOURCES_MEMBER_NAME, VariableExpr.withVariable(Variable.builder().setName(BACKGROUND_RESOURCES_MEMBER_NAME).setType(FIXED_TYPESTORE.get("BackgroundResource")).build()));
    if (generateOperationsStubLogic(service)) {
        // Transport-specific service stub may have only one element of the following, thus get(0).
        TypeNode operationsStubType = getTransportOperationsStubType(service);
        classMemberVarExprs.put(getTransportContext().transportOperationsStubNames().get(0), VariableExpr.withVariable(Variable.builder().setName(getTransportContext().transportOperationsStubNames().get(0)).setType(operationsStubType).build()));
    }
    boolean operationPollingMethod = checkOperationPollingMethod(service);
    if (operationPollingMethod) {
        VariableExpr longRunningVarExpr = declareLongRunningClient();
        if (longRunningVarExpr != null) {
            classMemberVarExprs.put("longRunningClient", longRunningVarExpr);
        }
    }
    classMemberVarExprs.put(CALLABLE_FACTORY_MEMBER_NAME, VariableExpr.withVariable(Variable.builder().setName(CALLABLE_FACTORY_MEMBER_NAME).setType(getTransportContext().stubCallableFactoryType()).build()));
    Map<String, Message> messageTypes = context.messages();
    List<Statement> classStatements = createClassStatements(service, protoMethodNameToDescriptorVarExprs, callableClassMemberVarExprs, classMemberVarExprs, messageTypes);
    StubCommentComposer commentComposer = new StubCommentComposer(getTransportContext().transportName());
    ClassDefinition classDef = ClassDefinition.builder().setPackageString(pakkage).setHeaderCommentStatements(commentComposer.createTransportServiceStubClassHeaderComments(service.name(), service.isDeprecated())).setAnnotations(createClassAnnotations(service)).setScope(ScopeNode.PUBLIC).setName(className).setExtendsType(typeStore.get(getTransportContext().classNames().getServiceStubClassName(service))).setMethods(createClassMethods(context, service, typeStore, classMemberVarExprs, callableClassMemberVarExprs, protoMethodNameToDescriptorVarExprs, classStatements)).setStatements(classStatements).build();
    return GapicClass.create(kind, classDef);
}
Also used : Message(com.google.api.generator.gapic.model.Message) EmptyLineStatement(com.google.api.generator.engine.ast.EmptyLineStatement) TryCatchStatement(com.google.api.generator.engine.ast.TryCatchStatement) CommentStatement(com.google.api.generator.engine.ast.CommentStatement) ExprStatement(com.google.api.generator.engine.ast.ExprStatement) Statement(com.google.api.generator.engine.ast.Statement) ClassDefinition(com.google.api.generator.engine.ast.ClassDefinition) LinkedHashMap(java.util.LinkedHashMap) StubCommentComposer(com.google.api.generator.gapic.composer.comment.StubCommentComposer) GapicClass(com.google.api.generator.gapic.model.GapicClass) TypeStore(com.google.api.generator.gapic.composer.store.TypeStore) Kind(com.google.api.generator.gapic.model.GapicClass.Kind) VariableExpr(com.google.api.generator.engine.ast.VariableExpr) TypeNode(com.google.api.generator.engine.ast.TypeNode)

Example 2 with StubCommentComposer

use of com.google.api.generator.gapic.composer.comment.StubCommentComposer in project gapic-generator-java by googleapis.

the class AbstractServiceCallableFactoryClassComposer method generate.

@Override
public GapicClass generate(GapicContext context, Service service) {
    TypeStore typeStore = createTypes(service);
    String className = getTransportContext().classNames().getTransportServiceCallableFactoryClassName(service);
    GapicClass.Kind kind = Kind.STUB;
    String pakkage = String.format("%s.stub", service.pakkage());
    StubCommentComposer commentComposer = new StubCommentComposer(getTransportContext().transportName());
    ClassDefinition classDef = ClassDefinition.builder().setPackageString(pakkage).setHeaderCommentStatements(commentComposer.createTransportServiceCallableFactoryClassHeaderComments(service.name(), service.isDeprecated())).setAnnotations(createClassAnnotations(service, typeStore)).setImplementsTypes(createClassImplements(service, typeStore)).setName(className).setMethods(createClassMethods(service, typeStore)).setScope(ScopeNode.PUBLIC).build();
    return GapicClass.create(kind, classDef);
}
Also used : StubCommentComposer(com.google.api.generator.gapic.composer.comment.StubCommentComposer) GapicClass(com.google.api.generator.gapic.model.GapicClass) TypeStore(com.google.api.generator.gapic.composer.store.TypeStore) Kind(com.google.api.generator.gapic.model.GapicClass.Kind) ClassDefinition(com.google.api.generator.engine.ast.ClassDefinition)

Aggregations

ClassDefinition (com.google.api.generator.engine.ast.ClassDefinition)2 StubCommentComposer (com.google.api.generator.gapic.composer.comment.StubCommentComposer)2 TypeStore (com.google.api.generator.gapic.composer.store.TypeStore)2 GapicClass (com.google.api.generator.gapic.model.GapicClass)2 Kind (com.google.api.generator.gapic.model.GapicClass.Kind)2 CommentStatement (com.google.api.generator.engine.ast.CommentStatement)1 EmptyLineStatement (com.google.api.generator.engine.ast.EmptyLineStatement)1 ExprStatement (com.google.api.generator.engine.ast.ExprStatement)1 Statement (com.google.api.generator.engine.ast.Statement)1 TryCatchStatement (com.google.api.generator.engine.ast.TryCatchStatement)1 TypeNode (com.google.api.generator.engine.ast.TypeNode)1 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)1 Message (com.google.api.generator.gapic.model.Message)1 LinkedHashMap (java.util.LinkedHashMap)1