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
Show all changes
33 commits
Select commit Hold shift + click to select a range
156b533
fix: various issues with Python codegen
lars-reimann Jan 10, 2022
7fc66bd
test: additional tests for Python codegen
lars-reimann Jan 10, 2022
204a2ce
fix: Python codegen of Booleans
lars-reimann Jan 10, 2022
7b0fc8c
fix: wrong member access for parameter objects
lars-reimann Jan 10, 2022
3d43bfb
refactor: classes for types
lars-reimann Jan 10, 2022
cad26b0
feat: create type hints
lars-reimann Jan 10, 2022
b6d8757
fix: reorder parameters of constructors
lars-reimann Jan 10, 2022
bf11b35
fix: usage of CrossReference vs. ContainmentReference
lars-reimann Jan 10, 2022
b3d3ce8
refactor: replace strings in model with richer types
lars-reimann Jan 10, 2022
579973b
fix: missing conversion of value
lars-reimann Jan 10, 2022
7edc94d
test: Python codegen for attributes
lars-reimann Jan 10, 2022
4116bce
test: Python codegen for constructors
lars-reimann Jan 10, 2022
105e7bf
test: Python codegen for functions
lars-reimann Jan 10, 2022
4eb581b
test: Python codegen for boundaries
lars-reimann Jan 10, 2022
e0024ad
test: Python codegen for parameter lists
lars-reimann Jan 10, 2022
f456820
test: Python codegen for classes
lars-reimann Jan 10, 2022
ebb08b6
test: Python codegen for modules
lars-reimann Jan 10, 2022
833c65d
feat: `from __future__ import annotations`
lars-reimann Jan 10, 2022
b098904
style: apply automatic fixes of linters
lars-reimann Jan 10, 2022
8c89ef4
add function tests and layout for constructor tests
paul0314 Jan 10, 2022
ec0917b
fix: indented blank lines
lars-reimann Jan 11, 2022
6e38af5
fix: forbid combinations enum+attribute and enum+optional
lars-reimann Jan 11, 2022
0f0b36b
feat: use f-strings instead of format calls
lars-reimann Jan 11, 2022
4aeb030
fix: missing imports for static methods and constructors
lars-reimann Jan 11, 2022
fbdb741
add self parameter to constructor tests
paul0314 Jan 11, 2022
d6d34c1
fix: disable combination attribute+boundary
lars-reimann Jan 11, 2022
18e8aac
fix: ConcurrentModificationException when processing group annotation…
lars-reimann Jan 11, 2022
e8aaf96
fix: failing test
lars-reimann Jan 12, 2022
ba25423
Merge remote-tracking branch 'origin/fix/pyCodegen' into test/pyCodegen
paul0314 Jan 12, 2022
d9505aa
add method and constructor tests
paul0314 Jan 12, 2022
6c29990
add tests for move / rename annotation
paul0314 Jan 12, 2022
6d4a665
update one outdated test case
paul0314 Jan 12, 2022
e4ab599
fix: combination of group and rename annotations
lars-reimann Jan 13, 2022
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import com.larsreimann.api_editor.mutable_model.PythonAttribute
import com.larsreimann.api_editor.mutable_model.PythonClass
import com.larsreimann.api_editor.mutable_model.PythonEnum
import com.larsreimann.api_editor.mutable_model.PythonEnumInstance
import com.larsreimann.api_editor.mutable_model.PythonExpression
import com.larsreimann.api_editor.mutable_model.PythonFunction
import com.larsreimann.api_editor.mutable_model.PythonModule
import com.larsreimann.api_editor.mutable_model.PythonNamedType
import com.larsreimann.api_editor.mutable_model.PythonParameter
import com.larsreimann.api_editor.mutable_model.PythonResult
import com.larsreimann.api_editor.mutable_model.PythonStringifiedExpression
import com.larsreimann.api_editor.mutable_model.PythonStringifiedType
import com.larsreimann.api_editor.mutable_model.PythonType
import de.unibonn.simpleml.constant.SmlFileExtension
import de.unibonn.simpleml.emf.createSmlAnnotationUse
import de.unibonn.simpleml.emf.createSmlArgument
Expand Down Expand Up @@ -124,7 +129,7 @@ internal fun PythonAttribute.toSmlAttribute(): SmlAttribute {
add(createSmlDescriptionAnnotationUse(description))
}
},
type = typeInDocs.toSmlType()
type = type.toSmlType()
)
}

Expand Down Expand Up @@ -181,7 +186,7 @@ internal fun PythonParameter.toSmlParameterOrNull(): SmlParameter? {
add(createSmlDescriptionAnnotationUse(description))
}
},
type = typeInDocs.toSmlType(),
type = type.toSmlType(),
defaultValue = defaultValue?.toSmlExpression()
)
}
Expand Down Expand Up @@ -258,21 +263,34 @@ private fun String.snakeCaseToCamelCase(): String {

// Type conversions ----------------------------------------------------------------------------------------------------

internal fun String.toSmlType(): SmlAbstractType {
internal fun PythonType?.toSmlType(): SmlAbstractType {
return when (this) {
"bool" -> createSmlNamedType(
declaration = createSmlClass("Boolean")
)
"float" -> createSmlNamedType(
declaration = createSmlClass("Float")
)
"int" -> createSmlNamedType(
declaration = createSmlClass("Int")
)
"str" -> createSmlNamedType(
declaration = createSmlClass("String")
)
else -> createSmlNamedType(
is PythonNamedType -> {
createSmlNamedType(
declaration = createSmlClass(this.declaration!!.name)
)
}
is PythonStringifiedType -> {
when (this.string) {
"bool" -> createSmlNamedType(
declaration = createSmlClass("Boolean")
)
"float" -> createSmlNamedType(
declaration = createSmlClass("Float")
)
"int" -> createSmlNamedType(
declaration = createSmlClass("Int")
)
"str" -> createSmlNamedType(
declaration = createSmlClass("String")
)
else -> createSmlNamedType(
declaration = createSmlClass("Any"),
isNullable = true
)
}
}
null -> createSmlNamedType(
declaration = createSmlClass("Any"),
isNullable = true
)
Expand All @@ -281,16 +299,20 @@ internal fun String.toSmlType(): SmlAbstractType {

// Value conversions ---------------------------------------------------------------------------------------------------

internal fun String.toSmlExpression(): SmlAbstractExpression? {
internal fun PythonExpression.toSmlExpression(): SmlAbstractExpression? {
if (this !is PythonStringifiedExpression) {
return createSmlString("###invalid###$this###")
}

return when {
isBlank() -> null
this == "False" -> createSmlBoolean(false)
this == "True" -> createSmlBoolean(true)
this == "None" -> createSmlNull()
isIntLiteral() -> createSmlInt(toInt())
isFloatLiteral() -> createSmlFloat(toDouble())
isStringLiteral() -> createSmlString(substring(1, length - 1))
else -> createSmlString("###invalid###$this###")
string.isBlank() -> null
string == "False" -> createSmlBoolean(false)
string == "True" -> createSmlBoolean(true)
string == "None" -> createSmlNull()
string.isIntLiteral() -> createSmlInt(string.toInt())
string.isFloatLiteral() -> createSmlFloat(string.toDouble())
string.isStringLiteral() -> createSmlString(string.substring(1, string.length - 1))
else -> createSmlString("###invalid###$string###")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ data class EnumAnnotation(val enumName: String, val pairs: List<EnumPair>) : Edi
data class EnumPair(val stringValue: String, val instanceName: String)

@Serializable
data class GroupAnnotation(val groupName: String, val parameters: List<String>) : EditorAnnotation() {
data class GroupAnnotation(val groupName: String, val parameters: MutableList<String>) : EditorAnnotation() {

@Transient
override val validTargets = FUNCTIONS
Expand Down Expand Up @@ -129,14 +129,14 @@ sealed class DefaultValue
@Serializable
class DefaultBoolean(val value: Boolean) : DefaultValue() {
override fun toString(): String {
return "$value"
return value.toString().replaceFirstChar { it.uppercase() }
}
}

@Serializable
class DefaultNumber(val value: Double) : DefaultValue() {
override fun toString(): String {
return "$value"
return value.toString()
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ fun convertClass(pythonClass: SerializablePythonClass): PythonClass {
return PythonClass(
name = pythonClass.name,
decorators = pythonClass.decorators.toMutableList(),
superclasses = pythonClass.superclasses.toMutableList(),
superclasses = pythonClass.superclasses.map { PythonNamedType(PythonClass(name = it)) }.toMutableList(),
attributes = pythonClass.attributes.map { convertAttribute(it) },
methods = pythonClass.methods.map { convertFunction(it) },
isPublic = pythonClass.isPublic,
description = pythonClass.description,
fullDocstring = pythonClass.fullDocstring,
annotations = pythonClass.annotations
)
}
Expand All @@ -57,7 +56,7 @@ fun convertEnum(pythonEnum: SerializablePythonEnum): PythonEnum {
fun convertEnumInstance(pythonEnumInstance: SerializablePythonEnumInstance): PythonEnumInstance {
return PythonEnumInstance(
name = pythonEnumInstance.name,
value = pythonEnumInstance.value,
value = PythonStringifiedExpression(pythonEnumInstance.value),
description = pythonEnumInstance.description,
annotations = mutableListOf()
)
Expand All @@ -71,8 +70,6 @@ fun convertFunction(pythonFunction: SerializablePythonFunction): PythonFunction
results = pythonFunction.results.map { convertResult(it) },
isPublic = pythonFunction.isPublic,
description = pythonFunction.description,
fullDocstring = pythonFunction.fullDocstring,
// calledAfter = pythonFunction.calledAfter,
isPure = pythonFunction.isPure,
annotations = pythonFunction.annotations,
)
Expand All @@ -81,9 +78,9 @@ fun convertFunction(pythonFunction: SerializablePythonFunction): PythonFunction
fun convertAttribute(pythonAttribute: SerializablePythonAttribute): PythonAttribute {
return PythonAttribute(
name = pythonAttribute.name,
value = pythonAttribute.defaultValue,
type = PythonStringifiedType(pythonAttribute.typeInDocs),
value = pythonAttribute.defaultValue?.let { PythonStringifiedExpression(it) },
isPublic = pythonAttribute.isPublic,
typeInDocs = pythonAttribute.typeInDocs,
description = pythonAttribute.description,
boundary = pythonAttribute.boundary,
annotations = pythonAttribute.annotations,
Expand All @@ -93,9 +90,9 @@ fun convertAttribute(pythonAttribute: SerializablePythonAttribute): PythonAttrib
fun convertParameter(pythonParameter: SerializablePythonParameter): PythonParameter {
return PythonParameter(
name = pythonParameter.name,
defaultValue = pythonParameter.defaultValue,
type = PythonStringifiedType(pythonParameter.typeInDocs),
defaultValue = pythonParameter.defaultValue?.let { PythonStringifiedExpression(it) },
assignedBy = pythonParameter.assignedBy,
typeInDocs = pythonParameter.typeInDocs,
description = pythonParameter.description,
boundary = pythonParameter.boundary,
annotations = pythonParameter.annotations,
Expand All @@ -105,8 +102,7 @@ fun convertParameter(pythonParameter: SerializablePythonParameter): PythonParame
fun convertResult(pythonResult: SerializablePythonResult): PythonResult {
return PythonResult(
name = pythonResult.name,
type = pythonResult.type,
typeInDocs = pythonResult.typeInDocs,
type = PythonStringifiedType(pythonResult.type),
description = pythonResult.description,
boundary = pythonResult.boundary,
annotations = pythonResult.annotations,
Expand Down
Loading