use of com.google.api.generator.gapic.composer.store.TypeStore in project gapic-generator-java by googleapis.
the class ResourceNameHelperClassComposer method createDynamicTypes.
private static TypeStore createDynamicTypes(ResourceName resourceName, List<List<String>> tokenHierarchies) {
String thisClassName = getThisClassName(resourceName);
TypeStore typeStore = new TypeStore();
typeStore.put(resourceName.pakkage(), thisClassName);
typeStore.put(resourceName.pakkage(), "Builder", true, thisClassName);
// Special-cased PubSub handling.
List<List<String>> processedTokenHierarchies = tokenHierarchies.stream().filter(tokens -> !tokens.contains(ResourceNameConstants.DELETED_TOPIC_LITERAL)).collect(Collectors.toList());
if (processedTokenHierarchies.size() > 1) {
typeStore.putAll(resourceName.pakkage(), tokenHierarchies.subList(1, tokenHierarchies.size()).stream().map(ts -> getBuilderTypeName(ts)).collect(Collectors.toList()));
}
return typeStore;
}
use of com.google.api.generator.gapic.composer.store.TypeStore in project gapic-generator-java by googleapis.
the class ServiceClientTestClassComposer method createStartStaticServerMethod.
@Override
protected MethodDefinition createStartStaticServerMethod(Service service, GapicContext context, Map<String, VariableExpr> classMemberVarExprs, TypeStore typeStore, String newBuilderMethod) {
VariableExpr serviceHelperVarExpr = classMemberVarExprs.get(SERVICE_HELPER_VAR_NAME);
Function<Service, VariableExpr> serviceToVarExprFn = s -> classMemberVarExprs.get(getMockServiceVarName(s));
Function<Service, Expr> serviceToVarInitExprFn = s -> {
VariableExpr mockServiceVarExpr = serviceToVarExprFn.apply(s);
return AssignmentExpr.builder().setVariableExpr(mockServiceVarExpr).setValueExpr(NewObjectExpr.builder().setType(mockServiceVarExpr.type()).build()).build();
};
List<Expr> varInitExprs = new ArrayList<>();
List<Expr> mockServiceVarExprs = new ArrayList<>();
varInitExprs.add(serviceToVarInitExprFn.apply(service));
mockServiceVarExprs.add(serviceToVarExprFn.apply(service));
// Context: https://github.com/googleapis/gapic-generator-java/pull/750
for (Service mixinService : context.mixinServices().stream().sorted((s1, s2) -> s2.name().compareTo(s1.name())).collect(Collectors.toList())) {
varInitExprs.add(serviceToVarInitExprFn.apply(mixinService));
mockServiceVarExprs.add(serviceToVarExprFn.apply(mixinService));
}
MethodInvocationExpr firstArg = MethodInvocationExpr.builder().setStaticReferenceType(FIXED_TYPESTORE.get("UUID")).setMethodName("randomUUID").build();
firstArg = MethodInvocationExpr.builder().setExprReferenceExpr(firstArg).setMethodName("toString").build();
MethodInvocationExpr secondArg = MethodInvocationExpr.builder().setStaticReferenceType(FIXED_TYPESTORE.get("Arrays")).setGenerics(Arrays.asList(FIXED_GRPC_TYPESTORE.get("MockGrpcService").reference())).setMethodName("asList").setArguments(mockServiceVarExprs).build();
Expr initServiceHelperExpr = AssignmentExpr.builder().setVariableExpr(serviceHelperVarExpr).setValueExpr(NewObjectExpr.builder().setType(serviceHelperVarExpr.type()).setArguments(Arrays.asList(firstArg, secondArg)).build()).build();
Expr startServiceHelperExpr = MethodInvocationExpr.builder().setExprReferenceExpr(serviceHelperVarExpr).setMethodName("start").build();
varInitExprs.add(initServiceHelperExpr);
varInitExprs.add(startServiceHelperExpr);
return MethodDefinition.builder().setAnnotations(Arrays.asList(AnnotationNode.withType(FIXED_TYPESTORE.get("BeforeClass")))).setScope(ScopeNode.PUBLIC).setIsStatic(true).setReturnType(TypeNode.VOID).setName("startStaticServer").setBody(varInitExprs.stream().map(e -> ExprStatement.withExpr(e)).collect(Collectors.toList())).build();
}
use of com.google.api.generator.gapic.composer.store.TypeStore in project gapic-generator-java by googleapis.
the class ServiceClientTestClassComposer method createClassMemberVarExprs.
@Override
protected Map<String, VariableExpr> createClassMemberVarExprs(Service service, GapicContext context, TypeStore typeStore) {
BiFunction<String, TypeNode, VariableExpr> varExprFn = (name, type) -> VariableExpr.withVariable(Variable.builder().setName(name).setType(type).build());
// Keep keys sorted in alphabetical order to ensure that the test output is deterministic.
Map<String, TypeNode> fields = new TreeMap<>();
fields.put(getMockServiceVarName(service), typeStore.get(ClassNames.getMockServiceClassName(service)));
for (Service mixinService : context.mixinServices()) {
fields.put(getMockServiceVarName(mixinService), typeStore.get(ClassNames.getMockServiceClassName(mixinService)));
}
fields.put(SERVICE_HELPER_VAR_NAME, FIXED_GRPC_TYPESTORE.get("MockServiceHelper"));
fields.put(CLIENT_VAR_NAME, typeStore.get(ClassNames.getServiceClientClassName(service)));
fields.put(CHANNEL_PROVIDER_VAR_NAME, FIXED_GRPC_TYPESTORE.get("LocalChannelProvider"));
return fields.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> varExprFn.apply(e.getKey(), e.getValue()), (u, v) -> {
throw new IllegalStateException();
}, TreeMap::new));
}
use of com.google.api.generator.gapic.composer.store.TypeStore in project gapic-generator-java by googleapis.
the class MockServiceClassComposer method createTypes.
private static TypeStore createTypes(Service service) {
List<Class<?>> concreteClazzes = Arrays.asList(AbstractMessage.class, BetaApi.class, Generated.class, ServerServiceDefinition.class);
TypeStore typeStore = new TypeStore(concreteClazzes);
typeStore.put("com.google.api.gax.grpc.testing", "MockGrpcService");
typeStore.putAll(service.pakkage(), Arrays.asList(ClassNames.getMockServiceImplClassName(service), ClassNames.getMockServiceClassName(service)));
return typeStore;
}
Aggregations