Skip to content

Commit 2e56b6a

Browse files
committed
use the new interfaces instead of GeneratedProperty, GeneratedReferencLink, ...
1 parent 49e862c commit 2e56b6a

File tree

7 files changed

+35
-30
lines changed

7 files changed

+35
-30
lines changed

editor-runtime/src/commonMain/kotlin/org/modelix/editor/CellTemplate.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package org.modelix.editor
22

33
import org.modelix.metamodel.GeneratedConcept
4-
import org.modelix.metamodel.GeneratedReferenceLink
54
import org.modelix.metamodel.ITypedConcept
65
import org.modelix.metamodel.ITypedNode
6+
import org.modelix.metamodel.ITypedReferenceLink
77
import org.modelix.metamodel.getPropertyValue
8+
import org.modelix.metamodel.getReferenceTargetOrNull
9+
import org.modelix.metamodel.setReferenceTarget
810
import org.modelix.metamodel.typed
911
import org.modelix.metamodel.typedUnsafe
1012
import org.modelix.metamodel.untyped
@@ -14,10 +16,8 @@ import org.modelix.model.api.INode
1416
import org.modelix.model.api.IProperty
1517
import org.modelix.model.api.addNewChild
1618
import org.modelix.model.api.getChildren
17-
import org.modelix.model.api.getReferenceTarget
1819
import org.modelix.model.api.moveChild
1920
import org.modelix.model.api.setPropertyValue
20-
import org.modelix.model.api.setReferenceTarget
2121

2222
abstract class CellTemplate<NodeT : ITypedNode, ConceptT : ITypedConcept>(val concept: GeneratedConcept<NodeT, ConceptT>) {
2323
val properties = CellProperties()
@@ -298,24 +298,24 @@ open class PropertyCellTemplate<NodeT : ITypedNode, ConceptT : ITypedConcept>(co
298298
}
299299
}
300300

301-
class ReferenceCellTemplate<NodeT : ITypedNode, ConceptT : ITypedConcept, TargetNodeT : ITypedNode, TargetConceptT : ITypedConcept>(
301+
class ReferenceCellTemplate<NodeT : ITypedNode, ConceptT : ITypedConcept, TargetNodeT : ITypedNode>(
302302
concept: GeneratedConcept<NodeT, ConceptT>,
303-
val link: GeneratedReferenceLink<TargetNodeT, TargetConceptT>,
303+
val link: ITypedReferenceLink<TargetNodeT>,
304304
val presentation: TargetNodeT.() -> String?
305305
) : CellTemplate<NodeT, ConceptT>(concept), IGrammarSymbol {
306306
override fun createCell(context: CellCreationContext, node: NodeT): CellData {
307-
val data = TextCellData(getText(node), "<no ${link.name}>")
308-
data.cellReferences += ReferencedNodeCellReference(node.untypedReference(), link)
307+
val data = TextCellData(getText(node), "<no ${link.untyped().name}>")
308+
data.cellReferences += ReferencedNodeCellReference(node.untypedReference(), link.untyped())
309309
data.properties[CommonCellProperties.tabTarget] = true
310310
return data
311311
}
312312
private fun getText(node: NodeT): String = getTargetNode(node)?.let(presentation) ?: ""
313313
private fun getTargetNode(sourceNode: NodeT): TargetNodeT? {
314-
return sourceNode.unwrap().getReferenceTarget(link)?.typedUnsafe()
314+
return sourceNode.unwrap().getReferenceTargetOrNull(link)
315315
}
316316
override fun getInstantiationActions(location: INonExistingNode, parameters: CodeCompletionParameters): List<IActionOrProvider>? {
317317
val specializedLocation = location.ofSubConcept(concept)
318-
val targets = specializedLocation.getVisibleReferenceTargets(link)
318+
val targets = specializedLocation.getVisibleReferenceTargets(link.untyped())
319319
return targets.map { WrapReferenceTarget(location, it, presentation(it.typedUnsafe()) ?: "") }
320320
}
321321

@@ -330,7 +330,7 @@ class ReferenceCellTemplate<NodeT : ITypedNode, ConceptT : ITypedConcept, Target
330330

331331
override fun execute(editor: EditorComponent) {
332332
val sourceNode = location.getOrCreateNode(concept)
333-
sourceNode.setReferenceTarget(link, target)
333+
sourceNode.setReferenceTarget(link, link.castTarget(target))
334334
editor.selectAfterUpdate {
335335
CaretPositionPolicy(createCellReference(sourceNode))
336336
.getBestSelection(editor)

editor-runtime/src/commonMain/kotlin/org/modelix/editor/CellTemplateBuilder.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,26 +173,26 @@ open class CellTemplateBuilder<NodeT : ITypedNode, ConceptT : ITypedConcept>(val
173173
.also(body).template.also(template::addChild)
174174
}
175175

176-
fun <TargetNodeT : ITypedNode, TargetConceptT : ITypedConcept> GeneratedReferenceLink<TargetNodeT, TargetConceptT>.cell(presentation: TargetNodeT.()->String?, body: ReferenceCellTemplateBuilder<NodeT, ConceptT, TargetNodeT, TargetConceptT>.()->Unit = {}) {
176+
fun <TargetNodeT : ITypedNode> ITypedReferenceLink<TargetNodeT>.cell(presentation: TargetNodeT.()->String?, body: ReferenceCellTemplateBuilder<NodeT, ConceptT, TargetNodeT>.()->Unit = {}) {
177177
ReferenceCellTemplateBuilder(ReferenceCellTemplate(template.concept, this, presentation), this)
178178
.also(body).template.also(template::addChild)
179179
}
180180

181-
fun GeneratedSingleChildLink<*, *>.cell(body: CellTemplateBuilder<NodeT, ConceptT>.()->Unit = {}) {
182-
CellTemplateBuilder(ChildCellTemplate(template.concept, this))
181+
fun ITypedSingleChildLink<*>.cell(body: CellTemplateBuilder<NodeT, ConceptT>.()->Unit = {}) {
182+
CellTemplateBuilder(ChildCellTemplate(template.concept, this.untyped()))
183183
.also(body).template.also(template::addChild)
184184
}
185185

186-
fun GeneratedChildListLink<*, *>.vertical(body: CellTemplateBuilder<NodeT, ConceptT>.()->Unit = {}) {
186+
fun ITypedChildListLink<*>.vertical(body: CellTemplateBuilder<NodeT, ConceptT>.()->Unit = {}) {
187187
// TODO add layout information
188188
horizontal(separator = null) {
189189
template.properties[CommonCellProperties.layout] = ECellLayout.VERTICAL
190190
body()
191191
}
192192
}
193193

194-
fun GeneratedChildListLink<*, *>.horizontal(separator: String? = ",", body: CellTemplateBuilder<NodeT, ConceptT>.()->Unit = {}) {
195-
CellTemplateBuilder(ChildCellTemplate(template.concept, this))
194+
fun ITypedChildListLink<*>.horizontal(separator: String? = ",", body: CellTemplateBuilder<NodeT, ConceptT>.()->Unit = {}) {
195+
CellTemplateBuilder(ChildCellTemplate(template.concept, this.untyped()))
196196
.also(body).template.also(template::addChild)
197197
}
198198

@@ -240,7 +240,7 @@ class PropertyCellTemplateBuilder<NodeT : ITypedNode, ConceptT : ITypedConcept>(
240240
}
241241
}
242242

243-
class ReferenceCellTemplateBuilder<SourceNodeT : ITypedNode, SourceConceptT : ITypedConcept, TargetNodeT : ITypedNode, TargetConceptT : ITypedConcept>(template: CellTemplate<SourceNodeT, SourceConceptT>, val link: GeneratedReferenceLink<TargetNodeT, TargetConceptT>) : CellTemplateBuilder<SourceNodeT, SourceConceptT>(
243+
class ReferenceCellTemplateBuilder<SourceNodeT : ITypedNode, SourceConceptT : ITypedConcept, TargetNodeT : ITypedNode>(template: CellTemplate<SourceNodeT, SourceConceptT>, val link: ITypedReferenceLink<TargetNodeT>) : CellTemplateBuilder<SourceNodeT, SourceConceptT>(
244244
template
245245
) {
246246
fun presentation(f: (TargetNodeT)->String?) {
@@ -249,7 +249,7 @@ class ReferenceCellTemplateBuilder<SourceNodeT : ITypedNode, SourceConceptT : IT
249249

250250
fun withTargetNode(body: WithTargetNodeContext.()->Unit) {
251251
withNode {
252-
val targetNode: ITypedNode? = node.unwrap().getReferenceTarget(link)?.let { it.typed() }
252+
val targetNode: ITypedNode? = node.unwrap().getReferenceTargetOrNull(link)
253253
if (targetNode != null) {
254254
body(WithTargetNodeContext(node, targetNode as TargetNodeT))
255255
}

editor-runtime/src/commonMain/kotlin/org/modelix/editor/ConceptEditor.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package org.modelix.editor
22

3-
import org.modelix.metamodel.GeneratedChildListLink
43
import org.modelix.metamodel.GeneratedConcept
5-
import org.modelix.metamodel.GeneratedSingleChildLink
4+
import org.modelix.metamodel.ITypedChildListLink
65
import org.modelix.metamodel.ITypedConcept
76
import org.modelix.metamodel.ITypedNode
7+
import org.modelix.metamodel.ITypedSingleChildLink
88
import org.modelix.metamodel.typed
99
import org.modelix.metamodel.untypedReference
1010
import org.modelix.model.api.serialize
@@ -41,8 +41,8 @@ val defaultConceptEditor = ConceptEditor(null) { subConcept ->
4141
newLine()
4242
label(link.name + ":")
4343
when (val l = link.typed()) {
44-
is GeneratedSingleChildLink -> l.cell()
45-
is GeneratedChildListLink -> {
44+
is ITypedSingleChildLink -> l.cell()
45+
is ITypedChildListLink -> {
4646
newLine()
4747
indented {
4848
l.vertical()

metamodel-generator/src/main/kotlin/org/modelix/metamodel/generator/MetaModelGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ fun String.nodeWrapperInterfaceName() = fqNamePrefix("N_")
449449
fun ConceptData.nodeWrapperImplName() = name.nodeWrapperImplName()
450450
fun String.nodeWrapperImplName() = fqNamePrefix("_N_TypedImpl_")
451451
fun ConceptData.conceptObjectName() = name.conceptObjectName()
452-
fun String.conceptObjectName() = fqNamePrefix("_C_Impl_")
452+
fun String.conceptObjectName() = fqNamePrefix("_C_UntypedImpl_")
453453
fun ConceptData.conceptWrapperImplName() = name.conceptWrapperImplName()
454454
fun String.conceptWrapperImplName() = fqNamePrefix("_C_TypedImpl_")
455455
fun ConceptData.conceptWrapperInterfaceName() = name.conceptWrapperInterfaceName()

metamodel-runtime/src/commonMain/kotlin/org/modelix/metamodel/GeneratedConcept.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ class GeneratedProperty<ValueT>(
165165

166166
override fun deserializeValue(serialized: String?): ValueT = serializer.deserialize(serialized)
167167
}
168+
fun IProperty.typed() = this as? ITypedProperty<*>
168169

169170
abstract class GeneratedChildLink<ChildNodeT : ITypedNode, ChildConceptT : ITypedConcept>(
170171
private val owner: IConcept,
@@ -189,15 +190,15 @@ abstract class GeneratedChildLink<ChildNodeT : ITypedNode, ChildConceptT : IType
189190
return childNode.typed(childNodeInterface)
190191
}
191192
}
192-
fun IChildLink.typed() = this as? GeneratedChildLink<ITypedNode, ITypedConcept>
193+
fun IChildLink.typed() = this as? ITypedChildLink<ITypedNode>
193194

194195
class GeneratedSingleChildLink<ChildNodeT : ITypedNode, ChildConceptT : ITypedConcept>(
195196
owner: IConcept,
196197
name: String,
197198
isOptional: Boolean,
198199
targetConcept: IConcept,
199200
childNodeInterface: KClass<ChildNodeT>
200-
) : GeneratedChildLink<ChildNodeT, ChildConceptT>(owner, name, false, isOptional, targetConcept, childNodeInterface) {
201+
) : GeneratedChildLink<ChildNodeT, ChildConceptT>(owner, name, false, isOptional, targetConcept, childNodeInterface), ITypedSingleChildLink<ChildNodeT> {
201202

202203
}
203204

@@ -207,7 +208,7 @@ class GeneratedChildListLink<ChildNodeT : ITypedNode, ChildConceptT : ITypedConc
207208
isOptional: Boolean,
208209
targetConcept: IConcept,
209210
childNodeInterface: KClass<ChildNodeT>
210-
) : GeneratedChildLink<ChildNodeT, ChildConceptT>(owner, name, true, isOptional, targetConcept, childNodeInterface) {
211+
) : GeneratedChildLink<ChildNodeT, ChildConceptT>(owner, name, true, isOptional, targetConcept, childNodeInterface), ITypedChildListLink<ChildNodeT> {
211212

212213
}
213214

@@ -229,5 +230,5 @@ class GeneratedReferenceLink<TargetNodeT : ITypedNode, TargetConceptT : ITypedCo
229230
return target.typed(targetNodeInterface)
230231
}
231232
}
232-
fun IReferenceLink.typed() = this as? GeneratedReferenceLink<ITypedNode, ITypedConcept>
233+
fun IReferenceLink.typed() = this as? ITypedReferenceLink<ITypedNode>
233234

metamodel-runtime/src/commonMain/kotlin/org/modelix/metamodel/ITypedChildLink.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ interface ITypedChildLink<ChildT : ITypedNode> : ITypedConceptFeature {
2424
fun castChild(childNode: INode): ChildT
2525
}
2626
interface ITypedSingleChildLink<ChildT : ITypedNode> : ITypedChildLink<ChildT>
27+
interface ITypedChildListLink<ChildT : ITypedNode> : ITypedChildLink<ChildT>
2728

2829
interface ITypedMandatorySingleChildLink<ChildT : ITypedNode> : ITypedSingleChildLink<ChildT>
2930

metamodel-runtime/src/commonMain/kotlin/org/modelix/metamodel/ITypedReferenceLink.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ interface ITypedReferenceLink<TargetT : ITypedNode?> : ITypedConceptFeature {
2222
fun untyped(): IReferenceLink
2323
fun castTarget(target: INode): TargetT
2424
}
25+
fun <TargetT : ITypedNode?> INode.getReferenceTargetOrNull(link: ITypedReferenceLink<TargetT>): TargetT? {
26+
return getReferenceTarget(link.untyped())?.let { link.castTarget(it) }
27+
}
2528
fun <TargetT : ITypedNode?> INode.getReferenceTarget(link: ITypedReferenceLink<TargetT>): TargetT {
26-
val rawTarget = getReferenceTarget(link.untyped())
27-
if (rawTarget == null && !link.untyped().isOptional) throw ReferenceNotSetException(this, link)
28-
return rawTarget?.let { link.castTarget(it) } as TargetT
29+
val target = getReferenceTargetOrNull(link)
30+
if (target == null && !link.untyped().isOptional) throw ReferenceNotSetException(this, link)
31+
return target as TargetT
2932
}
3033
fun <TargetT : ITypedNode?> INode.setReferenceTarget(link: ITypedReferenceLink<TargetT>, target: TargetT) {
3134
setReferenceTarget(link.untyped(), target?.unwrap())

0 commit comments

Comments
 (0)