Search in sources :

Example 1 with DefinitionImportTypeDefinitionVisitor

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());
}
Also used : PythonPackage(com.palantir.conjure.python.poet.PythonPackage) TypeName(com.palantir.conjure.spec.TypeName) PythonSnippet(com.palantir.conjure.python.poet.PythonSnippet) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) DefinitionImportTypeDefinitionVisitor(com.palantir.conjure.python.types.DefinitionImportTypeDefinitionVisitor)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 PythonPackage (com.palantir.conjure.python.poet.PythonPackage)1 PythonSnippet (com.palantir.conjure.python.poet.PythonSnippet)1 DefinitionImportTypeDefinitionVisitor (com.palantir.conjure.python.types.DefinitionImportTypeDefinitionVisitor)1 TypeName (com.palantir.conjure.spec.TypeName)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1