Skip to content

Commit

Permalink
use untyped model API to support editor rules generated by MPS (5)
Browse files Browse the repository at this point in the history
  • Loading branch information
slisson committed Nov 24, 2023
1 parent 750f8fe commit df9e2af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,12 @@ interface ITypedOrUntypedNode<NodeT> {
}
}

fun <NodeT :ITypedNode, ConceptT : IConceptOfTypedNode<NodeT>> CellTemplate.builder(concept: ConceptT): CellTemplateBuilder<NodeT, ConceptT> {
fun <NodeT : ITypedNode, ConceptT : IConceptOfTypedNode<NodeT>> CellTemplate.builder(concept: ConceptT): CellTemplateBuilder<NodeT, ConceptT> {
require(this.concept == concept.untyped())
return CellTemplateBuilder(this, concept, INodeConverter.Typed<NodeT>(concept))
}

fun <ConceptT : IConcept> CellTemplate.builder(concept: ConceptT): CellTemplateBuilder<INode, ConceptT> {
require(this.concept == concept)
return CellTemplateBuilder(this, concept, INodeConverter.Untyped)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package org.modelix.editor
import org.modelix.aspects.ILanguageAspect
import org.modelix.aspects.ILanguageAspectFactory
import org.modelix.metamodel.IConceptOfTypedNode
import org.modelix.metamodel.ITypedConcept
import org.modelix.metamodel.ITypedNode
import org.modelix.metamodel.typed
import org.modelix.model.api.IConcept
import org.modelix.model.api.IConceptReference
import org.modelix.model.api.ILanguage
Expand All @@ -14,13 +16,14 @@ class EditorAspect : ILanguageAspect {

fun <NodeT : ITypedNode, ConceptT : IConceptOfTypedNode<NodeT>> conceptEditor(concept: ConceptT, body: CellTemplateBuilder<NodeT, ConceptT>.()->Unit): ConceptEditor {
return ConceptEditor(concept.untyped()) { subConcept ->
CollectionCellTemplate(subConcept).builder(concept).also(body).template
val typedSubconcept= subConcept.typed() as ConceptT
CollectionCellTemplate(subConcept).builder(typedSubconcept).also(body).template
}.also(conceptEditors::add)
}

fun conceptEditor(concept: IConcept, body: CellTemplateBuilder<INode, IConcept>.()->Unit): ConceptEditor {
return ConceptEditor(concept) { subConcept ->
CollectionCellTemplate(subConcept).builder(concept).also(body).template
CollectionCellTemplate(subConcept).builder(subConcept).also(body).template
}.also(conceptEditors::add)
}

Expand Down

0 comments on commit df9e2af

Please sign in to comment.