Search in sources :

Example 1 with Kind

use of com.google.api.generator.gapic.model.GapicClass.Kind 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 Kind

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

the class AbstractServiceClientClassComposer method generate.

@Override
public GapicClass generate(GapicContext context, Service service) {
    Map<String, ResourceName> resourceNames = context.helperResourceNames();
    Map<String, Message> messageTypes = context.messages();
    TypeStore typeStore = createTypes(service, messageTypes);
    String className = ClassNames.getServiceClientClassName(service);
    GapicClass.Kind kind = Kind.MAIN;
    String pakkage = service.pakkage();
    boolean hasLroClient = service.hasStandardLroMethods();
    List<Sample> samples = new ArrayList<>();
    Map<String, List<String>> grpcRpcsToJavaMethodNames = new HashMap<>();
    ClassDefinition classDef = ClassDefinition.builder().setHeaderCommentStatements(createClassHeaderComments(service, typeStore, resourceNames, messageTypes, samples)).setPackageString(pakkage).setAnnotations(createClassAnnotations(service, typeStore)).setScope(ScopeNode.PUBLIC).setName(className).setImplementsTypes(createClassImplements(typeStore)).setStatements(createFieldDeclarations(service, typeStore, hasLroClient)).setMethods(createClassMethods(service, messageTypes, typeStore, resourceNames, hasLroClient, grpcRpcsToJavaMethodNames, samples)).setNestedClasses(createNestedPagingClasses(service, messageTypes, typeStore)).build();
    updateGapicMetadata(context, service, className, grpcRpcsToJavaMethodNames);
    return GapicClass.create(kind, classDef, SampleComposerUtil.handleDuplicateSamples(samples));
}
Also used : Message(com.google.api.generator.gapic.model.Message) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ResourceName(com.google.api.generator.gapic.model.ResourceName) Sample(com.google.api.generator.gapic.model.Sample) ArrayList(java.util.ArrayList) ClassDefinition(com.google.api.generator.engine.ast.ClassDefinition) 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) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with Kind

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

the class AbstractServiceSettingsClassComposer method generate.

@Override
public GapicClass generate(GapicContext context, Service service) {
    String pakkage = service.pakkage();
    TypeStore typeStore = createDynamicTypes(service);
    String className = ClassNames.getServiceSettingsClassName(service);
    GapicClass.Kind kind = Kind.MAIN;
    List<Sample> samples = new ArrayList<>();
    List<CommentStatement> classHeaderComments = createClassHeaderComments(service, typeStore.get(className), samples);
    ClassDefinition classDef = ClassDefinition.builder().setPackageString(pakkage).setHeaderCommentStatements(classHeaderComments).setAnnotations(createClassAnnotations(service)).setScope(ScopeNode.PUBLIC).setName(className).setExtendsType(TypeNode.withReference(FIXED_TYPESTORE.get("ClientSettings").reference().copyAndSetGenerics(Arrays.asList(typeStore.get(ClassNames.getServiceSettingsClassName(service)).reference())))).setMethods(createClassMethods(service, typeStore)).setNestedClasses(Arrays.asList(createNestedBuilderClass(service, typeStore))).build();
    return GapicClass.create(kind, classDef, SampleComposerUtil.handleDuplicateSamples(samples));
}
Also used : CommentStatement(com.google.api.generator.engine.ast.CommentStatement) Sample(com.google.api.generator.gapic.model.Sample) GapicClass(com.google.api.generator.gapic.model.GapicClass) ArrayList(java.util.ArrayList) 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)

Example 4 with Kind

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

the class MockServiceImplClassComposer method generate.

@Override
public GapicClass generate(GapicContext context, Service service) {
    TypeStore typeStore = createDynamicTypes(service);
    String className = ClassNames.getMockServiceImplClassName(service);
    GapicClass.Kind kind = Kind.TEST;
    String pakkage = service.pakkage();
    // Affects GCS.
    if (context.messages().keySet().stream().anyMatch(s -> s.equals("Object") || s.endsWith(".Object"))) {
        javaObjectReference = ConcreteReference.builder().setClazz(Object.class).setUseFullName(true).build();
    }
    responsesVarExpr = VariableExpr.withVariable(Variable.builder().setName("responses").setType(TypeNode.withReference(ConcreteReference.builder().setClazz(Queue.class).setGenerics(Arrays.asList(javaObjectReference)).build())).build());
    ClassDefinition classDef = ClassDefinition.builder().setPackageString(pakkage).setAnnotations(createClassAnnotations()).setScope(ScopeNode.PUBLIC).setName(className).setExtendsType(typeStore.get(String.format(IMPL_BASE_PATTERN, service.name()))).setStatements(createFieldDeclarations()).setMethods(createClassMethods(service, typeStore)).build();
    return GapicClass.create(kind, classDef);
}
Also used : 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) Queue(java.util.Queue)

Example 5 with Kind

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

the class MockServiceClassComposer method generate.

@Override
public GapicClass generate(GapicContext ignored, Service service) {
    TypeStore typeStore = createTypes(service);
    String className = ClassNames.getMockServiceClassName(service);
    GapicClass.Kind kind = Kind.TEST;
    String pakkage = service.pakkage();
    ClassDefinition classDef = ClassDefinition.builder().setPackageString(pakkage).setAnnotations(createClassAnnotations(typeStore)).setScope(ScopeNode.PUBLIC).setName(className).setImplementsTypes(createClassImplements(typeStore)).setStatements(createFieldDeclarations(service, typeStore)).setMethods(createClassMethods(service, typeStore)).build();
    return GapicClass.create(kind, classDef);
}
Also used : 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)8 TypeStore (com.google.api.generator.gapic.composer.store.TypeStore)8 GapicClass (com.google.api.generator.gapic.model.GapicClass)8 Kind (com.google.api.generator.gapic.model.GapicClass.Kind)8 Message (com.google.api.generator.gapic.model.Message)3 CommentStatement (com.google.api.generator.engine.ast.CommentStatement)2 VariableExpr (com.google.api.generator.engine.ast.VariableExpr)2 StubCommentComposer (com.google.api.generator.gapic.composer.comment.StubCommentComposer)2 ResourceName (com.google.api.generator.gapic.model.ResourceName)2 Sample (com.google.api.generator.gapic.model.Sample)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 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 HashMap (java.util.HashMap)1 List (java.util.List)1 Queue (java.util.Queue)1