diff options
Diffstat (limited to 'Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf')
3 files changed, 142 insertions, 0 deletions
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/validation/MetamodelValidator.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/validation/MetamodelValidator.xtend new file mode 100644 index 00000000..fccc433a --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/validation/MetamodelValidator.xtend | |||
@@ -0,0 +1,76 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.validation | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor | ||
4 | import java.util.LinkedList | ||
5 | import java.util.List | ||
6 | import org.eclipse.emf.ecore.EAttribute | ||
7 | import org.eclipse.emf.ecore.EClass | ||
8 | import org.eclipse.emf.ecore.EDataType | ||
9 | import org.eclipse.emf.ecore.EEnum | ||
10 | import org.eclipse.emf.ecore.EEnumLiteral | ||
11 | import org.eclipse.emf.ecore.EReference | ||
12 | import org.eclipse.emf.ecore.EcorePackage | ||
13 | |||
14 | class MetamodelValidator { | ||
15 | def validateMetamodel(EcoreMetamodelDescriptor descriptor) { | ||
16 | val errors = new LinkedList | ||
17 | this.allSupertypesAreIncluded(descriptor.classes,errors) | ||
18 | this.allEnumTypesareIncluded(descriptor.enums,descriptor.literals,errors) | ||
19 | this.referenceEndpointsAreIncluded(descriptor.classes,descriptor.references,errors) | ||
20 | this.attributeSourcePontIsIncluded(descriptor.classes,descriptor.attributes,errors) | ||
21 | this.attributeTargetIsSupported(descriptor.attributes,errors) | ||
22 | return errors | ||
23 | } | ||
24 | |||
25 | |||
26 | private def supportedEDataType(EDataType dataType) { | ||
27 | val extension l = EcorePackage.eINSTANCE | ||
28 | return #[EInt, EBoolean, EString, EDouble, EFloat].contains(dataType) | ||
29 | } | ||
30 | |||
31 | def allSupertypesAreIncluded(List<EClass> classes, List<String> errors) { | ||
32 | for(c : classes) { | ||
33 | for(s : c.ESuperTypes) { | ||
34 | if(!classes.contains(s)) { | ||
35 | errors.add('''Metamodel contains "«c.name»" but not contains its supertype "«s.name»"!''') | ||
36 | } | ||
37 | } | ||
38 | } | ||
39 | } | ||
40 | def allEnumTypesareIncluded(List<EEnum> enums, List<EEnumLiteral> literals, List<String> errors) { | ||
41 | for(l: literals) { | ||
42 | if(!enums.contains(l.EEnum)) { | ||
43 | errors.add('''Metamodel contains literal "«l.name»" but does not contains enum "«l.EEnum.name»"!''') | ||
44 | } | ||
45 | } | ||
46 | } | ||
47 | def referenceEndpointsAreIncluded(List<EClass> classes, List<EReference> references, List<String> errors) { | ||
48 | for(reference : references) { | ||
49 | val src = reference.EContainingClass | ||
50 | if(!classes.contains(src)) { | ||
51 | errors.add('''Metamodel contains reference "«reference.name»" but does not contains its source type "«src.name»"!''') | ||
52 | } | ||
53 | |||
54 | val trg = reference.EReferenceType | ||
55 | if(!classes.contains(trg)) { | ||
56 | errors.add('''Metamodel contains reference "«reference.name»" but does not contains its target type "«trg.name»"!''') | ||
57 | } | ||
58 | } | ||
59 | } | ||
60 | def attributeSourcePontIsIncluded(List<EClass> classes, List<EAttribute> attributes, List<String> errors) { | ||
61 | for(attribute : attributes) { | ||
62 | val src = attribute.containerClass | ||
63 | if(!classes.contains(src)) { | ||
64 | errors.add('''Metamodel contains attribute "«attribute.name»" but does not contains its source type "«src.name»"!''') | ||
65 | } | ||
66 | } | ||
67 | } | ||
68 | def attributeTargetIsSupported(List<EAttribute> attributes, List<String> errors) { | ||
69 | for(attribute: attributes) { | ||
70 | val trg = attribute.EAttributeType | ||
71 | if(!supportedEDataType(trg)) { | ||
72 | errors.add('''Metamodels contains attribute "«attribute.name»" with unsupported type "«trg.name»"!''') | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | } \ No newline at end of file | ||
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 | ||
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/valueconverter/ApplicationConfigurationValueConverterService.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/valueconverter/ApplicationConfigurationValueConverterService.xtend new file mode 100644 index 00000000..433f7148 --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/valueconverter/ApplicationConfigurationValueConverterService.xtend | |||
@@ -0,0 +1,14 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.valueconverter | ||
2 | |||
3 | import org.eclipse.xtext.common.services.DefaultTerminalConverters | ||
4 | import org.eclipse.xtext.conversion.IValueConverter | ||
5 | import org.eclipse.xtext.conversion.ValueConverter | ||
6 | |||
7 | class ApplicationConfigurationValueConverterService extends DefaultTerminalConverters { | ||
8 | //val org.eclipse.xtext.conversion.impl.QualifiedNameValueConverter converter = new org.eclipse.xtext.conversion.impl.QualifiedNameValueConverter | ||
9 | val QualifiedNameValueConverter converter2 = new QualifiedNameValueConverter | ||
10 | @ValueConverter(rule="QualifiedName") | ||
11 | def IValueConverter<String> QualifiedName() { | ||
12 | converter2 | ||
13 | } | ||
14 | } \ No newline at end of file | ||