use of com.google.api.generator.gapic.composer.store.TypeStore in project gapic-generator-java by googleapis.
the class AbstractServiceSettingsClassComposer method createDynamicTypes.
private static TypeStore createDynamicTypes(Service service) {
TypeStore typeStore = new TypeStore();
// ServiceStubSettings class.
typeStore.put(String.format("%s.stub", service.pakkage()), ClassNames.getServiceStubSettingsClassName(service));
// This class.
typeStore.put(service.pakkage(), ClassNames.getServiceSettingsClassName(service));
// Nested Builder class.
typeStore.put(service.pakkage(), BUILDER_CLASS_NAME, true, ClassNames.getServiceSettingsClassName(service));
// Pagination types.
typeStore.putAll(service.pakkage(), service.methods().stream().filter(m -> m.isPaged()).map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())).collect(Collectors.toList()), true, ClassNames.getServiceClientClassName(service));
return typeStore;
}
use of com.google.api.generator.gapic.composer.store.TypeStore in project gapic-generator-java by googleapis.
the class AbstractServiceStubClassComposer method createTypes.
private static TypeStore createTypes(Service service, Map<String, Message> messageTypes) {
List<Class<?>> concreteClazzes = Arrays.asList(BackgroundResource.class, BetaApi.class, BidiStreamingCallable.class, ClientStreamingCallable.class, Generated.class, Operation.class, OperationCallable.class, ServerStreamingCallable.class, UnaryCallable.class, UnsupportedOperationException.class);
TypeStore typeStore = new TypeStore(concreteClazzes);
typeStore.put("com.google.longrunning.stub", "OperationsStub");
// Pagination types.
typeStore.putAll(service.pakkage(), service.methods().stream().filter(m -> m.isPaged()).map(m -> String.format(PAGED_RESPONSE_TYPE_NAME_PATTERN, m.name())).collect(Collectors.toList()), true, ClassNames.getServiceClientClassName(service));
return typeStore;
}
use of com.google.api.generator.gapic.composer.store.TypeStore in project gapic-generator-java by googleapis.
the class AbstractServiceClientClassComposer method createBackgroundResourceMethods.
private static List<MethodDefinition> createBackgroundResourceMethods(Service service, TypeStore typeStore) {
List<MethodDefinition> methods = new ArrayList<>();
VariableExpr stubVarExpr = VariableExpr.withVariable(Variable.builder().setType(typeStore.get(ClassNames.getServiceStubClassName(service))).setName("stub").build());
MethodDefinition closeMethod = MethodDefinition.builder().setIsOverride(true).setScope(ScopeNode.PUBLIC).setIsFinal(true).setReturnType(TypeNode.VOID).setName("close").setBody(Arrays.asList(ExprStatement.withExpr(MethodInvocationExpr.builder().setExprReferenceExpr(stubVarExpr).setMethodName("close").build()))).build();
methods.add(closeMethod);
MethodDefinition shutdownMethod = MethodDefinition.builder().setIsOverride(true).setScope(ScopeNode.PUBLIC).setReturnType(TypeNode.VOID).setName("shutdown").setBody(Arrays.asList(ExprStatement.withExpr(MethodInvocationExpr.builder().setExprReferenceExpr(stubVarExpr).setMethodName("shutdown").build()))).build();
methods.add(shutdownMethod);
MethodDefinition isShutdownMethod = MethodDefinition.builder().setIsOverride(true).setScope(ScopeNode.PUBLIC).setReturnType(TypeNode.BOOLEAN).setName("isShutdown").setReturnExpr(MethodInvocationExpr.builder().setExprReferenceExpr(stubVarExpr).setMethodName("isShutdown").setReturnType(TypeNode.BOOLEAN).build()).build();
methods.add(isShutdownMethod);
MethodDefinition isTerminatedMethod = MethodDefinition.builder().setIsOverride(true).setScope(ScopeNode.PUBLIC).setReturnType(TypeNode.BOOLEAN).setName("isTerminated").setReturnExpr(MethodInvocationExpr.builder().setExprReferenceExpr(stubVarExpr).setMethodName("isTerminated").setReturnType(TypeNode.BOOLEAN).build()).build();
methods.add(isTerminatedMethod);
MethodDefinition shutdownNowMethod = MethodDefinition.builder().setIsOverride(true).setScope(ScopeNode.PUBLIC).setReturnType(TypeNode.VOID).setName("shutdownNow").setBody(Arrays.asList(ExprStatement.withExpr(MethodInvocationExpr.builder().setExprReferenceExpr(stubVarExpr).setMethodName("shutdownNow").build()))).build();
methods.add(shutdownNowMethod);
List<VariableExpr> arguments = Arrays.asList(VariableExpr.builder().setVariable(Variable.builder().setName("duration").setType(TypeNode.LONG).build()).build(), VariableExpr.builder().setVariable(Variable.builder().setName("unit").setType(typeStore.get("TimeUnit")).build()).build());
MethodDefinition awaitTerminationMethod = MethodDefinition.builder().setIsOverride(true).setScope(ScopeNode.PUBLIC).setReturnType(TypeNode.BOOLEAN).setName("awaitTermination").setArguments(arguments.stream().map(v -> v.toBuilder().setIsDecl(true).build()).collect(Collectors.toList())).setThrowsExceptions(Arrays.asList(typeStore.get("InterruptedException"))).setReturnExpr(MethodInvocationExpr.builder().setExprReferenceExpr(stubVarExpr).setMethodName("awaitTermination").setArguments(arguments.stream().map(v -> (Expr) v).collect(Collectors.toList())).setReturnType(TypeNode.BOOLEAN).build()).build();
methods.add(awaitTerminationMethod);
return methods;
}
use of com.google.api.generator.gapic.composer.store.TypeStore 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.composer.store.TypeStore in project gapic-generator-java by googleapis.
the class MockServiceImplClassComposer method createDynamicTypes.
private static TypeStore createDynamicTypes(Service service) {
TypeStore typeStore = new TypeStore();
// Hack: This two should be nested classes and perhaps a static import or something.
typeStore.put(String.format("%s.%sGrpc", service.originalJavaPackage(), service.name()), String.format(IMPL_BASE_PATTERN, service.name()));
typeStore.put(service.pakkage(), ClassNames.getMockServiceImplClassName(service));
return typeStore;
}
Aggregations