diff options
author | 2017-07-05 14:03:32 +0200 | |
---|---|---|
committer | 2017-07-05 14:03:32 +0200 | |
commit | 94c8f0eb155b624b07b92db2504dd17991be3f0f (patch) | |
tree | e8871f5f5458092e9185355f787fa5ff26709225 /Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner/logic2ecore | |
parent | When there is a definition to a declaration in the logic problem, the (diff) | |
download | VIATRA-Generator-94c8f0eb155b624b07b92db2504dd17991be3f0f.tar.gz VIATRA-Generator-94c8f0eb155b624b07b92db2504dd17991be3f0f.tar.zst VIATRA-Generator-94c8f0eb155b624b07b92db2504dd17991be3f0f.zip |
full Ecore -> Logic -> Ecore support
Diffstat (limited to 'Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner/logic2ecore')
-rw-r--r-- | Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner/logic2ecore/Logic2Ecore.xtend | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner/logic2ecore/Logic2Ecore.xtend b/Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner/logic2ecore/Logic2Ecore.xtend index 2ab7091e..65328a3a 100644 --- a/Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner/logic2ecore/Logic2Ecore.xtend +++ b/Framework/hu.bme.mit.inf.dslreasoner.logic2ecore/src/hu/bme/mit/inf/dslreasoner/logic2ecore/Logic2Ecore.xtend | |||
@@ -14,6 +14,7 @@ import java.util.Set | |||
14 | import org.eclipse.emf.ecore.EObject | 14 | import org.eclipse.emf.ecore.EObject |
15 | import java.util.List | 15 | import java.util.List |
16 | import java.util.Collection | 16 | import java.util.Collection |
17 | import org.eclipse.emf.ecore.EStructuralFeature | ||
17 | 18 | ||
18 | class Logic2Ecore { | 19 | class Logic2Ecore { |
19 | private val extension LogicProblemBuilder problemBuilder = new LogicProblemBuilder | 20 | private val extension LogicProblemBuilder problemBuilder = new LogicProblemBuilder |
@@ -29,7 +30,6 @@ class Logic2Ecore { | |||
29 | val elements = new HashSet | 30 | val elements = new HashSet |
30 | val element2Classes = new HashMap | 31 | val element2Classes = new HashMap |
31 | 32 | ||
32 | |||
33 | for(clazz: allClasses) { | 33 | for(clazz: allClasses) { |
34 | val type = ecore2Logic.TypeofEClass(forwardTrace,clazz); | 34 | val type = ecore2Logic.TypeofEClass(forwardTrace,clazz); |
35 | val elementsOfClass = getElements(interpretation,type) | 35 | val elementsOfClass = getElements(interpretation,type) |
@@ -48,20 +48,22 @@ class Logic2Ecore { | |||
48 | 48 | ||
49 | val allReferences = ecore2Logic.allReferencesInScope(forwardTrace) | 49 | val allReferences = ecore2Logic.allReferencesInScope(forwardTrace) |
50 | for(referenceType : allReferences) { | 50 | for(referenceType : allReferences) { |
51 | for(sourceElement : elements) { | 51 | if(referenceType.canSetFeature) { |
52 | val sourceObject = sourceElement.lookup(element2Object) | 52 | for(sourceElement : elements) { |
53 | if(sourceObject.eClass.isSuperTypeOf(referenceType.EContainingClass)) { | 53 | val sourceObject = sourceElement.lookup(element2Object) |
54 | for(targetElement: elements) { | 54 | if(referenceType.EContainingClass.isSuperTypeOf(sourceObject.eClass)) { |
55 | val targetObject = targetElement.lookup(element2Object) | 55 | for(targetElement: elements) { |
56 | if(targetObject.eClass.isSuperTypeOf(referenceType.EReferenceType)) { | 56 | val targetObject = targetElement.lookup(element2Object) |
57 | val expression = ecore2Logic.IsInReference(forwardTrace,sourceElement,targetElement,referenceType) | 57 | if(referenceType.EReferenceType.isSuperTypeOf(targetObject.eClass)) { |
58 | val linkExist = interpretation.evalAsBool(expression) | 58 | val expression = ecore2Logic.IsInReference(forwardTrace,sourceElement,targetElement,referenceType) |
59 | if(linkExist) { | 59 | val linkExist = interpretation.evalAsBool(expression) |
60 | if(referenceType.isMany) { | 60 | if(linkExist) { |
61 | val list = sourceObject.eGet(referenceType) as List<? super EObject> | 61 | if(referenceType.isMany) { |
62 | list+= targetObject | 62 | val list = sourceObject.eGet(referenceType) as List<? super EObject> |
63 | } else { | 63 | list+= targetObject |
64 | sourceObject.eSet(referenceType,targetObject) | 64 | } else { |
65 | sourceObject.eSet(referenceType,targetObject) | ||
66 | } | ||
65 | } | 67 | } |
66 | } | 68 | } |
67 | } | 69 | } |
@@ -70,11 +72,15 @@ class Logic2Ecore { | |||
70 | } | 72 | } |
71 | } | 73 | } |
72 | 74 | ||
73 | /// Attributes | 75 | /// + Attributes |
74 | 76 | ||
75 | return element2Object.values.root | 77 | return element2Object.values.root |
76 | } | 78 | } |
77 | 79 | ||
80 | private def canSetFeature(EStructuralFeature feature) { | ||
81 | feature.changeable && !feature.derived | ||
82 | } | ||
83 | |||
78 | def mostConcreteType(Set<EClass> classes) { | 84 | def mostConcreteType(Set<EClass> classes) { |
79 | for(candidate : classes) { | 85 | for(candidate : classes) { |
80 | val subtypeOfAll = classes.forall[it.isSuperTypeOf(candidate)] | 86 | val subtypeOfAll = classes.forall[it.isSuperTypeOf(candidate)] |
@@ -86,6 +92,11 @@ class Logic2Ecore { | |||
86 | } | 92 | } |
87 | 93 | ||
88 | def getRoot(Collection<EObject> objects) { | 94 | def getRoot(Collection<EObject> objects) { |
89 | objects.filter[eContainer === null].head | 95 | val rootCandidates = objects.filter[eContainer === null] |
96 | if(rootCandidates.size == 1) { | ||
97 | return rootCandidates.head | ||
98 | } else { | ||
99 | throw new AssertionError("Multiple root objects") | ||
100 | } | ||
90 | } | 101 | } |
91 | } \ No newline at end of file | 102 | } \ No newline at end of file |