Skip to content

Commit adddba8

Browse files
committed
properties can be optional
1 parent 0ca7ea5 commit adddba8

File tree

6 files changed

+12
-7
lines changed

6 files changed

+12
-7
lines changed

metamodel-generator/src/main/kotlin/org/modelix/metamodel/generator/MetaModelGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class MetaModelGenerator(val outputDir: Path) {
172172
when (val data = feature.data) {
173173
is PropertyData -> {
174174
addProperty(PropertySpec.builder(feature.validName, IProperty::class)
175-
.initializer("""${GeneratedConcept<*, *>::newProperty.name}("${feature.originalName}")""")
175+
.initializer("""${GeneratedConcept<*, *>::newProperty.name}("${feature.originalName}", ${data.optional})""")
176176
.build())
177177
}
178178
is ChildLinkData -> {

metamodel-runtime/src/commonMain/kotlin/org/modelix/metamodel/GeneratedConcept.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ abstract class GeneratedConcept<InstanceT : ITypedNode, WrapperT : ITypedConcept
1919
return is_abstract
2020
}
2121

22-
fun newProperty(name: String): GeneratedProperty {
23-
return GeneratedProperty(this, name).also {
22+
fun newProperty(name: String, optional: Boolean = true): GeneratedProperty {
23+
return GeneratedProperty(this, name, optional).also {
2424
propertiesMap[name] = it
2525
}
2626
}
@@ -118,7 +118,11 @@ abstract class GeneratedConcept<InstanceT : ITypedNode, WrapperT : ITypedConcept
118118
}
119119
}
120120

121-
class GeneratedProperty(private val owner: IConcept, override val name: String) : IProperty {
121+
class GeneratedProperty(
122+
private val owner: IConcept,
123+
override val name: String,
124+
override val isOptional: Boolean
125+
) : IProperty {
122126
override fun getConcept(): IConcept = owner
123127
override fun getUID(): String = getConcept().getUID() + "." + name
124128
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.modelix.model.api
22

33
interface ILink : IRole {
4-
val isOptional: Boolean
54
val targetConcept: IConcept
65
}

model-api/src/commonMain/kotlin/org/modelix/model/api/IRole.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ interface IRole {
44
fun getConcept(): IConcept
55
fun getUID(): String
66
val name: String
7+
val isOptional: Boolean
78
}

model-api/src/commonMain/kotlin/org/modelix/model/api/SimpleProperty.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
package org.modelix.model.api
1515

16-
class SimpleProperty(override val name: String) : IProperty {
16+
class SimpleProperty(override val name: String, override val isOptional: Boolean = true) : IProperty {
1717
var owner: SimpleConcept? = null
1818

1919
override fun getConcept(): IConcept = owner!!

model-api/src/commonMain/kotlin/org/modelix/model/data/MetaModelData.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ sealed interface IConceptFeatureData {
4343
data class PropertyData (
4444
override val uid: String? = null,
4545
override val name: String,
46-
val type: PropertyType = PropertyType.STRING
46+
val type: PropertyType = PropertyType.STRING,
47+
val optional: Boolean = true
4748
) : IConceptFeatureData
4849

4950
enum class PropertyType {

0 commit comments

Comments
 (0)