Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ import com.larsreimann.apiEditor.mutableModel.PythonPackage
* Processes all annotations and updates the AST to create adapters.
*/
fun PythonPackage.transform(newPackageName: String = "new_package") {
preprocess(newPackageName)
preprocess()
processAnnotations()
postprocess()
postprocess(newPackageName)
}

/**
* Transformation steps that have to be run before annotations can be processed.
*/
private fun PythonPackage.preprocess(newPackageName: String) {
private fun PythonPackage.preprocess() {
removePrivateDeclarations()
addOriginalDeclarations()
changeModulePrefix(newPackageName)
replaceClassMethodsWithStaticMethods()
updateParameterAssignment()
normalizeNamesOfImplicitParameters()
Expand All @@ -43,8 +42,9 @@ private fun PythonPackage.processAnnotations() {
/**
* Transformation steps that have to be run after annotations were processed.
*/
private fun PythonPackage.postprocess() {
private fun PythonPackage.postprocess(newPackageName: String) {
removeEmptyModules()
changeModulePrefix(newPackageName)
reorderParameters()
extractConstructors()
createAttributesForParametersOfConstructor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,10 +710,10 @@ class ConstructorPythonCodeGeneratorFullPipelineTest {
RenameAnnotation("renamedTestClass"),
)
testClass.annotations.add(
MoveAnnotation("movedTestModule"),
MoveAnnotation("testModule.movedTestModule"),
)
// when
testPackage.transform()
testPackage.transform("newTestModule")
val moduleContent = testPackage.modules[0].toPythonCode()

// then
Expand Down Expand Up @@ -753,6 +753,6 @@ class ConstructorPythonCodeGeneratorFullPipelineTest {
""".trimMargin()

moduleContent shouldBe expectedModuleContent
testPackage.modules[0].name shouldBe "movedTestModule"
testPackage.modules[0].name shouldBe "newTestModule.movedTestModule"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -638,10 +638,10 @@ class FunctionPythonCodeGeneratorFullPipelineTest {
),
)
testFunction.annotations.add(
MoveAnnotation("movedTestModule"),
MoveAnnotation("testModule.movedTestModule"),
)
// when
testPackage.transform()
testPackage.transform("newTestModule")
val moduleContent = testPackage.modules[0].toPythonCode()

// then
Expand Down Expand Up @@ -677,7 +677,7 @@ class FunctionPythonCodeGeneratorFullPipelineTest {
""".trimMargin()

moduleContent shouldBe expectedModuleContent
testPackage.modules[0].name shouldBe "movedTestModule"
testPackage.modules[0].name shouldBe "newTestModule.movedTestModule"
}

@Test
Expand Down