aboutsummaryrefslogtreecommitdiffstats
path: root/Domains/hu.bme.mit.inf.yakinduModelExtractor/src/hu/bme/mit/inf/yakinduModelExtractor/Yakindu2CommonModel.xtend
diff options
context:
space:
mode:
authorLibravatar OszkarSemerath <oszka@152.66.252.189>2017-06-21 18:44:04 +0200
committerLibravatar OszkarSemerath <oszka@152.66.252.189>2017-06-21 18:44:04 +0200
commitcf0c50e4fedf219f79a462615bb0ba603ce99378 (patch)
treea87bfbd1b2cd77c66ef1ab2106f9a9295cf97cfb /Domains/hu.bme.mit.inf.yakinduModelExtractor/src/hu/bme/mit/inf/yakinduModelExtractor/Yakindu2CommonModel.xtend
parentgenerated code for the newly added types (diff)
downloadVIATRA-Generator-cf0c50e4fedf219f79a462615bb0ba603ce99378.tar.gz
VIATRA-Generator-cf0c50e4fedf219f79a462615bb0ba603ce99378.tar.zst
VIATRA-Generator-cf0c50e4fedf219f79a462615bb0ba603ce99378.zip
Model translator and sanitiser from original yakindu files to simplified
metamodel. Added a sample Main function.
Diffstat (limited to 'Domains/hu.bme.mit.inf.yakinduModelExtractor/src/hu/bme/mit/inf/yakinduModelExtractor/Yakindu2CommonModel.xtend')
-rw-r--r--Domains/hu.bme.mit.inf.yakinduModelExtractor/src/hu/bme/mit/inf/yakinduModelExtractor/Yakindu2CommonModel.xtend82
1 files changed, 82 insertions, 0 deletions
diff --git a/Domains/hu.bme.mit.inf.yakinduModelExtractor/src/hu/bme/mit/inf/yakinduModelExtractor/Yakindu2CommonModel.xtend b/Domains/hu.bme.mit.inf.yakinduModelExtractor/src/hu/bme/mit/inf/yakinduModelExtractor/Yakindu2CommonModel.xtend
new file mode 100644
index 00000000..d9219d5a
--- /dev/null
+++ b/Domains/hu.bme.mit.inf.yakinduModelExtractor/src/hu/bme/mit/inf/yakinduModelExtractor/Yakindu2CommonModel.xtend
@@ -0,0 +1,82 @@
1package hu.bme.mit.inf.yakinduModelExtractor
2
3import org.yakindu.sct.model.sgraph.Statechart
4import org.yakindu.sct.model.sgraph.SGraphPackage
5import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.YakindummPackage
6import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.YakindummFactory
7import org.eclipse.emf.ecore.EObject
8import org.eclipse.emf.ecore.EClass
9import java.util.HashMap
10import org.eclipse.emf.ecore.EReference
11import java.util.List
12
13class Yakindu2CommonModel {
14 val yakinduSGraphPackage = org.yakindu.sct.model.sgraph.SGraphPackage.eINSTANCE
15 val commonSGraphPackage = YakindummPackage.eINSTANCE
16 val extension YakindummFactory factory = YakindummFactory.eINSTANCE
17
18 def transform(Statechart s) {
19 val o2o = new HashMap
20 o2o.put(s,s.copyObject)
21 for(content: s.eAllContents.toIterable) {
22 val copied = content.copyObject
23 if(copied !== null) {
24 o2o.put(content,copied)
25 }
26 }
27
28 for(sourceObjectEntry : o2o.entrySet) {
29 val originalSource = sourceObjectEntry.key
30 val copiedSource = sourceObjectEntry.value
31 for(originalReference : originalSource.eClass.EAllReferences) {
32 if(originalReference.isMany) {
33 val originalTargets = originalSource.eGet(originalReference) as List<? extends EObject>
34 for(originalTarget : originalTargets) {
35 if(o2o.containsKey(originalTarget)) {
36 copyReference(originalReference,copiedSource,o2o.get(originalTarget))
37 }
38 }
39 } else {
40 val originalTarget = originalSource.eGet(originalReference) as EObject
41 if(o2o.containsKey(originalTarget)) {
42 copyReference(originalReference,copiedSource,o2o.get(originalTarget))
43 }
44 }
45 }
46 }
47 return o2o.get(s)
48 }
49
50 def private copyObject(EObject o) {
51 if(o.createCopy) {
52 val className = o.eClass.name
53 //if(className =="Exit") println("Exit")
54 val correspondingClass = commonSGraphPackage.EClassifiers.filter(EClass).filter[it.name == className].head
55 if(correspondingClass != null) {
56 return factory.create(correspondingClass)
57 } else {
58 println(className)
59 return null
60 }
61 }
62 else return null
63 }
64
65 def private copyReference(EReference reference, EObject source, EObject target) {
66 val correspondingSourceClass = commonSGraphPackage.EClassifiers.filter(EClass).filter[it.name == reference.EContainingClass.name].head
67 if(correspondingSourceClass !== null) {
68 val correspondingReference = correspondingSourceClass.EReferences.filter[it.name === reference.name].head
69 if(correspondingReference !== null) {
70 if(correspondingReference.isMany) {
71 (source.eGet(correspondingReference) as List<? super EObject>).add(target)
72 } else {
73 source.eSet(correspondingReference,target);
74 }
75 }
76 }
77 }
78
79 def private createCopy(EObject o) {
80 o.eClass.EPackage === yakinduSGraphPackage
81 }
82} \ No newline at end of file