@@ -16,8 +16,13 @@ package org.modelix.model.mpsadapters
16
16
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations
17
17
import jetbrains.mps.smodel.MPSModuleRepository
18
18
import jetbrains.mps.smodel.adapter.MetaAdapterByDeclaration
19
+ import jetbrains.mps.smodel.adapter.ids.SContainmentLinkId
20
+ import jetbrains.mps.smodel.adapter.ids.SPropertyId
19
21
import jetbrains.mps.smodel.adapter.ids.SReferenceLinkId
22
+ import jetbrains.mps.smodel.adapter.structure.link.SContainmentLinkAdapterById
23
+ import jetbrains.mps.smodel.adapter.structure.property.SPropertyAdapterById
20
24
import jetbrains.mps.smodel.adapter.structure.ref.SReferenceLinkAdapterById
25
+ import org.jetbrains.mps.openapi.language.SContainmentLink
21
26
import org.jetbrains.mps.openapi.model.SNode
22
27
import org.modelix.model.api.BuiltinLanguages
23
28
import org.modelix.model.api.ConceptReference
@@ -77,9 +82,8 @@ data class MPSNode(val node: SNode) : IDeprecatedNodeDefaults {
77
82
}
78
83
79
84
override fun moveChild (role : IChildLink , index : Int , child : INode ) {
80
- require(role is MPSChildLink ) { " role must be an MPSChildLink " }
85
+ val link = getMPSContainmentLink( role)
81
86
82
- val link = role.link
83
87
val children = node.getChildren(link).toList()
84
88
require(index <= children.size) { " index out of bounds: $index > ${children.size} " }
85
89
@@ -95,9 +99,8 @@ data class MPSNode(val node: SNode) : IDeprecatedNodeDefaults {
95
99
}
96
100
97
101
override fun addNewChild (role : IChildLink , index : Int , concept : IConcept ? ): INode {
98
- require(role is MPSChildLink ) { " role must be an MPSChildLink " }
102
+ val link = getMPSContainmentLink( role)
99
103
100
- val link = role.link
101
104
val children = node.getChildren(link).toList()
102
105
require(index <= children.size) { " index out of bounds: $index > ${children.size} " }
103
106
@@ -160,7 +163,18 @@ data class MPSNode(val node: SNode) : IDeprecatedNodeDefaults {
160
163
}
161
164
162
165
override fun setPropertyValue (property : IProperty , value : String? ) {
163
- val mpsProperty = node.properties.first { MPSProperty (it).getUID() == property.getUID() }
166
+ val mpsProperty = when (property) {
167
+ is MPSProperty -> property.property
168
+ else -> node.properties.find { MPSProperty (it).getUID() == property.getUID() }
169
+ ? : node.concept.properties.find { MPSProperty (it).getUID() == property.getUID() }
170
+ ? : SPropertyAdapterById (SPropertyId .deserialize(property.getUID()), " " )
171
+ }
164
172
node.setProperty(mpsProperty, value)
165
173
}
174
+
175
+ private fun getMPSContainmentLink (childLink : IChildLink ): SContainmentLink = when (childLink) {
176
+ is MPSChildLink -> childLink.link
177
+ else -> node.concept.containmentLinks.find { MPSChildLink (it).getUID() == childLink.getUID() }
178
+ ? : SContainmentLinkAdapterById (SContainmentLinkId .deserialize(childLink.getUID()), " " )
179
+ }
166
180
}
0 commit comments