Skip to content

Commit 475547e

Browse files
author
Oleksandr Dzhychko
committed
fix(model-api): add children eagerly to concepts for builtin languages
Previously, the child links were only added lazily by delegates or not at all. This resulted in returning incomplete lists of child links.
1 parent 2a5641d commit 475547e

File tree

2 files changed

+36
-47
lines changed

2 files changed

+36
-47
lines changed

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

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.modelix.model.api
1818

19-
import kotlin.reflect.KProperty
20-
2119
/**
2220
* TODO if you add a new Concept to a language, do not forget to add it to the language's included concepts field.
2321
* Otherwise the concept will not be eagerly added to the Language, when registering the language in the ILanguageRegistry.
@@ -43,8 +41,13 @@ object BuiltinLanguages {
4341
uid = "ceab5195-25ea-4f22-9b92-103b95ca8c0c/1133920641626/1193676396447",
4442
).also(this::addProperty)
4543

46-
val smodelAttribute by childLink("ceab5195-25ea-4f22-9b92-103b95ca8c0c/1133920641626/5169995583184591170").multiple()
47-
.optional().type { Attribute }
44+
val smodelAttribute = SimpleChildLink(
45+
simpleName = "smodelAttribute",
46+
isMultiple = true,
47+
isOptional = true,
48+
targetConcept = Attribute,
49+
uid = "ceab5195-25ea-4f22-9b92-103b95ca8c0c/1133920641626/5169995583184591170",
50+
).also(this::addChildLink)
4851
}
4952

5053
object Attribute : SimpleConcept(
@@ -111,21 +114,23 @@ object BuiltinLanguages {
111114
isOptional = true,
112115
targetConcept = jetbrains_mps_lang_core.BaseConcept,
113116
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/474657388638618892/474657388638618900",
114-
)
117+
).also(this::addChildLink)
118+
115119
val modelImports = SimpleChildLink(
116120
simpleName = "modelImports",
117121
isMultiple = true,
118122
isOptional = true,
119123
targetConcept = ModelReference,
120124
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/474657388638618892/6402965165736931000",
121-
)
125+
).also(this::addChildLink)
126+
122127
val usedLanguages = SimpleChildLink(
123128
simpleName = "usedLanguages",
124129
isMultiple = true,
125130
isOptional = true,
126131
targetConcept = SingleLanguageDependency,
127132
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/474657388638618892/5381564949800872334",
128-
)
133+
).also(this::addChildLink)
129134
}
130135

131136
object Module : SimpleConcept(
@@ -156,28 +161,31 @@ object BuiltinLanguages {
156161
isOptional = true,
157162
targetConcept = Model,
158163
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/474657388638618895/474657388638618898",
159-
)
164+
).also(this::addChildLink)
165+
160166
val facets = SimpleChildLink(
161167
simpleName = "facets",
162168
isMultiple = true,
163169
isOptional = true,
164170
targetConcept = ModuleFacet,
165171
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/474657388638618895/2206727074858242412",
166-
)
172+
).also(this::addChildLink)
173+
167174
val dependencies = SimpleChildLink(
168175
simpleName = "dependencies",
169176
isMultiple = true,
170177
isOptional = true,
171178
targetConcept = ModuleDependency,
172179
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/474657388638618895/2206727074858242425",
173-
)
180+
).also(this::addChildLink)
181+
174182
val languageDependencies = SimpleChildLink(
175183
simpleName = "languageDependencies",
176184
isMultiple = true,
177185
isOptional = true,
178186
targetConcept = LanguageDependency,
179187
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/474657388638618895/2206727074858242439",
180-
)
188+
).also(this::addChildLink)
181189
}
182190

183191
object Solution : SimpleConcept(
@@ -217,23 +225,23 @@ object BuiltinLanguages {
217225
isOptional = true,
218226
targetConcept = Module,
219227
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/474657388638618902/474657388638618903",
220-
)
228+
).also(this::addChildLink)
221229

222230
val projects = SimpleChildLink(
223231
simpleName = "projects",
224232
isMultiple = true,
225233
isOptional = true,
226234
targetConcept = Project,
227235
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/474657388638618902/7064605579395546636",
228-
)
236+
).also(this::addChildLink)
229237

230238
val tempModules = SimpleChildLink(
231239
simpleName = "tempModules",
232240
isMultiple = true,
233241
isOptional = true,
234242
targetConcept = Module,
235243
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/474657388638618902/8226136427470548682",
236-
)
244+
).also(this::addChildLink)
237245
}
238246

239247
object Project : SimpleConcept(
@@ -249,15 +257,15 @@ object BuiltinLanguages {
249257
isOptional = true,
250258
targetConcept = Module,
251259
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/4008363636171860313/4008363636171860450",
252-
)
260+
).also(this::addChildLink)
253261

254262
val projectModules = SimpleChildLink(
255263
simpleName = "projectModules",
256264
isMultiple = true,
257265
isOptional = true,
258266
targetConcept = ProjectModule,
259267
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/4008363636171860313/4201834143491306088",
260-
)
268+
).also(this::addChildLink)
261269
}
262270

263271
object ProjectModule : SimpleConcept(
@@ -426,7 +434,7 @@ object BuiltinLanguages {
426434
isOptional = true,
427435
targetConcept = RepositoryInfo,
428436
uid = "b6980ebd-f01d-459d-a952-38740f6313b4/7113393488488348863/7113393488488348866",
429-
)
437+
).also(this::addChildLink)
430438
}
431439

432440
object RepositoryInfo : SimpleConcept(
@@ -447,7 +455,7 @@ object BuiltinLanguages {
447455
isOptional = true,
448456
targetConcept = BranchInfo,
449457
uid = "b6980ebd-f01d-459d-a952-38740f6313b4/7113393488488348864/7113393488488348868",
450-
)
458+
).also(this::addChildLink)
451459
}
452460

453461
object BranchInfo : SimpleConcept(
@@ -465,32 +473,3 @@ object BuiltinLanguages {
465473
ModelixRuntimelang,
466474
)
467475
}
468-
469-
private fun SimpleConcept.childLink(uid: String) = object {
470-
private lateinit var name: String
471-
private lateinit var owner: SimpleConcept
472-
private var multiple: Boolean = true
473-
private var optional: Boolean = true
474-
private lateinit var targetConcept: () -> IConcept
475-
private val instance: IChildLink by lazy {
476-
SimpleChildLink(
477-
simpleName = name,
478-
uid = uid,
479-
isMultiple = multiple,
480-
isOptional = optional,
481-
targetConcept = targetConcept(),
482-
).also { owner.addChildLink(it) }
483-
}
484-
485-
operator fun getValue(ownerConcept: SimpleConcept, kotlinProperty: KProperty<*>): IChildLink {
486-
this.owner = ownerConcept
487-
this.name = kotlinProperty.name
488-
return instance
489-
}
490-
491-
fun mandatory() = this.also { this.optional = false }
492-
fun optional() = this.also { this.optional = true }
493-
fun single() = this.also { this.multiple = false }
494-
fun multiple() = this.also { this.multiple = true }
495-
fun type(targetConcept: () -> IConcept) = also { this.targetConcept = targetConcept }
496-
}

model-api/src/commonTest/kotlin/org/modelix/model/api/BuiltinLanguagesTest.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,14 @@ class BuiltinLanguagesTest {
3131
// Model.stereotype was accessed once directly.
3232
assertEquals(4, properties.size)
3333
}
34+
35+
@Test
36+
fun allChildrenAreListed() {
37+
val childLinks = BuiltinLanguages.MPSRepositoryConcepts.Model.getOwnChildLinks()
38+
39+
// This trivial assertion is relevant
40+
// because previously, children were not listed at all in Model.getOwnChildLinks().
41+
// They were only accessible by directly calling Model.modelImports for example.
42+
assertEquals(3, childLinks.size)
43+
}
3444
}

0 commit comments

Comments
 (0)