Skip to content

Commit da0a0aa

Browse files
committed
feat(model-api): add and implement ITreeChangeVisitor::conceptChanged
1 parent 6b1668c commit da0a0aa

File tree

15 files changed

+72
-1
lines changed

15 files changed

+72
-1
lines changed

model-api/src/commonMain/kotlin/org/modelix/model/api/ITreeChangeVisitor.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ interface ITreeChangeVisitor {
2626
*/
2727
fun containmentChanged(nodeId: Long)
2828

29+
/**
30+
* Called when the concept of a node has changed.
31+
*
32+
* @param nodeId id of the affected node
33+
*/
34+
fun conceptChanged(nodeId: Long)
35+
2936
/**
3037
* Called when the children of a node have changed.
3138
*

model-client/src/commonMain/kotlin/org/modelix/model/IncrementalBranch.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class IncrementalBranch(val branch: IBranch) : IBranch, IBranchWrapper {
4545
modified(ContainmentDependency(this@IncrementalBranch, nodeId))
4646
}
4747

48+
override fun conceptChanged(nodeId: Long) {
49+
modified(ConceptDependency(this@IncrementalBranch, nodeId))
50+
}
51+
4852
override fun childrenChanged(nodeId: Long, role: String?) {
4953
modified(ChildrenDependency(this@IncrementalBranch, nodeId, role))
5054
}
@@ -331,7 +335,6 @@ class IncrementalBranch(val branch: IBranch) : IBranch, IBranchWrapper {
331335
val oldRole = transaction.getRole(nodeId)
332336
transaction.setConcept(nodeId, concept)
333337
modified(ChildrenDependency(this@IncrementalBranch, oldParentId, oldRole))
334-
modified(ContainmentDependency(this@IncrementalBranch, nodeId))
335338
modified(UnclassifiedNodeDependency(this@IncrementalBranch, nodeId))
336339
}
337340

@@ -541,4 +544,8 @@ data class ContainmentDependency(val branch: IBranch, val nodeId: Long) : Depend
541544
override fun getGroup() = UnclassifiedNodeDependency(branch, nodeId)
542545
}
543546

547+
data class ConceptDependency(val branch: IBranch, val nodeId: Long) : DependencyBase() {
548+
override fun getGroup(): IStateVariableGroup = UnclassifiedNodeDependency(branch, nodeId)
549+
}
550+
544551
fun IBranch.withIncrementalComputationSupport() = IncrementalBranch(this)

model-client/src/commonMain/kotlin/org/modelix/model/ModelIndex.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class ModelIndex private constructor(val tree: ITree, val propertyRole: String)
4444

4545
override fun referenceChanged(nodeId: Long, role: String) {}
4646
override fun containmentChanged(nodeId: Long) {}
47+
override fun conceptChanged(nodeId: Long) {}
48+
4749
override fun nodeRemoved(nodeId: Long) {
4850
val key = oldIndex.readKey(nodeId)
4951
index.nodeMap[key]?.remove(nodeId)

model-client/src/commonMain/kotlin/org/modelix/model/SubtreeChanges.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class SubtreeChanges(val cacheSize: Int) {
5252
// there is always a corresponding childrenChanged event for this
5353
}
5454

55+
override fun conceptChanged(nodeId: Long) {
56+
affectedNodes += nodeId
57+
}
58+
5559
override fun propertyChanged(nodeId: Long, role: String) {
5660
affectedNodes += nodeId
5761
}

model-client/src/commonMain/kotlin/org/modelix/model/metameta/MetaModelIndex.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class MetaModelIndex private constructor(val tree: ITree) {
7070

7171
override fun referenceChanged(nodeId: Long, role: String) {}
7272
override fun containmentChanged(nodeId: Long) {}
73+
override fun conceptChanged(nodeId: Long) {}
7374
},
7475
)
7576

model-client/src/jsMain/kotlin/org/modelix/model/client2/ChangeJS.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,10 @@ data class ReferenceChanged(override val node: INodeJS, val role: String) : Chan
5555
)
5656
@JsExport
5757
data class ContainmentChanged(override val node: INodeJS) : ChangeJS
58+
59+
@UnstableModelixFeature(
60+
reason = "The overarching task https://issues.modelix.org/issue/MODELIX-500 is in development.",
61+
intendedFinalization = "The client is intended to be finalized when the overarching task is finished.",
62+
)
63+
@JsExport
64+
data class ConceptChanged(override val node: INodeJS) : ChangeJS

model-client/src/jsMain/kotlin/org/modelix/model/client2/ClientJS.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ class ChangeListener(private val branch: IBranch, private val changeCallback: (C
171171
changeCallback(ContainmentChanged(nodeIdToInode(nodeId)))
172172
}
173173

174+
override fun conceptChanged(nodeId: Long) {
175+
changeCallback(ConceptChanged(nodeIdToInode(nodeId)))
176+
}
177+
174178
override fun childrenChanged(nodeId: Long, role: String?) {
175179
changeCallback(ChildrenChanged(nodeIdToInode(nodeId), role))
176180
}

model-datastructure/src/commonMain/kotlin/org/modelix/model/lazy/CLTree.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ class CLTree : ITree, IBulkTree {
486486
}
487487
if (oldElement.parentId != newElement.parentId) {
488488
visitor.containmentChanged(key)
489+
} else if (oldElement.concept != newElement.concept) {
490+
visitor.conceptChanged(key)
489491
} else if (oldElement.roleInParent != newElement.roleInParent) {
490492
visitor.containmentChanged(key)
491493
notifyChildrenChange(oldElement.parentId, oldElement.roleInParent)

model-datastructure/src/commonTest/kotlin/ConflictResolutionTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,10 @@ fun assertSameTree(tree1: ITree, tree2: ITree) {
825825
fail("containmentChanged ${nodeId.toString(16)}")
826826
}
827827

828+
override fun conceptChanged(nodeId: Long) {
829+
fail("conceptChanged ${nodeId.toString(16)}")
830+
}
831+
828832
override fun childrenChanged(nodeId: Long, role: String?) {
829833
fail("childrenChanged ${nodeId.toString(16)}, $role")
830834
}

model-datastructure/src/commonTest/kotlin/DiffTest.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import org.modelix.model.api.BuiltinLanguages
1718
import org.modelix.model.api.ConceptReference
1819
import org.modelix.model.api.ITree
1920
import org.modelix.model.api.NodeReference
@@ -26,6 +27,17 @@ import kotlin.test.fail
2627

2728
class DiffTest {
2829

30+
@Test
31+
fun changeConcept() {
32+
runTest(
33+
setOf(
34+
TreeChangeCollector.ConceptChangedEvent(ITree.ROOT_ID),
35+
),
36+
) {
37+
it.setConcept(ITree.ROOT_ID, BuiltinLanguages.jetbrains_mps_lang_core.INamedConcept.getReference())
38+
}
39+
}
40+
2941
@Test
3042
fun changeProperty() {
3143
runTest(

0 commit comments

Comments
 (0)