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

Commit cf83477

Browse files
authored
feat: @value annotation to replace @attribute, @constant, @optional, @required (#901)
* feat(parser): mostly finish updating parser schema * test(parser): update tests * feat(parser): fully migrate parser * feat(gui): migration from annotation store v1 to v2 * refactor(gui): upgrade annotation store in annotation slice to new version * refactor(gui): update most of the gui code * feat(gui): get everything running again (still needs testing) * fix(gui): update help button * fix(gui): run migration on import/startup * fix(gui): behavior of value form when changing type * feat(gui): improve tag for value annotation * fix(gui): allow selection of False and empty string * feat(gui)!: replace attribute annotation with optional on import * feat(gui): move value annotation to uncategorized section in dropdown * style: fix lint errors * style: fix lint errors * fix(backend): failing tests * style(backend): fix linter errors * style(backend): fix linter errors * style: apply automatic fixes of linters * fix: smoke tests * feat(gui): improve labels in value form * fix(gui): make boolean value required and fix initialization * feat(gui): polishing * style: apply automatic fixes of linters * chore(data): update annotation data * fix(gui): adding new annotations * refactor(gui): polishing * fix(gui): failing test * style: apply automatic fixes of linters * fix(backend): wrong main class * refactor(gui): rename a function * style(backend): use trailing commas * style: apply automatic fixes of linters Co-authored-by: lars-reimann <[email protected]>
1 parent 03272b1 commit cf83477

File tree

147 files changed

+31204
-29390
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+31204
-29390
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ insert_final_newline = true
1010

1111
[{*.yaml,*.yml}]
1212
indent_size = 2
13+
14+
[*.{kt,kts}]
15+
disabled_rules = filename
16+
ij_kotlin_allow_trailing_comma = true
17+
ij_kotlin_allow_trailing_comma_on_call_site = true

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
run: poetry run parse-package usages -p package_parser -c package_parser -o out
9393

9494
- name: Smoke test (annotations)
95-
run: poetry run parse-package annotations -a tests/data/removes/api_data.json -u tests/data/removes/usage_data.json -o out/annotations.json
95+
run: poetry run parse-package annotations -a tests/data/removeAnnotations/api_data.json -u tests/data/removeAnnotations/usage_data.json -o out/annotations.json
9696

9797
- name: Smoke test (all)
9898
run: poetry run parse-package all -p package_parser -s package_parser -c package_parser -o out

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ jobs:
138138
run: poetry run parse-package usages -p package_parser -c package_parser -o out
139139

140140
- name: Smoke test (annotations)
141-
run: poetry run parse-package annotations -a tests/data/removes/api_data.json -u tests/data/removes/usage_data.json -o out/annotations.json
141+
run: poetry run parse-package annotations -a tests/data/removeAnnotations/api_data.json -u tests/data/removeAnnotations/usage_data.json -o out/annotations.json
142142

143143
- name: Smoke test (all)
144144
run: poetry run parse-package all -p package_parser -s package_parser -c package_parser -o out

api-editor/backend/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ plugins {
1414
}
1515

1616
application {
17-
mainClass.set("com.larsreimann.api_editor.server.ApplicationKt")
17+
mainClass.set("com.larsreimann.apiEditor.server.ApplicationKt")
1818
}
1919

2020
java {
@@ -81,7 +81,7 @@ tasks {
8181
val winFileText = winScriptFile.readText()
8282
.replace(
8383
Regex("set CLASSPATH=.*"),
84-
"rem original CLASSPATH declaration replaced by:\nset CLASSPATH=%APP_HOME%\\\\lib\\\\*"
84+
"rem original CLASSPATH declaration replaced by:\nset CLASSPATH=%APP_HOME%\\\\lib\\\\*",
8585
)
8686

8787
winScriptFile.writeText(winFileText)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package com.larsreimann.api_editor.codegen
1+
package com.larsreimann.apiEditor.codegen
22

3-
import com.larsreimann.api_editor.mutable_model.PythonModule
4-
import com.larsreimann.api_editor.mutable_model.PythonPackage
3+
import com.larsreimann.apiEditor.mutableModel.PythonModule
4+
import com.larsreimann.apiEditor.mutableModel.PythonPackage
55
import com.larsreimann.safeds.constant.SdsFileExtension
66
import java.io.BufferedInputStream
77
import java.io.BufferedOutputStream
Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
package com.larsreimann.api_editor.codegen
2-
3-
import com.larsreimann.api_editor.model.Boundary
4-
import com.larsreimann.api_editor.model.ComparisonOperator.LESS_THAN
5-
import com.larsreimann.api_editor.model.ComparisonOperator.LESS_THAN_OR_EQUALS
6-
import com.larsreimann.api_editor.model.ComparisonOperator.UNRESTRICTED
7-
import com.larsreimann.api_editor.model.PythonParameterAssignment.IMPLICIT
8-
import com.larsreimann.api_editor.model.PythonParameterAssignment.NAMED_VARARG
9-
import com.larsreimann.api_editor.model.PythonParameterAssignment.NAME_ONLY
10-
import com.larsreimann.api_editor.model.PythonParameterAssignment.POSITIONAL_VARARG
11-
import com.larsreimann.api_editor.model.PythonParameterAssignment.POSITION_ONLY
12-
import com.larsreimann.api_editor.model.PythonParameterAssignment.POSITION_OR_NAME
13-
import com.larsreimann.api_editor.mutable_model.PythonArgument
14-
import com.larsreimann.api_editor.mutable_model.PythonAttribute
15-
import com.larsreimann.api_editor.mutable_model.PythonBoolean
16-
import com.larsreimann.api_editor.mutable_model.PythonCall
17-
import com.larsreimann.api_editor.mutable_model.PythonClass
18-
import com.larsreimann.api_editor.mutable_model.PythonConstructor
19-
import com.larsreimann.api_editor.mutable_model.PythonDeclaration
20-
import com.larsreimann.api_editor.mutable_model.PythonEnum
21-
import com.larsreimann.api_editor.mutable_model.PythonEnumInstance
22-
import com.larsreimann.api_editor.mutable_model.PythonExpression
23-
import com.larsreimann.api_editor.mutable_model.PythonFloat
24-
import com.larsreimann.api_editor.mutable_model.PythonFunction
25-
import com.larsreimann.api_editor.mutable_model.PythonInt
26-
import com.larsreimann.api_editor.mutable_model.PythonMemberAccess
27-
import com.larsreimann.api_editor.mutable_model.PythonModule
28-
import com.larsreimann.api_editor.mutable_model.PythonNamedSpread
29-
import com.larsreimann.api_editor.mutable_model.PythonNamedType
30-
import com.larsreimann.api_editor.mutable_model.PythonNone
31-
import com.larsreimann.api_editor.mutable_model.PythonParameter
32-
import com.larsreimann.api_editor.mutable_model.PythonPositionalSpread
33-
import com.larsreimann.api_editor.mutable_model.PythonReference
34-
import com.larsreimann.api_editor.mutable_model.PythonString
35-
import com.larsreimann.api_editor.mutable_model.PythonStringifiedExpression
36-
import com.larsreimann.api_editor.mutable_model.PythonStringifiedType
37-
import com.larsreimann.api_editor.mutable_model.PythonType
1+
package com.larsreimann.apiEditor.codegen
2+
3+
import com.larsreimann.apiEditor.model.Boundary
4+
import com.larsreimann.apiEditor.model.ComparisonOperator.LESS_THAN
5+
import com.larsreimann.apiEditor.model.ComparisonOperator.LESS_THAN_OR_EQUALS
6+
import com.larsreimann.apiEditor.model.ComparisonOperator.UNRESTRICTED
7+
import com.larsreimann.apiEditor.model.PythonParameterAssignment.IMPLICIT
8+
import com.larsreimann.apiEditor.model.PythonParameterAssignment.NAMED_VARARG
9+
import com.larsreimann.apiEditor.model.PythonParameterAssignment.NAME_ONLY
10+
import com.larsreimann.apiEditor.model.PythonParameterAssignment.POSITIONAL_VARARG
11+
import com.larsreimann.apiEditor.model.PythonParameterAssignment.POSITION_ONLY
12+
import com.larsreimann.apiEditor.model.PythonParameterAssignment.POSITION_OR_NAME
13+
import com.larsreimann.apiEditor.mutableModel.PythonArgument
14+
import com.larsreimann.apiEditor.mutableModel.PythonAttribute
15+
import com.larsreimann.apiEditor.mutableModel.PythonBoolean
16+
import com.larsreimann.apiEditor.mutableModel.PythonCall
17+
import com.larsreimann.apiEditor.mutableModel.PythonClass
18+
import com.larsreimann.apiEditor.mutableModel.PythonConstructor
19+
import com.larsreimann.apiEditor.mutableModel.PythonDeclaration
20+
import com.larsreimann.apiEditor.mutableModel.PythonEnum
21+
import com.larsreimann.apiEditor.mutableModel.PythonEnumInstance
22+
import com.larsreimann.apiEditor.mutableModel.PythonExpression
23+
import com.larsreimann.apiEditor.mutableModel.PythonFloat
24+
import com.larsreimann.apiEditor.mutableModel.PythonFunction
25+
import com.larsreimann.apiEditor.mutableModel.PythonInt
26+
import com.larsreimann.apiEditor.mutableModel.PythonMemberAccess
27+
import com.larsreimann.apiEditor.mutableModel.PythonModule
28+
import com.larsreimann.apiEditor.mutableModel.PythonNamedSpread
29+
import com.larsreimann.apiEditor.mutableModel.PythonNamedType
30+
import com.larsreimann.apiEditor.mutableModel.PythonNone
31+
import com.larsreimann.apiEditor.mutableModel.PythonParameter
32+
import com.larsreimann.apiEditor.mutableModel.PythonPositionalSpread
33+
import com.larsreimann.apiEditor.mutableModel.PythonReference
34+
import com.larsreimann.apiEditor.mutableModel.PythonString
35+
import com.larsreimann.apiEditor.mutableModel.PythonStringifiedExpression
36+
import com.larsreimann.apiEditor.mutableModel.PythonStringifiedType
37+
import com.larsreimann.apiEditor.mutableModel.PythonType
3838
import com.larsreimann.modeling.closest
3939
import com.larsreimann.modeling.descendants
4040

@@ -47,7 +47,7 @@ fun PythonModule.toPythonCode(): String {
4747
importsToPythonCode(),
4848
classes.joinToString("\n\n") { it.toPythonCode() },
4949
functions.joinToString("\n\n") { it.toPythonCode() },
50-
enums.joinToString("\n\n") { it.toPythonCode() }
50+
enums.joinToString("\n\n") { it.toPythonCode() },
5151
)
5252

5353
val joinedStrings = strings
@@ -59,7 +59,6 @@ fun PythonModule.toPythonCode(): String {
5959

6060
private fun PythonModule.importsToPythonCode() = buildString {
6161
val imports = buildSet<String> {
62-
6362
// Functions
6463
this += descendants { it !is PythonDeclaration }
6564
.filterIsInstance<PythonFunction>()
@@ -292,7 +291,7 @@ fun List<PythonParameter>.toPythonCode(): String {
292291
positionOrNameParametersString,
293292
positionalVarargParametersString,
294293
nameOnlyParametersString,
295-
namedVarargsParametersString
294+
namedVarargsParametersString,
296295
)
297296

298297
return parameterStrings
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package com.larsreimann.api_editor.codegen
1+
package com.larsreimann.apiEditor.codegen
22

3-
import com.larsreimann.api_editor.model.PythonParameterAssignment
4-
import com.larsreimann.api_editor.mutable_model.PythonAttribute
5-
import com.larsreimann.api_editor.mutable_model.PythonClass
6-
import com.larsreimann.api_editor.mutable_model.PythonFunction
7-
import com.larsreimann.api_editor.mutable_model.PythonParameter
3+
import com.larsreimann.apiEditor.model.PythonParameterAssignment
4+
import com.larsreimann.apiEditor.mutableModel.PythonAttribute
5+
import com.larsreimann.apiEditor.mutableModel.PythonClass
6+
import com.larsreimann.apiEditor.mutableModel.PythonFunction
7+
import com.larsreimann.apiEditor.mutableModel.PythonParameter
88

99
private fun attributesDocstring(attributes: List<PythonAttribute>) = buildString {
1010
if (attributes.all { it.description.isBlank() }) {
Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
package com.larsreimann.api_editor.codegen
2-
3-
import com.larsreimann.api_editor.model.PythonParameterAssignment.IMPLICIT
4-
import com.larsreimann.api_editor.mutable_model.PythonAttribute
5-
import com.larsreimann.api_editor.mutable_model.PythonClass
6-
import com.larsreimann.api_editor.mutable_model.PythonEnum
7-
import com.larsreimann.api_editor.mutable_model.PythonEnumInstance
8-
import com.larsreimann.api_editor.mutable_model.PythonExpression
9-
import com.larsreimann.api_editor.mutable_model.PythonFunction
10-
import com.larsreimann.api_editor.mutable_model.PythonModule
11-
import com.larsreimann.api_editor.mutable_model.PythonNamedType
12-
import com.larsreimann.api_editor.mutable_model.PythonParameter
13-
import com.larsreimann.api_editor.mutable_model.PythonResult
14-
import com.larsreimann.api_editor.mutable_model.PythonStringifiedExpression
15-
import com.larsreimann.api_editor.mutable_model.PythonStringifiedType
16-
import com.larsreimann.api_editor.mutable_model.PythonType
1+
package com.larsreimann.apiEditor.codegen
2+
3+
import com.larsreimann.apiEditor.model.PythonParameterAssignment.IMPLICIT
4+
import com.larsreimann.apiEditor.mutableModel.PythonAttribute
5+
import com.larsreimann.apiEditor.mutableModel.PythonClass
6+
import com.larsreimann.apiEditor.mutableModel.PythonEnum
7+
import com.larsreimann.apiEditor.mutableModel.PythonEnumInstance
8+
import com.larsreimann.apiEditor.mutableModel.PythonExpression
9+
import com.larsreimann.apiEditor.mutableModel.PythonFunction
10+
import com.larsreimann.apiEditor.mutableModel.PythonModule
11+
import com.larsreimann.apiEditor.mutableModel.PythonNamedType
12+
import com.larsreimann.apiEditor.mutableModel.PythonParameter
13+
import com.larsreimann.apiEditor.mutableModel.PythonResult
14+
import com.larsreimann.apiEditor.mutableModel.PythonStringifiedExpression
15+
import com.larsreimann.apiEditor.mutableModel.PythonStringifiedType
16+
import com.larsreimann.apiEditor.mutableModel.PythonType
1717
import com.larsreimann.safeds.constant.SdsFileExtension
1818
import com.larsreimann.safeds.emf.createSdsAnnotationCall
1919
import com.larsreimann.safeds.emf.createSdsArgument
@@ -56,7 +56,7 @@ fun PythonModule.toStubCode(): String {
5656
createSdsDummyResource(
5757
"compilationUnitStub",
5858
SdsFileExtension.Stub,
59-
compilationUnit
59+
compilationUnit,
6060
)
6161

6262
return when (val result = compilationUnit.serializeToFormattedString()) {
@@ -75,7 +75,7 @@ fun PythonModule.toSdsCompilationUnit(): SdsCompilationUnit {
7575

7676
return createSdsCompilationUnit(
7777
packageName = name,
78-
members = classes + functions + enums
78+
members = classes + functions + enums,
7979
)
8080
}
8181

@@ -99,7 +99,7 @@ fun PythonClass.toSdsClass(): SdsClass {
9999
}
100100
},
101101
parameters = buildConstructor(),
102-
members = attributes + methods
102+
members = attributes + methods,
103103
)
104104
}
105105

@@ -126,7 +126,7 @@ fun PythonAttribute.toSdsAttribute(): SdsAttribute {
126126
add(createSdsDescriptionAnnotationUse(description))
127127
}
128128
},
129-
type = type.toSdsType()
129+
type = type.toSdsType(),
130130
)
131131
}
132132

@@ -148,21 +148,21 @@ fun PythonFunction.toSdsFunction(): SdsFunction {
148148
}
149149
},
150150
parameters = parameters.mapNotNull { it.toSdsParameterOrNull() },
151-
results = results.map { it.toSdsResult() }
151+
results = results.map { it.toSdsResult() },
152152
)
153153
}
154154

155155
private fun createSdsDescriptionAnnotationUse(description: String): SdsAnnotationCall {
156156
return createSdsAnnotationCall(
157157
"Description",
158-
listOf(createSdsArgument(createSdsString(description)))
158+
listOf(createSdsArgument(createSdsString(description))),
159159
)
160160
}
161161

162162
private fun createSdsPythonNameAnnotationUse(name: String): SdsAnnotationCall {
163163
return createSdsAnnotationCall(
164164
"PythonName",
165-
listOf(createSdsArgument(createSdsString(name)))
165+
listOf(createSdsArgument(createSdsString(name))),
166166
)
167167
}
168168

@@ -184,7 +184,7 @@ fun PythonParameter.toSdsParameterOrNull(): SdsParameter? {
184184
}
185185
},
186186
type = type.toSdsType(),
187-
defaultValue = defaultValue?.toSdsExpression()
187+
defaultValue = defaultValue?.toSdsExpression(),
188188
)
189189
}
190190

@@ -201,7 +201,7 @@ fun PythonResult.toSdsResult(): SdsResult {
201201
add(createSdsDescriptionAnnotationUse(description))
202202
}
203203
},
204-
type = type.toSdsType()
204+
type = type.toSdsType(),
205205
)
206206
}
207207

@@ -240,7 +240,7 @@ fun PythonEnumInstance.toSdsEnumVariant(): SdsEnumVariant {
240240
if (description.isNotBlank()) {
241241
add(createSdsDescriptionAnnotationUse(description))
242242
}
243-
}
243+
},
244244
)
245245
}
246246

@@ -264,32 +264,32 @@ fun PythonType?.toSdsType(): SdsAbstractType {
264264
return when (this) {
265265
is PythonNamedType -> {
266266
createSdsNamedType(
267-
declaration = createSdsClass(this.declaration!!.name)
267+
declaration = createSdsClass(this.declaration!!.name),
268268
)
269269
}
270270
is PythonStringifiedType -> {
271271
when (this.string) {
272272
"bool" -> createSdsNamedType(
273-
declaration = createSdsClass("Boolean")
273+
declaration = createSdsClass("Boolean"),
274274
)
275275
"float" -> createSdsNamedType(
276-
declaration = createSdsClass("Float")
276+
declaration = createSdsClass("Float"),
277277
)
278278
"int" -> createSdsNamedType(
279-
declaration = createSdsClass("Int")
279+
declaration = createSdsClass("Int"),
280280
)
281281
"str" -> createSdsNamedType(
282-
declaration = createSdsClass("String")
282+
declaration = createSdsClass("String"),
283283
)
284284
else -> createSdsNamedType(
285285
declaration = createSdsClass("Any"),
286-
isNullable = true
286+
isNullable = true,
287287
)
288288
}
289289
}
290290
null -> createSdsNamedType(
291291
declaration = createSdsClass("Any"),
292-
isNullable = true
292+
isNullable = true,
293293
)
294294
}
295295
}

api-editor/backend/src/main/kotlin/com/larsreimann/api_editor/codegen/Util.kt renamed to api-editor/backend/src/main/kotlin/com/larsreimann/apiEditor/codegen/Util.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.larsreimann.api_editor.codegen
1+
package com.larsreimann.apiEditor.codegen
22

33
internal fun String.prependIndentUnlessBlank(indent: String = " "): String {
44
return lineSequence()

0 commit comments

Comments
 (0)