use of com.palantir.conjure.python.types.DefinitionImportTypeDefinitionVisitor in project conjure-python by palantir.
the class ConjurePythonGenerator method getInitFiles.
private List<PythonFile> getInitFiles(ConjureDefinition conjureDefinition, TypeNameProcessor implTypeNameProcessor, PackageNameProcessor definitionPackageNameProcessor, TypeNameProcessor definitionTypeNameProcessor) {
String moduleSpecifier = ".._impl";
DefinitionImportTypeDefinitionVisitor definitionImportTypeDefinitionVisitor = new DefinitionImportTypeDefinitionVisitor(moduleSpecifier, implTypeNameProcessor, definitionTypeNameProcessor);
List<PythonSnippet> snippets = new ArrayList<>();
snippets.addAll(conjureDefinition.getTypes().stream().map(typeDefinition -> {
TypeName typeName = typeDefinition.accept(TypeDefinitionVisitor.TYPE_NAME);
return EmptySnippet.builder().pythonPackage(PythonPackage.of(definitionPackageNameProcessor.process(typeName.getPackage()))).addAllImports(typeDefinition.accept(definitionImportTypeDefinitionVisitor)).build();
}).collect(Collectors.toList()));
snippets.addAll(conjureDefinition.getServices().stream().map(serviceDefinition -> EmptySnippet.builder().pythonPackage(PythonPackage.of(definitionPackageNameProcessor.process(serviceDefinition.getServiceName().getPackage()))).addImports(PythonImport.of(moduleSpecifier, NamedImport.of(implTypeNameProcessor.process(serviceDefinition.getServiceName()), definitionTypeNameProcessor.process(serviceDefinition.getServiceName())))).build()).collect(Collectors.toList()));
Map<PythonPackage, List<PythonSnippet>> snippetsByPackage = snippets.stream().collect(Collectors.groupingBy(PythonSnippet::pythonPackage));
return KeyedStream.stream(snippetsByPackage).map((pythonPackage, pythonSnippets) -> PythonFile.builder().pythonPackage(pythonPackage).fileName(INIT_PY).contents(pythonSnippets).build()).values().collect(Collectors.toList());
}
Aggregations