@@ -50,7 +50,7 @@ class ModelImporter(
5050) {
5151
5252 private val originalIdToExisting: MutableMap <String , INode > = mutableMapOf ()
53- private val postponedReferences = ArrayList < () -> Unit > ()
53+ private val postponedReferences = mutableListOf< PostponedReference >()
5454 private val nodesToRemove = HashSet <INode >()
5555 private var numExpectedNodes = 0
5656 private var currentNodeProgress = 0
@@ -72,6 +72,23 @@ class ModelImporter(
7272 }
7373 }
7474
75+ data class PostponedReference (
76+ val expectedTargetId : String ,
77+ val mpsNode : INode ,
78+ val role : String ,
79+ )
80+
81+ private fun PostponedReference.setPostponedReference () {
82+ val expectedRefTarget = originalIdToExisting[expectedTargetId]
83+ if (expectedRefTarget == null ) {
84+ // The target node is not part of the model. Assuming it exists in some other model we can
85+ // store the reference and try to resolve it dynamically on access.
86+ mpsNode.setReferenceTarget(role, SerializedNodeReference (expectedTargetId))
87+ } else {
88+ mpsNode.setReferenceTarget(role, expectedRefTarget)
89+ }
90+ }
91+
7592 /* *
7693 * Incrementally updates this importers root based on the provided [ModelData] specification.
7794 *
@@ -95,11 +112,7 @@ class ModelImporter(
95112 syncNode(root, data.root, progressReporter)
96113
97114 logger.info { " Synchronizing references..." }
98- postponedReferences.forEach {
99- doAndPotentiallyContinueOnErrors {
100- it.invoke()
101- }
102- }
115+ postponedReferences.forEach { it.setPostponedReference() }
103116
104117 logger.info { " Removing extra nodes..." }
105118 nodesToRemove.forEach {
@@ -234,16 +247,7 @@ class ModelImporter(
234247 if (actualTargetId != expectedTargetId) {
235248 val expectedTarget = originalIdToExisting[expectedTargetId]
236249 if (expectedTarget == null ) {
237- postponedReferences + = {
238- val expectedRefTarget = originalIdToExisting[expectedTargetId]
239- if (expectedRefTarget == null ) {
240- // The target node is not part of the model. Assuming it exists in some other model we can
241- // store the reference and try to resolve it dynamically on access.
242- node.setReferenceTarget(it.key, SerializedNodeReference (expectedTargetId))
243- } else {
244- node.setReferenceTarget(it.key, expectedRefTarget)
245- }
246- }
250+ postponedReferences + = PostponedReference (expectedTargetId, node, it.key)
247251 } else {
248252 node.setReferenceTarget(it.key, expectedTarget)
249253 }
0 commit comments