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

Commit 0de1b85

Browse files
committed
refactor: remove outdated PythonParameterAssignment values
1 parent 65f4844 commit 0de1b85

File tree

7 files changed

+7
-67
lines changed

7 files changed

+7
-67
lines changed

Diff for: server/src/main/kotlin/com/larsreimann/api_editor/codegen/PythonCodeGenerator.kt

-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.larsreimann.api_editor.codegen
22

33
import com.larsreimann.api_editor.model.ComparisonOperator
4-
import com.larsreimann.api_editor.model.PythonParameterAssignment.ENUM
5-
import com.larsreimann.api_editor.model.PythonParameterAssignment.GROUP
64
import com.larsreimann.api_editor.model.PythonParameterAssignment.IMPLICIT
75
import com.larsreimann.api_editor.model.PythonParameterAssignment.NAME_ONLY
86
import com.larsreimann.api_editor.model.PythonParameterAssignment.POSITION_ONLY
@@ -191,10 +189,7 @@ private fun buildParameters(parameters: List<PythonParameter>): String {
191189
IMPLICIT -> implicitParameters.add(pythonParameter.toPythonCode())
192190
POSITION_ONLY -> positionOnlyParameters.add(pythonParameter.toPythonCode())
193191
POSITION_OR_NAME -> positionOrNameParameters.add(pythonParameter.toPythonCode())
194-
ENUM -> positionOrNameParameters.add(pythonParameter.toPythonCode())
195-
GROUP -> positionOrNameParameters.add(pythonParameter.toPythonCode())
196192
NAME_ONLY -> nameOnlyParameters.add(pythonParameter.toPythonCode())
197-
else -> {}
198193
}
199194
}
200195
assert(implicitParameters.size < 2)

Diff for: server/src/main/kotlin/com/larsreimann/api_editor/codegen/StubCodeGenerator.kt

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package com.larsreimann.api_editor.codegen
22

3-
import com.larsreimann.api_editor.model.PythonParameterAssignment.ENUM
4-
import com.larsreimann.api_editor.model.PythonParameterAssignment.GROUP
5-
import com.larsreimann.api_editor.model.PythonParameterAssignment.NAME_ONLY
6-
import com.larsreimann.api_editor.model.PythonParameterAssignment.POSITION_ONLY
7-
import com.larsreimann.api_editor.model.PythonParameterAssignment.POSITION_OR_NAME
3+
import com.larsreimann.api_editor.model.PythonParameterAssignment.IMPLICIT
84
import com.larsreimann.api_editor.mutable_model.PythonAttribute
95
import com.larsreimann.api_editor.mutable_model.PythonClass
106
import com.larsreimann.api_editor.mutable_model.PythonEnum
@@ -169,7 +165,7 @@ private fun createSmlPythonNameAnnotationUse(name: String): SmlAnnotationUse {
169165
}
170166

171167
internal fun PythonParameter.toSmlParameterOrNull(): SmlParameter? {
172-
if (assignedBy !in setOf(POSITION_ONLY, POSITION_OR_NAME, ENUM, GROUP, NAME_ONLY)) {
168+
if (assignedBy == IMPLICIT) {
173169
return null
174170
}
175171

Diff for: server/src/main/kotlin/com/larsreimann/api_editor/model/packageData.kt

-4
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,6 @@ enum class PythonParameterAssignment {
207207
POSITION_ONLY,
208208
POSITION_OR_NAME,
209209
NAME_ONLY,
210-
ATTRIBUTE,
211-
CONSTANT,
212-
ENUM,
213-
GROUP
214210
}
215211

216212
@Serializable

Diff for: server/src/main/kotlin/com/larsreimann/api_editor/transformation/Postprocessor.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ private fun PythonFunction.reorderParameters() {
3737
this.parameters.addAll(groups[PythonParameterAssignment.POSITION_ONLY].orEmpty())
3838
this.parameters.addAll(groups[PythonParameterAssignment.POSITION_OR_NAME].orEmpty())
3939
this.parameters.addAll(groups[PythonParameterAssignment.NAME_ONLY].orEmpty())
40-
this.parameters.addAll(groups[PythonParameterAssignment.ATTRIBUTE].orEmpty())
41-
this.parameters.addAll(groups[PythonParameterAssignment.CONSTANT].orEmpty())
4240
}
4341

4442
/**
@@ -85,7 +83,7 @@ fun PythonPackage.createAttributesForParametersOfConstructor() {
8583
private fun PythonClass.createAttributesForParametersOfConstructor() {
8684
this.constructor
8785
?.parameters
88-
?.filter { it.assignedBy !in setOf(PythonParameterAssignment.IMPLICIT, PythonParameterAssignment.CONSTANT) }
86+
?.filter { it.assignedBy != PythonParameterAssignment.IMPLICIT }
8987
?.forEach {
9088
this.attributes += PythonAttribute(
9189
name = it.name,

Diff for: server/src/test/kotlin/com/larsreimann/api_editor/codegen/StubCodeGeneratorTest.kt

+3-31
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import org.junit.jupiter.api.Nested
4949
import org.junit.jupiter.api.Test
5050
import org.junit.jupiter.params.ParameterizedTest
5151
import org.junit.jupiter.params.provider.CsvSource
52-
import org.junit.jupiter.params.provider.EnumSource
5352

5453
class StubCodeGeneratorTest {
5554

@@ -321,14 +320,6 @@ class StubCodeGeneratorTest {
321320
PythonParameter(
322321
name = "nameOnly",
323322
assignedBy = PythonParameterAssignment.NAME_ONLY
324-
),
325-
PythonParameter(
326-
name = "attribute",
327-
assignedBy = PythonParameterAssignment.ATTRIBUTE
328-
),
329-
PythonParameter(
330-
name = "constant",
331-
assignedBy = PythonParameterAssignment.CONSTANT
332323
)
333324
)
334325
)
@@ -611,25 +602,9 @@ class StubCodeGeneratorTest {
611602
name = "positionOrName",
612603
assignedBy = PythonParameterAssignment.POSITION_OR_NAME
613604
),
614-
PythonParameter(
615-
name = "enum",
616-
assignedBy = PythonParameterAssignment.ENUM
617-
),
618-
PythonParameter(
619-
name = "group",
620-
assignedBy = PythonParameterAssignment.GROUP
621-
),
622605
PythonParameter(
623606
name = "nameOnly",
624607
assignedBy = PythonParameterAssignment.NAME_ONLY
625-
),
626-
PythonParameter(
627-
name = "attribute",
628-
assignedBy = PythonParameterAssignment.ATTRIBUTE
629-
),
630-
PythonParameter(
631-
name = "constant",
632-
assignedBy = PythonParameterAssignment.CONSTANT
633608
)
634609
)
635610
)
@@ -639,8 +614,6 @@ class StubCodeGeneratorTest {
639614
.shouldContainExactly(
640615
"positionOnly",
641616
"positionOrName",
642-
"enum",
643-
"group",
644617
"nameOnly"
645618
)
646619
}
@@ -665,12 +638,11 @@ class StubCodeGeneratorTest {
665638
@Nested
666639
inner class ToSmlParameter {
667640

668-
@ParameterizedTest
669-
@EnumSource(PythonParameterAssignment::class, names = ["IMPLICIT", "ATTRIBUTE", "CONSTANT"])
670-
fun `should return null for invisible parameters`(assignedBy: PythonParameterAssignment) {
641+
@Test
642+
fun `should return null for implicit parameters`() {
671643
val pythonParameter = PythonParameter(
672644
name = "testParameter",
673-
assignedBy = assignedBy
645+
assignedBy = PythonParameterAssignment.IMPLICIT
674646
)
675647

676648
pythonParameter.toSmlParameterOrNull().shouldBeNull()

Diff for: server/src/test/kotlin/com/larsreimann/api_editor/transformation/EnumAnnotationProcessorTest.kt

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.larsreimann.api_editor.transformation
22

33
import com.larsreimann.api_editor.model.EnumAnnotation
44
import com.larsreimann.api_editor.model.EnumPair
5-
import com.larsreimann.api_editor.model.PythonParameterAssignment
65
import com.larsreimann.api_editor.mutable_model.PythonArgument
76
import com.larsreimann.api_editor.mutable_model.PythonCall
87
import com.larsreimann.api_editor.mutable_model.PythonDeclaration

Diff for: server/src/test/kotlin/com/larsreimann/api_editor/transformation/PostprocessorTest.kt

+1-17
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ class PostprocessorTest {
5050
PythonParameter(
5151
name = "positionOrName",
5252
assignedBy = PythonParameterAssignment.POSITION_OR_NAME
53-
),
54-
PythonParameter(
55-
name = "constant",
56-
assignedBy = PythonParameterAssignment.CONSTANT
5753
)
5854
)
5955
),
@@ -126,18 +122,8 @@ class PostprocessorTest {
126122
name = "nameOnly",
127123
assignedBy = PythonParameterAssignment.NAME_ONLY
128124
)
129-
val attribute = PythonParameter(
130-
name = "attribute",
131-
assignedBy = PythonParameterAssignment.ATTRIBUTE
132-
)
133-
val constant = PythonParameter(
134-
name = "constant",
135-
assignedBy = PythonParameterAssignment.CONSTANT
136-
)
137125

138126
testFunction.parameters += listOf(
139-
constant,
140-
attribute,
141127
nameOnly,
142128
positionOrName,
143129
positionOnly,
@@ -151,9 +137,7 @@ class PostprocessorTest {
151137
implicit,
152138
positionOnly,
153139
positionOrName,
154-
nameOnly,
155-
attribute,
156-
constant
140+
nameOnly
157141
)
158142
)
159143
}

0 commit comments

Comments
 (0)