use of com.palantir.conjure.python.processors.packagename.PackageNameProcessor 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.processors.packagename.PackageNameProcessor in project conjure-python by palantir.
the class PackageNameProcessorTests method testPackageNameProcessorComposition.
@Test
public void testPackageNameProcessorComposition() {
PackageNameProcessor processor = new CompoundPackageNameProcessor(ImmutableList.of(new TwoComponentStrippingPackageNameProcessor(), FlatteningPackageNameProcessor.INSTANCE, new PrefixingPackageNameProcessor("toplevel")));
assertThat(processor.process("test")).isEqualTo("toplevel.test");
assertThat(processor.process("test.whatever")).isEqualTo("toplevel.test_whatever");
assertThat(processor.process("com.palantir.test")).isEqualTo("toplevel.test");
assertThat(processor.process("com.palantir.test.whatever")).isEqualTo("toplevel.test_whatever");
}
use of com.palantir.conjure.python.processors.packagename.PackageNameProcessor in project conjure-python by palantir.
the class PackageNameProcessorTests method testTwoComponentStrippingPackageNameProcessor.
@Test
public void testTwoComponentStrippingPackageNameProcessor() {
PackageNameProcessor processor = new CompoundPackageNameProcessor(ImmutableList.of(new TwoComponentStrippingPackageNameProcessor()));
assertThat(processor.process("com.palantir.test")).isEqualTo("test");
assertThat(processor.process("com.palantir")).isEqualTo("com.palantir");
}
use of com.palantir.conjure.python.processors.packagename.PackageNameProcessor in project conjure-python by palantir.
the class PackageNameProcessorTests method testPackageNameProcessor.
@Test
public void testPackageNameProcessor() {
PackageNameProcessor processor = new CompoundPackageNameProcessor(ImmutableList.of());
assertThat(processor.process("com.palantir.test")).isEqualTo("com.palantir.test");
}
use of com.palantir.conjure.python.processors.packagename.PackageNameProcessor in project conjure-python by palantir.
the class PackageNameProcessorTests method testTopLevelRenamingPackageNameProcessor.
@Test
public void testTopLevelRenamingPackageNameProcessor() {
PackageNameProcessor processor = new CompoundPackageNameProcessor(ImmutableList.of(new PrefixingPackageNameProcessor("toplevel")));
assertThat(processor.process("test")).isEqualTo("toplevel.test");
assertThat(processor.process("test.whatever")).isEqualTo("toplevel.test.whatever");
}
Aggregations