use of com.palantir.conjure.python.poet.PythonFile in project conjure-python by palantir.
the class ConjurePythonGenerator method generate.
private List<PythonFile> generate(ConjureDefinition conjureDefinition) {
DealiasingTypeVisitor dealiasingTypeVisitor = new DealiasingTypeVisitor(conjureDefinition.getTypes().stream().collect(Collectors.toMap(type -> type.accept(TypeDefinitionVisitor.TYPE_NAME), Function.identity())));
PackageNameProcessor implPackageNameProcessor = new ConstantPackageNameProcessor(config.pythonicPackageName().orElse(""));
List<PackageNameProcessor> packageNameProcessors = new ArrayList<>();
packageNameProcessors.add(new TwoComponentStrippingPackageNameProcessor());
packageNameProcessors.add(FlatteningPackageNameProcessor.INSTANCE);
packageNameProcessors.addAll(config.pythonicPackageName().map(pythonPackageName -> ImmutableSet.of(new PrefixingPackageNameProcessor(pythonPackageName))).orElseGet(ImmutableSet::of));
PackageNameProcessor definitionPackageNameProcessor = new CompoundPackageNameProcessor(packageNameProcessors);
TypeNameProcessor implTypeNameProcessor = new PackagePrependingTypeNameProcessor(new CompoundPackageNameProcessor(ImmutableList.of(new TwoComponentStrippingPackageNameProcessor(), FlatteningPackageNameProcessor.INSTANCE)));
TypeNameProcessor definitionTypeNameProcessor = NameOnlyTypeNameProcessor.INSTANCE;
List<PythonFile> pythonFiles = new ArrayList<>();
pythonFiles.add(getImplPythonFile(conjureDefinition, dealiasingTypeVisitor, implPackageNameProcessor, implTypeNameProcessor, definitionPackageNameProcessor, definitionTypeNameProcessor));
List<PythonFile> initFiles = getInitFiles(conjureDefinition, implTypeNameProcessor, definitionPackageNameProcessor, definitionTypeNameProcessor);
pythonFiles.addAll(initFiles);
PythonPackage rootPackage = PythonPackage.of(buildPackageNameProcessor().process("."));
pythonFiles.add(getRootInit(initFiles.stream().map(PythonFile::pythonPackage).collect(Collectors.toSet()), rootPackage));
return pythonFiles;
}
use of com.palantir.conjure.python.poet.PythonFile in project conjure-python by palantir.
the class ConjurePythonGenerator method getImplPythonFile.
private PythonFile getImplPythonFile(ConjureDefinition conjureDefinition, DealiasingTypeVisitor dealiasingTypeVisitor, PackageNameProcessor implPackageNameProcessor, TypeNameProcessor implTypeNameProcessor, PackageNameProcessor definitionPackageNameProcessor, TypeNameProcessor definitionTypeNameProcessor) {
PythonTypeGenerator beanGenerator = new PythonTypeGenerator(implPackageNameProcessor, implTypeNameProcessor, definitionPackageNameProcessor, definitionTypeNameProcessor, dealiasingTypeVisitor);
ClientGenerator clientGenerator = new ClientGenerator(implPackageNameProcessor, implTypeNameProcessor, definitionPackageNameProcessor, definitionTypeNameProcessor, dealiasingTypeVisitor);
List<PythonSnippet> snippets = new ArrayList<>();
snippets.addAll(conjureDefinition.getTypes().stream().map(beanGenerator::generateType).collect(Collectors.toList()));
snippets.addAll(conjureDefinition.getServices().stream().map(clientGenerator::generateClient).collect(Collectors.toList()));
Map<PythonPackage, List<PythonSnippet>> snippetsByPackage = snippets.stream().collect(Collectors.groupingBy(PythonSnippet::pythonPackage));
PythonPackage rootPackage = PythonPackage.of(implPackageNameProcessor.process(""));
List<PythonFile> pythonFiles = KeyedStream.stream(snippetsByPackage).map((_pythonPackage, pythonSnippets) -> PythonFile.builder().pythonPackage(rootPackage).fileName(IMPL_PY).contents(pythonSnippets).build()).values().collect(Collectors.toList());
return Iterables.getOnlyElement(pythonFiles);
}
Aggregations