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);
}
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));
}
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));
}
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);
}
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);
}
Aggregations