diff options
author | 2018-01-30 01:29:00 +0100 | |
---|---|---|
committer | 2018-01-30 01:29:00 +0100 | |
commit | 2002dffe76957cbd1d45b7da5c678742053566bd (patch) | |
tree | 40b886b18a958cc9c60535277de741d6fe5c7fae /Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/validation/QueryAndMetamodelValidator.xtend | |
parent | Scoping + Linking services fixed (diff) | |
download | VIATRA-Generator-2002dffe76957cbd1d45b7da5c678742053566bd.tar.gz VIATRA-Generator-2002dffe76957cbd1d45b7da5c678742053566bd.tar.zst VIATRA-Generator-2002dffe76957cbd1d45b7da5c678742053566bd.zip |
Validators refactored
Diffstat (limited to 'Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/validation/QueryAndMetamodelValidator.xtend')
-rw-r--r-- | Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/validation/QueryAndMetamodelValidator.xtend | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/validation/QueryAndMetamodelValidator.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/validation/QueryAndMetamodelValidator.xtend new file mode 100644 index 00000000..0efd522b --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/validation/QueryAndMetamodelValidator.xtend | |||
@@ -0,0 +1,52 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.validation | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor | ||
4 | import hu.bme.mit.inf.dslreasoner.viatra2logic.ViatraQuerySetDescriptor | ||
5 | import java.util.LinkedList | ||
6 | import java.util.List | ||
7 | import java.util.Set | ||
8 | import org.eclipse.emf.ecore.ENamedElement | ||
9 | import org.eclipse.viatra.query.patternlanguage.patternLanguage.Pattern | ||
10 | |||
11 | class QueryAndMetamodelValidator { | ||
12 | |||
13 | def public validateQueryAndMetamodel( | ||
14 | EcoreMetamodelDescriptor metamodel, | ||
15 | Pair<ViatraQuerySetDescriptor, Set<Pattern>> viatra) | ||
16 | { | ||
17 | val patterns = viatra.value | ||
18 | val elementsInMetamodel = | ||
19 | (metamodel.classes + | ||
20 | metamodel.enums + | ||
21 | metamodel.literals+ | ||
22 | metamodel.attributes + | ||
23 | metamodel.references) | ||
24 | .toSet | ||
25 | val errors = new LinkedList | ||
26 | for(pattern : patterns) { | ||
27 | val elements = getReferredNamedElements(pattern) | ||
28 | for(element : elements) { | ||
29 | if(!elementsInMetamodel.contains(element)) { | ||
30 | errors+='''Pattern "«pattern.name»" refers to an element "«element»" that is not included to the selected metamodel!''' | ||
31 | } | ||
32 | } | ||
33 | } | ||
34 | return errors | ||
35 | } | ||
36 | |||
37 | def getReferredNamedElements(Pattern pattern) { | ||
38 | val elements = pattern.eAllContents.toList | ||
39 | return elements.map[element| | ||
40 | val references = element.eClass.EAllReferences | ||
41 | return references.map[r | | ||
42 | if(r.isMany) { | ||
43 | return (element.eGet(r) as List<?>).filter(ENamedElement) | ||
44 | } else { | ||
45 | val value = element.eGet(r) | ||
46 | if(value instanceof ENamedElement) return #[value] | ||
47 | else return #[] | ||
48 | } | ||
49 | ].flatten.filter(ENamedElement) | ||
50 | ].flatten | ||
51 | } | ||
52 | } \ No newline at end of file | ||