-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathInvalidatingVisitor.kt
41 lines (32 loc) · 1.26 KB
/
InvalidatingVisitor.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package org.modelix.model.sync.bulk
import org.modelix.model.api.ITree
import org.modelix.model.api.ITreeChangeVisitorEx
import org.modelix.model.api.TreePointer
import org.modelix.model.api.getNode
/**
* Visitor that visits a [tree] and stores the invalidation information in an [invalidationTree].
*/
class InvalidatingVisitor(val newTree: ITree, val invalidationTree: InvalidationTree) : ITreeChangeVisitorEx {
private fun invalidateNode(nodeId: Long) {
invalidationTree.invalidate(TreePointer(newTree).getNode(nodeId).asReadableNode(), false)
}
override fun containmentChanged(nodeId: Long) {
// Containment can only change if also the children of the parent changed.
// Synchronizing the parent will automatically update the containment of the children.
}
override fun childrenChanged(nodeId: Long, role: String?) {
invalidateNode(nodeId)
}
override fun referenceChanged(nodeId: Long, role: String) {
invalidateNode(nodeId)
}
override fun propertyChanged(nodeId: Long, role: String) {
invalidateNode(nodeId)
}
override fun nodeRemoved(nodeId: Long) {
// same reason as in containmentChanged
}
override fun nodeAdded(nodeId: Long) {
invalidateNode(nodeId)
}
}