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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
|
package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.rules
import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.InverseRelationAssertion
import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.LowerMultiplicityAssertion
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.BoolTypeReference
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.ComplexTypeReference
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.IntTypeReference
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguageFactory
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.PrimitiveTypeReference
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealTypeReference
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.StringTypeReference
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type
import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem
import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.ModelGenerationStatistics
import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.ScopePropagator
import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.GeneratedPatterns
import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns.ObjectCreationPrecondition
import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialBooleanInterpretation
import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation
import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialIntegerInterpretation
import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation
import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRealInterpretation
import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation
import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialStringInterpretation
import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialTypeInterpratation
import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationFactory
import java.lang.reflect.Field
import java.util.HashMap
import java.util.LinkedHashMap
import java.util.LinkedList
import java.util.List
import java.util.Map
import org.eclipse.viatra.query.runtime.api.AdvancedViatraQueryEngine
import org.eclipse.viatra.query.runtime.api.GenericPatternMatch
import org.eclipse.viatra.query.runtime.api.IQuerySpecification
import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine
import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher
import org.eclipse.viatra.query.runtime.emf.EMFScope
import org.eclipse.viatra.query.runtime.rete.matcher.ReteBackendFactory
import org.eclipse.viatra.transformation.runtime.emf.rules.batch.BatchTransformationRule
import org.eclipse.viatra.transformation.runtime.emf.rules.batch.BatchTransformationRuleFactory
import org.eclipse.xtend.lib.annotations.Data
import org.eclipse.xtext.xbase.lib.Functions.Function0
class RefinementRuleProvider {
val extension BatchTransformationRuleFactory factory = new BatchTransformationRuleFactory
val extension PartialinterpretationFactory factory2 = PartialinterpretationFactory.eINSTANCE
val extension LogiclanguageFactory factory3 = LogiclanguageFactory.eINSTANCE
var AdvancedViatraQueryEngine queryEngine
var Field delayMessageDelivery
def canonizeName(String name) {
return name.replace(' ', '_')
}
def LinkedHashMap<ObjectCreationPrecondition, BatchTransformationRule<GenericPatternMatch, ViatraQueryMatcher<GenericPatternMatch>>> createObjectRefinementRules(
LogicProblem p,
PartialInterpretation i,
GeneratedPatterns patterns,
ScopePropagator scopePropagator,
boolean nameNewElement,
ModelGenerationStatistics statistics
) {
val res = new LinkedHashMap
val recursiveObjectCreation = recursiveObjectCreation(p, i)
queryEngine = ViatraQueryEngine.on(new EMFScope(i)) as AdvancedViatraQueryEngine
delayMessageDelivery = queryEngine.class.getDeclaredField("delayMessageDelivery")
delayMessageDelivery.accessible = true
for (LHSEntry : patterns.refineObjectQueries.entrySet) {
val containmentRelation = LHSEntry.key.containmentRelation
val inverseRelation = LHSEntry.key.inverseContainment
val type = LHSEntry.key.newType
val lhs = LHSEntry.value as IQuerySpecification<ViatraQueryMatcher<GenericPatternMatch>>
val rule = createObjectCreationRule(p, containmentRelation, inverseRelation, type,
recursiveObjectCreation.get(type), lhs, nameNewElement, scopePropagator, statistics)
res.put(LHSEntry.key, rule)
}
return res
}
def private createObjectCreationRule(LogicProblem p, Relation containmentRelation, Relation inverseRelation,
Type type, List<ObjectCreationInterpretationData> recursiceObjectCreations,
IQuerySpecification<ViatraQueryMatcher<GenericPatternMatch>> lhs, boolean nameNewElement,
ScopePropagator scopePropagator, ModelGenerationStatistics statistics) {
val name = '''addObject_«type.name.canonizeName»«IF containmentRelation!==null»_by_«containmentRelation.name.canonizeName»«ENDIF»'''
val ruleBuilder = factory.createRule(lhs).name(name)
if (containmentRelation !== null) {
if (inverseRelation !== null) {
ruleBuilder.action [ match |
statistics.incrementTransformationCount
// println(name)
// val problem = match.get(0) as LogicProblem
val interpretation = match.get(1) as PartialInterpretation
val relationInterpretation = match.get(2) as PartialRelationInterpretation
val inverseRelationInterpretation = match.get(3) as PartialRelationInterpretation
val typeInterpretation = match.get(4) as PartialComplexTypeInterpretation
val container = match.get(5) as DefinedElement
val startTime = System.nanoTime
createObjectActionWithContainmentAndInverse(
nameNewElement,
interpretation,
typeInterpretation,
container,
relationInterpretation,
inverseRelationInterpretation,
[createDefinedElement],
recursiceObjectCreations,
scopePropagator
)
statistics.addExecutionTime(System.nanoTime - startTime)
flushQueryEngine
// Scope propagation
val propagatorStartTime = System.nanoTime
scopePropagator.propagateAllScopeConstraints()
statistics.addScopePropagationTime(System.nanoTime - propagatorStartTime)
]
} else {
ruleBuilder.action [ match |
statistics.incrementTransformationCount
// println(name)
// val problem = match.get(0) as LogicProblem
val interpretation = match.get(1) as PartialInterpretation
val relationInterpretation = match.get(2) as PartialRelationInterpretation
val typeInterpretation = match.get(3) as PartialComplexTypeInterpretation
val container = match.get(4) as DefinedElement
val startTime = System.nanoTime
createObjectActionWithContainment(
nameNewElement,
interpretation,
typeInterpretation,
container,
relationInterpretation,
[createDefinedElement],
recursiceObjectCreations,
scopePropagator
)
statistics.addExecutionTime(System.nanoTime - startTime)
flushQueryEngine
// Scope propagation
val propagatorStartTime = System.nanoTime
scopePropagator.propagateAllScopeConstraints()
statistics.addScopePropagationTime(System.nanoTime - propagatorStartTime)
]
}
} else {
ruleBuilder.action [ match |
statistics.incrementTransformationCount
// println(name)
// val problem = match.get(0) as LogicProblem
val interpretation = match.get(1) as PartialInterpretation
val typeInterpretation = match.get(2) as PartialComplexTypeInterpretation
val startTime = System.nanoTime
createObjectAction(
nameNewElement,
interpretation,
typeInterpretation,
[createDefinedElement],
recursiceObjectCreations,
scopePropagator
)
statistics.addExecutionTime(System.nanoTime - startTime)
flushQueryEngine
// Scope propagation
val propagatorStartTime = System.nanoTime
scopePropagator.propagateAllScopeConstraints()
statistics.addScopePropagationTime(System.nanoTime - propagatorStartTime)
]
}
return ruleBuilder.build
}
def private recursiveObjectCreation(LogicProblem p, PartialInterpretation i) {
val Map<Type, List<ObjectCreationInterpretationData>> recursiveObjectCreation = new HashMap
for (type : p.types) {
recursiveObjectCreation.put(type, new LinkedList)
}
val containmentReferences = p.containmentHierarchies.head.containmentRelations
for (relationInterpretation : i.partialrelationinterpretation) {
val relation = relationInterpretation.interpretationOf
val lowermultiplicities = p.annotations.filter(LowerMultiplicityAssertion).filter[it.relation === relation]
if ((!lowermultiplicities.empty)) {
val number = lowermultiplicities.head.lower
if (number > 0) {
val sourceTypeInterpretation = getTypeInterpretation(i, relation,
0) as PartialComplexTypeInterpretation
val subtypeInterpretations = i.partialtypeinterpratation.filter(PartialComplexTypeInterpretation).
filter [
it === sourceTypeInterpretation ||
it.supertypeInterpretation.contains(sourceTypeInterpretation)
]
if (containmentReferences.contains(relation)) {
val targetTypeInterpretation = getTypeInterpretation(i, relation, 1)
val targetType = (targetTypeInterpretation as PartialComplexTypeInterpretation).interpretationOf
if ((!targetType.isIsAbstract) && (targetType.supertypes.empty)) {
val inverseAnnotation = p.annotations.filter(InverseRelationAssertion).filter [
it.inverseA === relation || it.inverseB === relation
]
if (!inverseAnnotation.empty) {
val onlyInverseAnnotation = if (inverseAnnotation.head.inverseA === relation) {
inverseAnnotation.head.inverseB
} else {
inverseAnnotation.head.inverseA
}
val inverseRelationInterpretation = i.partialrelationinterpretation.filter [
it.interpretationOf === onlyInverseAnnotation
].head
for (subTypeInterpretation : subtypeInterpretations) {
for (var times = 0; times < number; times++) {
recursiveObjectCreation.get(subTypeInterpretation.interpretationOf) +=
new ObjectCreationInterpretationData(
i,
targetTypeInterpretation,
relationInterpretation,
inverseRelationInterpretation,
targetTypeInterpretation.getTypeConstructor
)
}
}
} else {
for (subTypeInterpretation : subtypeInterpretations) {
for (var times = 0; times < number; times++) {
recursiveObjectCreation.get(subTypeInterpretation.interpretationOf) +=
new ObjectCreationInterpretationData(
i,
targetTypeInterpretation,
relationInterpretation,
null,
targetTypeInterpretation.getTypeConstructor
)
}
}
}
}
} else if (relation.parameters.get(1) instanceof PrimitiveTypeReference) {
val targetTypeInterpretation = getTypeInterpretation(i, relation, 1)
for (subTypeInterpretation : subtypeInterpretations) {
for (var times = 0; times < number; times++) {
recursiveObjectCreation.get(subTypeInterpretation.interpretationOf) +=
new ObjectCreationInterpretationData(
i,
targetTypeInterpretation,
relationInterpretation,
null,
targetTypeInterpretation.getTypeConstructor
)
}
}
}
}
}
}
// Doing the recursion
var objectCreations = new LinkedList(recursiveObjectCreation.values.flatten.toList)
for (objectCreation : objectCreations) {
val newInterpretation = objectCreation.typeInterpretation
if (newInterpretation instanceof PartialComplexTypeInterpretation) {
val newlyCreatedType = newInterpretation.interpretationOf
if (recursiveObjectCreation.containsKey(newlyCreatedType)) {
val actionsWhenTypeCreated = recursiveObjectCreation.get(newlyCreatedType)
objectCreation.recursiveConstructors += actionsWhenTypeCreated
}
}
}
// checking acyclicity
for (objectCreation : objectCreations) {
var reachable = objectCreation.recursiveConstructors
do {
if (reachable.contains(objectCreation)) {
throw new IllegalArgumentException('''Cicrle in the containment!''')
} else {
reachable = reachable.map[it.recursiveConstructors].flatten.toList
}
} while (!reachable.empty)
}
return recursiveObjectCreation
}
private def getTypeInterpretation(PartialInterpretation i, RelationDeclaration relation, int index) {
val typeReference = relation.parameters.get(index)
return getTypeInterpretation(i, typeReference)
}
private dispatch def getTypeInterpretation(PartialInterpretation i, ComplexTypeReference reference) {
return i.partialtypeinterpratation.filter(PartialComplexTypeInterpretation).filter [
it.getInterpretationOf == reference.referred
].head
}
private dispatch def getTypeInterpretation(PartialInterpretation i, BoolTypeReference reference) {
return i.partialtypeinterpratation.filter(PartialBooleanInterpretation).head
}
private dispatch def getTypeInterpretation(PartialInterpretation i, IntTypeReference reference) {
return i.partialtypeinterpratation.filter(PartialIntegerInterpretation).head
}
private dispatch def getTypeInterpretation(PartialInterpretation i, RealTypeReference reference) {
return i.partialtypeinterpratation.filter(PartialRealInterpretation).head
}
private dispatch def getTypeInterpretation(PartialInterpretation i, StringTypeReference reference) {
return i.partialtypeinterpratation.filter(PartialStringInterpretation).head
}
private dispatch def Function0<DefinedElement> getTypeConstructor(PartialComplexTypeInterpretation reference) {
[createDefinedElement]
}
private dispatch def Function0<DefinedElement> getTypeConstructor(PartialBooleanInterpretation reference) {
[createBooleanElement]
}
private dispatch def Function0<DefinedElement> getTypeConstructor(PartialIntegerInterpretation reference) {
[createIntegerElement]
}
private dispatch def Function0<DefinedElement> getTypeConstructor(PartialRealInterpretation reference) {
[createRealElement]
}
private dispatch def Function0<DefinedElement> getTypeConstructor(PartialStringInterpretation reference) {
[createStringElement]
}
def createRelationRefinementRules(GeneratedPatterns patterns, ScopePropagator scopePropagator,
ModelGenerationStatistics statistics) {
val res = new LinkedHashMap
for (LHSEntry : patterns.refinerelationQueries.entrySet) {
val declaration = LHSEntry.key.key
val inverseReference = LHSEntry.key.value
val lhs = LHSEntry.value as IQuerySpecification<ViatraQueryMatcher<GenericPatternMatch>>
val rule = createRelationRefinementRule(declaration, inverseReference, lhs, scopePropagator, statistics)
res.put(LHSEntry.key, rule)
}
return res
}
def private BatchTransformationRule<GenericPatternMatch, ViatraQueryMatcher<GenericPatternMatch>> createRelationRefinementRule(
RelationDeclaration declaration, Relation inverseRelation,
IQuerySpecification<ViatraQueryMatcher<GenericPatternMatch>> lhs, ScopePropagator scopePropagator,
ModelGenerationStatistics statistics) {
val name = '''addRelation_«declaration.name.canonizeName»«IF inverseRelation !== null»_and_«inverseRelation.name.canonizeName»«ENDIF»'''
val ruleBuilder = factory.createRule(lhs).name(name)
if (inverseRelation === null) {
ruleBuilder.action [ match |
statistics.incrementTransformationCount
// println(name)
// val problem = match.get(0) as LogicProblem
// val interpretation = match.get(1) as PartialInterpretation
val relationInterpretation = match.get(2) as PartialRelationInterpretation
val src = match.get(3) as DefinedElement
val trg = match.get(4) as DefinedElement
queryEngine.delayUpdatePropagation [
val startTime = System.nanoTime
createRelationLinkAction(src, trg, relationInterpretation)
statistics.addExecutionTime(System.nanoTime - startTime)
]
// Scope propagation
if (scopePropagator.isPropagationNeededAfterAdditionToRelation(declaration)) {
queryEngine.delayUpdatePropagation [
val propagatorStartTime = System.nanoTime
scopePropagator.propagateAllScopeConstraints()
statistics.addScopePropagationTime(System.nanoTime - propagatorStartTime)
]
}
]
} else {
ruleBuilder.action [ match |
statistics.incrementTransformationCount
// println(name)
// val problem = match.get(0) as LogicProblem
// val interpretation = match.get(1) as PartialInterpretation
val relationInterpretation = match.get(2) as PartialRelationInterpretation
val inverseInterpretation = match.get(3) as PartialRelationInterpretation
val src = match.get(4) as DefinedElement
val trg = match.get(5) as DefinedElement
val startTime = System.nanoTime
createRelationLinkWithInverse(src, trg, relationInterpretation, inverseInterpretation)
statistics.addExecutionTime(System.nanoTime - startTime)
// Scope propagation
if (scopePropagator.isPropagationNeededAfterAdditionToRelation(declaration)) {
flushQueryEngine
val propagatorStartTime = System.nanoTime
scopePropagator.propagateAllScopeConstraints()
statistics.addScopePropagationTime(System.nanoTime - propagatorStartTime)
}
]
}
return ruleBuilder.build
}
// ///////////////////////
// Actions
// ///////////////////////
protected def void createObjectAction(boolean nameNewElement, ObjectCreationInterpretationData data,
DefinedElement container, ScopePropagator scopePropagator) {
if (data.containerInterpretation !== null) {
if (data.containerInverseInterpretation !== null) {
createObjectActionWithContainmentAndInverse(
nameNewElement,
data.interpretation,
data.typeInterpretation,
container,
data.containerInterpretation,
data.containerInverseInterpretation,
data.constructor,
data.recursiveConstructors,
scopePropagator
)
} else {
createObjectActionWithContainment(
nameNewElement,
data.interpretation,
data.typeInterpretation,
container,
data.containerInterpretation,
data.constructor,
data.recursiveConstructors,
scopePropagator
)
}
} else {
createObjectAction(
nameNewElement,
data.interpretation,
data.typeInterpretation,
data.constructor,
data.recursiveConstructors,
scopePropagator
)
}
}
protected def createObjectActionWithContainmentAndInverse(
boolean nameNewElement,
PartialInterpretation interpretation,
PartialTypeInterpratation typeInterpretation,
DefinedElement container,
PartialRelationInterpretation relationInterpretation,
PartialRelationInterpretation inverseRelationInterpretation,
Function0<DefinedElement> constructor,
List<ObjectCreationInterpretationData> recursiceObjectCreations,
ScopePropagator scopePropagator
) {
val newElement = constructor.apply
if (nameNewElement) {
newElement.name = '''new «interpretation.newElements.size»'''
}
// Types
typeInterpretation.elements += newElement
if (typeInterpretation instanceof PartialComplexTypeInterpretation) {
typeInterpretation.supertypeInterpretation.forEach[it.elements += newElement]
}
// ContainmentRelation
val newLink1 = factory2.createBinaryElementRelationLink => [it.param1 = container it.param2 = newElement]
relationInterpretation.relationlinks += newLink1
// Inverse Containment
val newLink2 = factory2.createBinaryElementRelationLink => [it.param1 = newElement it.param2 = container]
inverseRelationInterpretation.relationlinks += newLink2
// Scope propagation
scopePropagator.decrementTypeScope(typeInterpretation)
// Existence
interpretation.newElements += newElement
// Do recursive object creation
for (newConstructor : recursiceObjectCreations) {
createObjectAction(nameNewElement, newConstructor, newElement, scopePropagator)
}
return newElement
}
protected def createObjectActionWithContainment(
boolean nameNewElement,
PartialInterpretation interpretation,
PartialTypeInterpratation typeInterpretation,
DefinedElement container,
PartialRelationInterpretation relationInterpretation,
Function0<DefinedElement> constructor,
List<ObjectCreationInterpretationData> recursiceObjectCreations,
ScopePropagator scopePropagator
) {
val newElement = constructor.apply
if (nameNewElement) {
newElement.name = '''new «interpretation.newElements.size»'''
}
// Types
typeInterpretation.elements += newElement
if (typeInterpretation instanceof PartialComplexTypeInterpretation) {
typeInterpretation.supertypeInterpretation.forEach[it.elements += newElement]
}
// ContainmentRelation
val newLink = factory2.createBinaryElementRelationLink => [it.param1 = container it.param2 = newElement]
relationInterpretation.relationlinks += newLink
// Scope propagation
scopePropagator.decrementTypeScope(typeInterpretation)
// Existence
interpretation.newElements += newElement
// Do recursive object creation
for (newConstructor : recursiceObjectCreations) {
createObjectAction(nameNewElement, newConstructor, newElement, scopePropagator)
}
return newElement
}
protected def createObjectAction(boolean nameNewElement, PartialInterpretation interpretation,
PartialTypeInterpratation typeInterpretation, Function0<DefinedElement> constructor,
List<ObjectCreationInterpretationData> recursiceObjectCreations, ScopePropagator scopePropagator) {
val newElement = constructor.apply
if (nameNewElement) {
newElement.name = '''new «interpretation.newElements.size»'''
}
// Types
typeInterpretation.elements += newElement
if (typeInterpretation instanceof PartialComplexTypeInterpretation) {
typeInterpretation.supertypeInterpretation.forEach[it.elements += newElement]
}
// Scope propagation
scopePropagator.decrementTypeScope(typeInterpretation)
// Existence
interpretation.newElements += newElement
// Do recursive object creation
for (newConstructor : recursiceObjectCreations) {
createObjectAction(nameNewElement, newConstructor, newElement, scopePropagator)
}
return newElement
}
protected def boolean createRelationLinkAction(DefinedElement src, DefinedElement trg,
PartialRelationInterpretation relationInterpretation) {
val link = createBinaryElementRelationLink => [it.param1 = src it.param2 = trg]
relationInterpretation.relationlinks += link
}
protected def boolean createRelationLinkWithInverse(DefinedElement src, DefinedElement trg,
PartialRelationInterpretation relationInterpretation, PartialRelationInterpretation inverseInterpretation) {
val link = createBinaryElementRelationLink => [it.param1 = src it.param2 = trg]
relationInterpretation.relationlinks += link
val inverseLink = createBinaryElementRelationLink => [it.param1 = trg it.param2 = src]
inverseInterpretation.relationlinks += inverseLink
}
protected def flushQueryEngine() {
if (queryEngine.updatePropagationDelayed) {
delayMessageDelivery.setBoolean(queryEngine, false)
queryEngine.getQueryBackend(ReteBackendFactory.INSTANCE).flushUpdates
delayMessageDelivery.setBoolean(queryEngine, true)
}
}
}
@Data
class ObjectCreationInterpretationData {
PartialInterpretation interpretation
PartialTypeInterpratation typeInterpretation
PartialRelationInterpretation containerInterpretation
PartialRelationInterpretation containerInverseInterpretation
Function0<DefinedElement> constructor
List<ObjectCreationInterpretationData> recursiveConstructors = new LinkedList
}
|