@@ -50,7 +50,7 @@ class ModelImporter(
50
50
) {
51
51
52
52
private val originalIdToExisting: MutableMap <String , INode > = mutableMapOf ()
53
- private val postponedReferences = ArrayList < () -> Unit > ()
53
+ private val postponedReferences = mutableListOf< PostponedReference >()
54
54
private val nodesToRemove = HashSet <INode >()
55
55
private var numExpectedNodes = 0
56
56
private var currentNodeProgress = 0
@@ -72,6 +72,23 @@ class ModelImporter(
72
72
}
73
73
}
74
74
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
+
75
92
/* *
76
93
* Incrementally updates this importers root based on the provided [ModelData] specification.
77
94
*
@@ -95,11 +112,7 @@ class ModelImporter(
95
112
syncNode(root, data.root, progressReporter)
96
113
97
114
logger.info { " Synchronizing references..." }
98
- postponedReferences.forEach {
99
- doAndPotentiallyContinueOnErrors {
100
- it.invoke()
101
- }
102
- }
115
+ postponedReferences.forEach { it.setPostponedReference() }
103
116
104
117
logger.info { " Removing extra nodes..." }
105
118
nodesToRemove.forEach {
@@ -234,16 +247,7 @@ class ModelImporter(
234
247
if (actualTargetId != expectedTargetId) {
235
248
val expectedTarget = originalIdToExisting[expectedTargetId]
236
249
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)
247
251
} else {
248
252
node.setReferenceTarget(it.key, expectedTarget)
249
253
}
0 commit comments