Search in sources :

Example 1 with PackageNameProcessor

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;
}
Also used : ConstantPackageNameProcessor(com.palantir.conjure.python.processors.packagename.ConstantPackageNameProcessor) FlatteningPackageNameProcessor(com.palantir.conjure.python.processors.packagename.FlatteningPackageNameProcessor) PackageNameProcessor(com.palantir.conjure.python.processors.packagename.PackageNameProcessor) TwoComponentStrippingPackageNameProcessor(com.palantir.conjure.python.processors.packagename.TwoComponentStrippingPackageNameProcessor) PrefixingPackageNameProcessor(com.palantir.conjure.python.processors.packagename.PrefixingPackageNameProcessor) CompoundPackageNameProcessor(com.palantir.conjure.python.processors.packagename.CompoundPackageNameProcessor) PythonPackage(com.palantir.conjure.python.poet.PythonPackage) ArrayList(java.util.ArrayList) DealiasingTypeVisitor(com.palantir.conjure.visitor.DealiasingTypeVisitor) TwoComponentStrippingPackageNameProcessor(com.palantir.conjure.python.processors.packagename.TwoComponentStrippingPackageNameProcessor) PythonFile(com.palantir.conjure.python.poet.PythonFile) ConstantPackageNameProcessor(com.palantir.conjure.python.processors.packagename.ConstantPackageNameProcessor) PrefixingPackageNameProcessor(com.palantir.conjure.python.processors.packagename.PrefixingPackageNameProcessor) PackagePrependingTypeNameProcessor(com.palantir.conjure.python.processors.typename.PackagePrependingTypeNameProcessor) NameOnlyTypeNameProcessor(com.palantir.conjure.python.processors.typename.NameOnlyTypeNameProcessor) TypeNameProcessor(com.palantir.conjure.python.processors.typename.TypeNameProcessor) PackagePrependingTypeNameProcessor(com.palantir.conjure.python.processors.typename.PackagePrependingTypeNameProcessor) CompoundPackageNameProcessor(com.palantir.conjure.python.processors.packagename.CompoundPackageNameProcessor)

Example 2 with PackageNameProcessor

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");
}
Also used : PrefixingPackageNameProcessor(com.palantir.conjure.python.processors.packagename.PrefixingPackageNameProcessor) FlatteningPackageNameProcessor(com.palantir.conjure.python.processors.packagename.FlatteningPackageNameProcessor) PackageNameProcessor(com.palantir.conjure.python.processors.packagename.PackageNameProcessor) CompoundPackageNameProcessor(com.palantir.conjure.python.processors.packagename.CompoundPackageNameProcessor) TwoComponentStrippingPackageNameProcessor(com.palantir.conjure.python.processors.packagename.TwoComponentStrippingPackageNameProcessor) PrefixingPackageNameProcessor(com.palantir.conjure.python.processors.packagename.PrefixingPackageNameProcessor) TwoComponentStrippingPackageNameProcessor(com.palantir.conjure.python.processors.packagename.TwoComponentStrippingPackageNameProcessor) CompoundPackageNameProcessor(com.palantir.conjure.python.processors.packagename.CompoundPackageNameProcessor) Test(org.junit.Test)

Example 3 with PackageNameProcessor

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");
}
Also used : PrefixingPackageNameProcessor(com.palantir.conjure.python.processors.packagename.PrefixingPackageNameProcessor) FlatteningPackageNameProcessor(com.palantir.conjure.python.processors.packagename.FlatteningPackageNameProcessor) PackageNameProcessor(com.palantir.conjure.python.processors.packagename.PackageNameProcessor) CompoundPackageNameProcessor(com.palantir.conjure.python.processors.packagename.CompoundPackageNameProcessor) TwoComponentStrippingPackageNameProcessor(com.palantir.conjure.python.processors.packagename.TwoComponentStrippingPackageNameProcessor) TwoComponentStrippingPackageNameProcessor(com.palantir.conjure.python.processors.packagename.TwoComponentStrippingPackageNameProcessor) CompoundPackageNameProcessor(com.palantir.conjure.python.processors.packagename.CompoundPackageNameProcessor) Test(org.junit.Test)

Example 4 with PackageNameProcessor

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");
}
Also used : PrefixingPackageNameProcessor(com.palantir.conjure.python.processors.packagename.PrefixingPackageNameProcessor) FlatteningPackageNameProcessor(com.palantir.conjure.python.processors.packagename.FlatteningPackageNameProcessor) PackageNameProcessor(com.palantir.conjure.python.processors.packagename.PackageNameProcessor) CompoundPackageNameProcessor(com.palantir.conjure.python.processors.packagename.CompoundPackageNameProcessor) TwoComponentStrippingPackageNameProcessor(com.palantir.conjure.python.processors.packagename.TwoComponentStrippingPackageNameProcessor) CompoundPackageNameProcessor(com.palantir.conjure.python.processors.packagename.CompoundPackageNameProcessor) Test(org.junit.Test)

Example 5 with PackageNameProcessor

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");
}
Also used : PrefixingPackageNameProcessor(com.palantir.conjure.python.processors.packagename.PrefixingPackageNameProcessor) FlatteningPackageNameProcessor(com.palantir.conjure.python.processors.packagename.FlatteningPackageNameProcessor) PackageNameProcessor(com.palantir.conjure.python.processors.packagename.PackageNameProcessor) CompoundPackageNameProcessor(com.palantir.conjure.python.processors.packagename.CompoundPackageNameProcessor) TwoComponentStrippingPackageNameProcessor(com.palantir.conjure.python.processors.packagename.TwoComponentStrippingPackageNameProcessor) PrefixingPackageNameProcessor(com.palantir.conjure.python.processors.packagename.PrefixingPackageNameProcessor) CompoundPackageNameProcessor(com.palantir.conjure.python.processors.packagename.CompoundPackageNameProcessor) Test(org.junit.Test)

Aggregations

CompoundPackageNameProcessor (com.palantir.conjure.python.processors.packagename.CompoundPackageNameProcessor)7 FlatteningPackageNameProcessor (com.palantir.conjure.python.processors.packagename.FlatteningPackageNameProcessor)7 PackageNameProcessor (com.palantir.conjure.python.processors.packagename.PackageNameProcessor)7 PrefixingPackageNameProcessor (com.palantir.conjure.python.processors.packagename.PrefixingPackageNameProcessor)7 TwoComponentStrippingPackageNameProcessor (com.palantir.conjure.python.processors.packagename.TwoComponentStrippingPackageNameProcessor)7 Test (org.junit.Test)5 ConstantPackageNameProcessor (com.palantir.conjure.python.processors.packagename.ConstantPackageNameProcessor)2 ArrayList (java.util.ArrayList)2 PythonFile (com.palantir.conjure.python.poet.PythonFile)1 PythonPackage (com.palantir.conjure.python.poet.PythonPackage)1 NameOnlyTypeNameProcessor (com.palantir.conjure.python.processors.typename.NameOnlyTypeNameProcessor)1 PackagePrependingTypeNameProcessor (com.palantir.conjure.python.processors.typename.PackagePrependingTypeNameProcessor)1 TypeNameProcessor (com.palantir.conjure.python.processors.typename.TypeNameProcessor)1 DealiasingTypeVisitor (com.palantir.conjure.visitor.DealiasingTypeVisitor)1