Skip to content

Commit 75dd4cd

Browse files
committed
IDs of properties/links were not generated for the typed API
1 parent 024cac7 commit 75dd4cd

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,21 @@ class MetaModelGenerator(val outputDir: Path) {
190190
}
191191
}).asTypeName()
192192
addProperty(PropertySpec.builder(feature.validName, GeneratedProperty::class.asClassName().parameterizedBy(data.asKotlinType()))
193-
.initializer("""newProperty(%S, %T, ${data.optional})""", feature.originalName, serializer)
193+
.initializer(
194+
"""newProperty(%S, %S, %T, ${data.optional})""",
195+
feature.originalName,
196+
data.uid,
197+
serializer
198+
)
194199
.build())
195200
}
196201
is ChildLinkData -> {
197202
val methodName = if (data.multiple) "newChildListLink" else "newSingleChildLink"
198203
addProperty(PropertySpec.builder(feature.validName, feature.generatedChildLinkType())
199204
.initializer(
200-
"""$methodName(%S, ${data.optional}, %T, %T::class)""",
205+
"""$methodName(%S, %S, ${data.optional}, %T, %T::class)""",
201206
feature.originalName,
207+
data.uid,
202208
data.type.conceptObjectName().parseClassName(),
203209
data.type.nodeWrapperInterfaceName().parseClassName()
204210
)
@@ -207,8 +213,9 @@ class MetaModelGenerator(val outputDir: Path) {
207213
is ReferenceLinkData -> {
208214
addProperty(PropertySpec.builder(feature.validName, feature.generatedReferenceLinkType())
209215
.initializer(
210-
"""newReferenceLink(%S, ${data.optional}, %T, %T::class)""",
216+
"""newReferenceLink(%S, %S, ${data.optional}, %T, %T::class)""",
211217
feature.originalName,
218+
data.uid,
212219
data.type.conceptObjectName().parseClassName(),
213220
data.type.nodeWrapperInterfaceName().parseClassName()
214221
)

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,23 @@ abstract class GeneratedConcept<NodeT : ITypedNode, ConceptT : ITypedConcept>(
2121
return is_abstract
2222
}
2323

24-
fun <ValueT> newProperty(name: String, serializer: IPropertyValueSerializer<ValueT>, optional: Boolean): GeneratedProperty<ValueT> {
25-
return GeneratedProperty(this, name, optional, serializer).also {
24+
fun <ValueT> newProperty(name: String, uid: String?, serializer: IPropertyValueSerializer<ValueT>, optional: Boolean): GeneratedProperty<ValueT> {
25+
return GeneratedProperty(this, name, uid, optional, serializer).also {
2626
propertiesMap[name] = it
2727
}
2828
}
2929

3030
fun <ChildNodeT : ITypedNode, ChildConceptT : ITypedConcept> newSingleChildLink(
3131
name: String,
32+
uid: String?,
3233
isOptional: Boolean,
3334
targetConcept: IConcept,
3435
childNodeInterface: KClass<ChildNodeT>
3536
): GeneratedSingleChildLink<ChildNodeT, ChildConceptT> {
3637
return GeneratedSingleChildLink<ChildNodeT, ChildConceptT>(
3738
this,
3839
name,
40+
uid,
3941
isOptional,
4042
targetConcept,
4143
childNodeInterface
@@ -46,13 +48,15 @@ abstract class GeneratedConcept<NodeT : ITypedNode, ConceptT : ITypedConcept>(
4648

4749
fun <ChildNodeT : ITypedNode, ChildConceptT : ITypedConcept> newChildListLink(
4850
name: String,
51+
uid: String?,
4952
isOptional: Boolean,
5053
targetConcept: IConcept,
5154
childNodeInterface: KClass<ChildNodeT>
5255
): GeneratedChildListLink<ChildNodeT, ChildConceptT> {
5356
return GeneratedChildListLink<ChildNodeT, ChildConceptT>(
5457
this,
5558
name,
59+
uid,
5660
isOptional,
5761
targetConcept,
5862
childNodeInterface
@@ -63,13 +67,15 @@ abstract class GeneratedConcept<NodeT : ITypedNode, ConceptT : ITypedConcept>(
6367

6468
fun <TargetNodeT : ITypedNode, TargetConceptT : ITypedConcept> newReferenceLink(
6569
name: String,
70+
uid: String?,
6671
isOptional: Boolean,
6772
targetConcept: IConcept,
6873
targetNodeInterface: KClass<TargetNodeT>
6974
): GeneratedReferenceLink<TargetNodeT, TargetConceptT> {
7075
return GeneratedReferenceLink<TargetNodeT, TargetConceptT>(
7176
this,
7277
name,
78+
uid,
7379
isOptional,
7480
targetConcept,
7581
targetNodeInterface
@@ -114,6 +120,7 @@ abstract class GeneratedConcept<NodeT : ITypedNode, ConceptT : ITypedConcept>(
114120
}
115121

116122
override fun getUID(): String {
123+
// This method is overridden if the concept specifies a UID
117124
return UID_PREFIX + getLongName()
118125
}
119126

@@ -156,11 +163,12 @@ abstract class GeneratedConcept<NodeT : ITypedNode, ConceptT : ITypedConcept>(
156163
class GeneratedProperty<ValueT>(
157164
private val owner: IConcept,
158165
override val name: String,
166+
private val uid: String?,
159167
override val isOptional: Boolean,
160168
private val serializer: IPropertyValueSerializer<ValueT>
161169
) : ITypedProperty<ValueT>, IProperty {
162170
override fun getConcept(): IConcept = owner
163-
override fun getUID(): String = getConcept().getUID() + "." + name
171+
override fun getUID(): String = uid ?: (getConcept().getUID() + "." + name)
164172
override fun untyped(): IProperty = this
165173

166174
override fun serializeValue(value: ValueT): String? = serializer.serialize(value)
@@ -172,6 +180,7 @@ fun IProperty.typed() = this as? ITypedProperty<*>
172180
abstract class GeneratedChildLink<ChildNodeT : ITypedNode, ChildConceptT : ITypedConcept>(
173181
private val owner: IConcept,
174182
override val name: String,
183+
private val uid: String?,
175184
override val isMultiple: Boolean,
176185
override val isOptional: Boolean,
177186
override val targetConcept: IConcept,
@@ -182,7 +191,7 @@ abstract class GeneratedChildLink<ChildNodeT : ITypedNode, ChildConceptT : IType
182191

183192
override fun getConcept(): IConcept = owner
184193

185-
override fun getUID(): String = getConcept().getUID() + "." + name
194+
override fun getUID(): String = uid ?: (getConcept().getUID() + "." + name)
186195

187196
override fun untyped(): IChildLink {
188197
return this
@@ -197,34 +206,37 @@ fun IChildLink.typed() = this as? ITypedChildLink<ITypedNode>
197206
class GeneratedSingleChildLink<ChildNodeT : ITypedNode, ChildConceptT : ITypedConcept>(
198207
owner: IConcept,
199208
name: String,
209+
uid: String?,
200210
isOptional: Boolean,
201211
targetConcept: IConcept,
202212
childNodeInterface: KClass<ChildNodeT>
203-
) : GeneratedChildLink<ChildNodeT, ChildConceptT>(owner, name, false, isOptional, targetConcept, childNodeInterface), ITypedSingleChildLink<ChildNodeT> {
213+
) : GeneratedChildLink<ChildNodeT, ChildConceptT>(owner, name, uid, false, isOptional, targetConcept, childNodeInterface), ITypedSingleChildLink<ChildNodeT> {
204214

205215
}
206216

207217
class GeneratedChildListLink<ChildNodeT : ITypedNode, ChildConceptT : ITypedConcept>(
208218
owner: IConcept,
209219
name: String,
220+
uid: String?,
210221
isOptional: Boolean,
211222
targetConcept: IConcept,
212223
childNodeInterface: KClass<ChildNodeT>
213-
) : GeneratedChildLink<ChildNodeT, ChildConceptT>(owner, name, true, isOptional, targetConcept, childNodeInterface), ITypedChildListLink<ChildNodeT> {
224+
) : GeneratedChildLink<ChildNodeT, ChildConceptT>(owner, name, uid, true, isOptional, targetConcept, childNodeInterface), ITypedChildListLink<ChildNodeT> {
214225

215226
}
216227

217228
class GeneratedReferenceLink<TargetNodeT : ITypedNode, TargetConceptT : ITypedConcept>(
218229
private val owner: IConcept,
219230
override val name: String,
231+
private val uid: String?,
220232
override val isOptional: Boolean,
221233
override val targetConcept: IConcept,
222234
private val targetNodeInterface: KClass<TargetNodeT>
223235
) : IReferenceLink, ITypedReferenceLink<TargetNodeT> {
224236

225237
override fun getConcept(): IConcept = owner
226238

227-
override fun getUID(): String = getConcept().getUID() + "." + name
239+
override fun getUID(): String = uid ?: (getConcept().getUID() + "." + name)
228240

229241
override fun untyped(): IReferenceLink = this
230242

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ interface INode {
5151
fun getReferenceRoles(): List<String>
5252
}
5353

54-
private fun IRole.key(): String = name
54+
private fun IRole.key(): String = name // TODO use .getUID(), but this is a breaking change
5555
fun INode.getChildren(link: IChildLink): Iterable<INode> = getChildren(link.key())
5656
fun INode.moveChild(role: IChildLink, index: Int, child: INode): Unit = moveChild(role.key(), index, child)
5757
fun INode.addNewChild(role: IChildLink, index: Int, concept: IConcept?) = addNewChild(role.key(), index, concept)

0 commit comments

Comments
 (0)