Skip to content

Commit

Permalink
fix(mps-sync-plugin-lib): replaced mappedMpsNodeID with getOriginalRe…
Browse files Browse the repository at this point in the history
…ference (MODELIX-822)
  • Loading branch information
benedekh committed Mar 20, 2024
1 parent a913de9 commit 0778534
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import org.modelix.mps.sync.tasks.SyncDirection
import org.modelix.mps.sync.tasks.SyncLock
import org.modelix.mps.sync.tasks.SyncQueue
import org.modelix.mps.sync.transformation.cache.MpsToModelixMap
import org.modelix.mps.sync.util.mappedMpsNodeID
import org.modelix.mps.sync.util.nodeIdAsLong
import org.modelix.mps.sync.util.waitForCompletionOfEachTask

Expand Down Expand Up @@ -81,7 +80,6 @@ class SNodeFactory(
// 1. create node
val mpsNodeId = getMpsNodeId(iNode)
val sNode = jetbrains.mps.smodel.SNode(concept, mpsNodeId)
val nodeId = iNode.nodeIdAsLong()

// 2. add to parent
val parent = iNode.parent
Expand Down Expand Up @@ -115,7 +113,7 @@ class SNodeFactory(
}

private fun getMpsNodeId(iNode: INode): SNodeId {
val mpsNodeIdAsString = iNode.mappedMpsNodeID()
val mpsNodeIdAsString = iNode.getOriginalReference()
val mpsId = mpsNodeIdAsString?.let { PersistenceFacade.getInstance().createNodeId(it) }
return if (mpsId != null) {
mpsId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,8 @@ import org.modelix.kotlin.utils.UnstableModelixFeature
import org.modelix.model.api.BuiltinLanguages
import org.modelix.model.api.INode
import org.modelix.model.api.PNodeAdapter
import org.modelix.model.api.PropertyFromName
import org.modelix.model.data.NodeData
import org.modelix.model.mpsadapters.MPSNode

@UnstableModelixFeature(reason = "The new modelix MPS plugin is under construction", intendedFinalization = "2024.1")
fun INode.mappedMpsNodeID(): String? {
return try {
val nodeIdProperty = PropertyFromName(NodeData.ID_PROPERTY_KEY)
this.getPropertyValue(nodeIdProperty)
} catch (e: RuntimeException) {
throw RuntimeException(
"Failed to retrieve the ${NodeData.ID_PROPERTY_KEY} property in mappedMpsNodeID. The INode is $this , concept: ${this.concept}",
e,
)
}
}

@UnstableModelixFeature(reason = "The new modelix MPS plugin is under construction", intendedFinalization = "2024.1")
fun INode.nodeIdAsLong(): Long =
when (this) {
Expand Down Expand Up @@ -79,9 +64,7 @@ fun INode.isSingleLanguageDependency(): Boolean {
fun INode.isModelImport(): Boolean {
val concept = this.concept ?: return false
val isModelReference = concept.isSubConceptOf(BuiltinLanguages.MPSRepositoryConcepts.ModelReference)
// we have to use roleInParent, because getContainmentLink() is sometimes null, when roleInParent is not
val isModelImportRole =
this.roleInParent == BuiltinLanguages.MPSRepositoryConcepts.Model.modelImports.getSimpleName()
val isModelImportRole = BuiltinLanguages.MPSRepositoryConcepts.Model.modelImports == this.getContainmentLink()
return isModelReference && isModelImportRole
}

Expand Down

0 comments on commit 0778534

Please sign in to comment.