Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit 85a9f6b

Browse files
authored
fix(backend): rename modules after annotations are processed (#1024)
* fix(backend): rename modules after annotations are processed * test: update failing tests
1 parent 48bba49 commit 85a9f6b

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

api-editor/backend/src/main/kotlin/com/larsreimann/apiEditor/transformation/TransformationPlan.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ import com.larsreimann.apiEditor.mutableModel.PythonPackage
66
* Processes all annotations and updates the AST to create adapters.
77
*/
88
fun PythonPackage.transform(newPackageName: String = "new_package") {
9-
preprocess(newPackageName)
9+
preprocess()
1010
processAnnotations()
11-
postprocess()
11+
postprocess(newPackageName)
1212
}
1313

1414
/**
1515
* Transformation steps that have to be run before annotations can be processed.
1616
*/
17-
private fun PythonPackage.preprocess(newPackageName: String) {
17+
private fun PythonPackage.preprocess() {
1818
removePrivateDeclarations()
1919
addOriginalDeclarations()
20-
changeModulePrefix(newPackageName)
2120
replaceClassMethodsWithStaticMethods()
2221
updateParameterAssignment()
2322
normalizeNamesOfImplicitParameters()
@@ -43,8 +42,9 @@ private fun PythonPackage.processAnnotations() {
4342
/**
4443
* Transformation steps that have to be run after annotations were processed.
4544
*/
46-
private fun PythonPackage.postprocess() {
45+
private fun PythonPackage.postprocess(newPackageName: String) {
4746
removeEmptyModules()
47+
changeModulePrefix(newPackageName)
4848
reorderParameters()
4949
extractConstructors()
5050
createAttributesForParametersOfConstructor()

api-editor/backend/src/test/kotlin/com/larsreimann/apiEditor/codegen/ConstructorPythonCodeGeneratorFullPipelineTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,10 +710,10 @@ class ConstructorPythonCodeGeneratorFullPipelineTest {
710710
RenameAnnotation("renamedTestClass"),
711711
)
712712
testClass.annotations.add(
713-
MoveAnnotation("movedTestModule"),
713+
MoveAnnotation("testModule.movedTestModule"),
714714
)
715715
// when
716-
testPackage.transform()
716+
testPackage.transform("newTestModule")
717717
val moduleContent = testPackage.modules[0].toPythonCode()
718718

719719
// then
@@ -753,6 +753,6 @@ class ConstructorPythonCodeGeneratorFullPipelineTest {
753753
""".trimMargin()
754754

755755
moduleContent shouldBe expectedModuleContent
756-
testPackage.modules[0].name shouldBe "movedTestModule"
756+
testPackage.modules[0].name shouldBe "newTestModule.movedTestModule"
757757
}
758758
}

api-editor/backend/src/test/kotlin/com/larsreimann/apiEditor/codegen/FunctionPythonCodeGeneratorFullPipelineTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -638,10 +638,10 @@ class FunctionPythonCodeGeneratorFullPipelineTest {
638638
),
639639
)
640640
testFunction.annotations.add(
641-
MoveAnnotation("movedTestModule"),
641+
MoveAnnotation("testModule.movedTestModule"),
642642
)
643643
// when
644-
testPackage.transform()
644+
testPackage.transform("newTestModule")
645645
val moduleContent = testPackage.modules[0].toPythonCode()
646646

647647
// then
@@ -677,7 +677,7 @@ class FunctionPythonCodeGeneratorFullPipelineTest {
677677
""".trimMargin()
678678

679679
moduleContent shouldBe expectedModuleContent
680-
testPackage.modules[0].name shouldBe "movedTestModule"
680+
testPackage.modules[0].name shouldBe "newTestModule.movedTestModule"
681681
}
682682

683683
@Test

0 commit comments

Comments
 (0)