Skip to content

Commit 2a5641d

Browse files
author
Oleksandr Dzhychko
committed
fix(model-api): add properties eagerly to concepts for builtin languages
Using delegates resulted in adding the properties only once they were accessed. Querying properties before directly accessing them resulted in an incomplete properties list.
1 parent ac992fe commit 2a5641d

File tree

2 files changed

+125
-34
lines changed

2 files changed

+125
-34
lines changed

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

Lines changed: 91 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ object BuiltinLanguages {
3838
addConcept(this)
3939
}
4040

41-
val virtualPackage by property("ceab5195-25ea-4f22-9b92-103b95ca8c0c/1133920641626/1193676396447")
41+
val virtualPackage = SimpleProperty(
42+
"virtualPackage",
43+
uid = "ceab5195-25ea-4f22-9b92-103b95ca8c0c/1133920641626/1193676396447",
44+
).also(this::addProperty)
45+
4246
val smodelAttribute by childLink("ceab5195-25ea-4f22-9b92-103b95ca8c0c/1133920641626/5169995583184591170").multiple()
4347
.optional().type { Attribute }
4448
}
@@ -63,7 +67,10 @@ object BuiltinLanguages {
6367

6468
object INamedConcept : SimpleConcept(conceptName = "INamedConcept") {
6569
init { addConcept(this) }
66-
val name by property("ceab5195-25ea-4f22-9b92-103b95ca8c0c/1169194658468/1169194664001")
70+
val name = SimpleProperty(
71+
"name",
72+
uid = "ceab5195-25ea-4f22-9b92-103b95ca8c0c/1169194658468/1169194664001",
73+
).also(this::addProperty)
6774
}
6875
}
6976

@@ -88,8 +95,15 @@ object BuiltinLanguages {
8895
) {
8996
init { addConcept(this) }
9097

91-
val id by property("0a7577d1-d4e5-431d-98b1-fae38f9aee80/474657388638618892/2615330535972958738")
92-
val stereotype by property("0a7577d1-d4e5-431d-98b1-fae38f9aee80/474657388638618892/3832696962605996173")
98+
val id = SimpleProperty(
99+
"id",
100+
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/474657388638618892/2615330535972958738",
101+
).also(this::addProperty)
102+
103+
val stereotype = SimpleProperty(
104+
"stereotype",
105+
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/474657388638618892/3832696962605996173",
106+
).also(this::addProperty)
93107

94108
val rootNodes = SimpleChildLink(
95109
simpleName = "rootNodes",
@@ -121,9 +135,20 @@ object BuiltinLanguages {
121135
) {
122136
init { addConcept(this) }
123137

124-
val id by property("0a7577d1-d4e5-431d-98b1-fae38f9aee80/474657388638618895/4225291329823310560")
125-
val moduleVersion by property("0a7577d1-d4e5-431d-98b1-fae38f9aee80/474657388638618895/2206727074858242370")
126-
val compileInMPS by property("0a7577d1-d4e5-431d-98b1-fae38f9aee80/474657388638618895/2206727074858242373")
138+
val id = SimpleProperty(
139+
"id",
140+
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/474657388638618895/4225291329823310560",
141+
).also(this::addProperty)
142+
143+
val moduleVersion = SimpleProperty(
144+
"moduleVersion",
145+
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/474657388638618895/2206727074858242370",
146+
).also(this::addProperty)
147+
148+
val compileInMPS = SimpleProperty(
149+
"compileInMPS",
150+
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/474657388638618895/2206727074858242373",
151+
).also(this::addProperty)
127152

128153
val models = SimpleChildLink(
129154
simpleName = "models",
@@ -242,7 +267,10 @@ object BuiltinLanguages {
242267
) {
243268
init { addConcept(this) }
244269

245-
val virtualFolder by property("0a7577d1-d4e5-431d-98b1-fae38f9aee80/4201834143491306084/4201834143491306085")
270+
val virtualFolder = SimpleProperty(
271+
"virtualFolder",
272+
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/4201834143491306084/4201834143491306085",
273+
).also(this::addProperty)
246274
}
247275

248276
object ModuleReference : SimpleConcept(
@@ -283,8 +311,15 @@ object BuiltinLanguages {
283311
) {
284312
init { addConcept(this) }
285313

286-
val uuid by property("0a7577d1-d4e5-431d-98b1-fae38f9aee80/8958347146611575311/8958347146611575314")
287-
val name by property("0a7577d1-d4e5-431d-98b1-fae38f9aee80/8958347146611575311/8958347146611575315")
314+
val uuid = SimpleProperty(
315+
"uuid",
316+
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/8958347146611575311/8958347146611575314",
317+
).also(this::addProperty)
318+
319+
val name = SimpleProperty(
320+
"name",
321+
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/8958347146611575311/8958347146611575315",
322+
).also(this::addProperty)
288323
}
289324

290325
object SingleLanguageDependency : SimpleConcept(
@@ -294,7 +329,10 @@ object BuiltinLanguages {
294329
) {
295330
init { addConcept(this) }
296331

297-
val version by property("0a7577d1-d4e5-431d-98b1-fae38f9aee80/2206727074858242429/2206727074858242435")
332+
val version = SimpleProperty(
333+
"version",
334+
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/2206727074858242429/2206727074858242435",
335+
).also(this::addProperty)
298336
}
299337

300338
object DevkitDependency : SimpleConcept(
@@ -320,8 +358,15 @@ object BuiltinLanguages {
320358
) {
321359
init { addConcept(this) }
322360

323-
val generated by property("0a7577d1-d4e5-431d-98b1-fae38f9aee80/2206727074858242406/2206727074858242407")
324-
val path by property("0a7577d1-d4e5-431d-98b1-fae38f9aee80/2206727074858242406/2206727074858242409")
361+
val generated = SimpleProperty(
362+
"generated",
363+
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/2206727074858242406/2206727074858242407",
364+
).also(this::addProperty)
365+
366+
val path = SimpleProperty(
367+
"path",
368+
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/2206727074858242406/2206727074858242409",
369+
).also(this::addProperty)
325370
}
326371

327372
object ModuleDependency : SimpleConcept(
@@ -331,12 +376,35 @@ object BuiltinLanguages {
331376
) {
332377
init { addConcept(this) }
333378

334-
val reexport by property("0a7577d1-d4e5-431d-98b1-fae38f9aee80/2206727074858242415/2206727074858242416")
335-
val uuid by property("0a7577d1-d4e5-431d-98b1-fae38f9aee80/2206727074858242415/2206727074858242418")
336-
val name by property("0a7577d1-d4e5-431d-98b1-fae38f9aee80/2206727074858242415/2206727074858242421")
337-
val explicit by property("0a7577d1-d4e5-431d-98b1-fae38f9aee80/2206727074858242415/2206727074858750565")
338-
val version by property("0a7577d1-d4e5-431d-98b1-fae38f9aee80/2206727074858242415/2206727074858750570")
339-
val scope by property("0a7577d1-d4e5-431d-98b1-fae38f9aee80/2206727074858242415/8438396892798826745")
379+
val reexport = SimpleProperty(
380+
"reexport",
381+
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/2206727074858242415/2206727074858242416",
382+
).also(this::addProperty)
383+
384+
val uuid = SimpleProperty(
385+
"uuid",
386+
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/2206727074858242415/2206727074858242418",
387+
).also(this::addProperty)
388+
389+
val name = SimpleProperty(
390+
"name",
391+
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/2206727074858242415/2206727074858242421",
392+
).also(this::addProperty)
393+
394+
val explicit = SimpleProperty(
395+
"explicit",
396+
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/2206727074858242415/2206727074858750565",
397+
).also(this::addProperty)
398+
399+
val version = SimpleProperty(
400+
"version",
401+
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/2206727074858242415/2206727074858750570",
402+
).also(this::addProperty)
403+
404+
val scope = SimpleProperty(
405+
"scope",
406+
uid = "0a7577d1-d4e5-431d-98b1-fae38f9aee80/2206727074858242415/8438396892798826745",
407+
).also(this::addProperty)
340408
}
341409
}
342410

@@ -368,7 +436,10 @@ object BuiltinLanguages {
368436
) {
369437
init { addConcept(this) }
370438

371-
val id by property("b6980ebd-f01d-459d-a952-38740f6313b4/7113393488488348864/7113393488488348870")
439+
val id = SimpleProperty(
440+
"id",
441+
uid = "b6980ebd-f01d-459d-a952-38740f6313b4/7113393488488348864/7113393488488348870",
442+
).also(this::addProperty)
372443

373444
val branches = SimpleChildLink(
374445
simpleName = "branches",
@@ -395,20 +466,6 @@ object BuiltinLanguages {
395466
)
396467
}
397468

398-
private fun SimpleConcept.property(uid: String) = object {
399-
private lateinit var name: String
400-
private lateinit var owner: SimpleConcept
401-
private val instance: IProperty by lazy {
402-
SimpleProperty(name, uid = uid).also { owner.addProperty(it) }
403-
}
404-
405-
operator fun getValue(ownerConcept: SimpleConcept, kotlinProperty: KProperty<*>): IProperty {
406-
this.owner = ownerConcept
407-
this.name = kotlinProperty.name
408-
return instance
409-
}
410-
}
411-
412469
private fun SimpleConcept.childLink(uid: String) = object {
413470
private lateinit var name: String
414471
private lateinit var owner: SimpleConcept
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2023-2024.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.modelix.model.api
18+
19+
import kotlin.test.Test
20+
import kotlin.test.assertEquals
21+
22+
class BuiltinLanguagesTest {
23+
24+
@Test
25+
fun allPropertiesAreListedWithoutPriorAccess() {
26+
val properties = BuiltinLanguages.MPSRepositoryConcepts.Model.getAllProperties()
27+
28+
// This trivial assertion is relevant
29+
// because previously, some properties were only after the property was directly accessed.
30+
// For example, Model.stereotype would be included in Model.getAllProperties() before
31+
// Model.stereotype was accessed once directly.
32+
assertEquals(4, properties.size)
33+
}
34+
}

0 commit comments

Comments
 (0)