@@ -16,8 +16,13 @@ package org.modelix.model.mpsadapters
1616import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations
1717import jetbrains.mps.smodel.MPSModuleRepository
1818import jetbrains.mps.smodel.adapter.MetaAdapterByDeclaration
19+ import jetbrains.mps.smodel.adapter.ids.SContainmentLinkId
20+ import jetbrains.mps.smodel.adapter.ids.SPropertyId
1921import jetbrains.mps.smodel.adapter.ids.SReferenceLinkId
22+ import jetbrains.mps.smodel.adapter.structure.link.SContainmentLinkAdapterById
23+ import jetbrains.mps.smodel.adapter.structure.property.SPropertyAdapterById
2024import jetbrains.mps.smodel.adapter.structure.ref.SReferenceLinkAdapterById
25+ import org.jetbrains.mps.openapi.language.SContainmentLink
2126import org.jetbrains.mps.openapi.model.SNode
2227import org.modelix.model.api.BuiltinLanguages
2328import org.modelix.model.api.ConceptReference
@@ -77,9 +82,8 @@ data class MPSNode(val node: SNode) : IDeprecatedNodeDefaults {
7782 }
7883
7984 override fun moveChild (role : IChildLink , index : Int , child : INode ) {
80- require(role is MPSChildLink ) { " role must be an MPSChildLink " }
85+ val link = getMPSContainmentLink( role)
8186
82- val link = role.link
8387 val children = node.getChildren(link).toList()
8488 require(index <= children.size) { " index out of bounds: $index > ${children.size} " }
8589
@@ -95,9 +99,8 @@ data class MPSNode(val node: SNode) : IDeprecatedNodeDefaults {
9599 }
96100
97101 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)
99103
100- val link = role.link
101104 val children = node.getChildren(link).toList()
102105 require(index <= children.size) { " index out of bounds: $index > ${children.size} " }
103106
@@ -160,7 +163,18 @@ data class MPSNode(val node: SNode) : IDeprecatedNodeDefaults {
160163 }
161164
162165 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+ }
164172 node.setProperty(mpsProperty, value)
165173 }
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+ }
166180}
0 commit comments