diff options
author | 2018-01-13 19:33:26 +0100 | |
---|---|---|
committer | 2018-01-13 19:33:26 +0100 | |
commit | 7e50434905cbb7f5d03636033b698e17a9075e9d (patch) | |
tree | 10e0968c20ac55dae4f5dc6077f39cf9947e3cb9 /Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/util/VQLParser.xtend | |
parent | Test and measurement runners (diff) | |
download | VIATRA-Generator-7e50434905cbb7f5d03636033b698e17a9075e9d.tar.gz VIATRA-Generator-7e50434905cbb7f5d03636033b698e17a9075e9d.tar.zst VIATRA-Generator-7e50434905cbb7f5d03636033b698e17a9075e9d.zip |
Initial commit of the configuration language and application
Diffstat (limited to 'Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/util/VQLParser.xtend')
-rw-r--r-- | Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/util/VQLParser.xtend | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/util/VQLParser.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/util/VQLParser.xtend new file mode 100644 index 00000000..9b5c538f --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/util/VQLParser.xtend | |||
@@ -0,0 +1,99 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.execution.util | ||
2 | |||
3 | import com.google.inject.Guice | ||
4 | import com.google.inject.Injector | ||
5 | import com.google.inject.Module | ||
6 | import java.util.LinkedHashMap | ||
7 | import org.eclipse.emf.common.util.URI | ||
8 | import org.eclipse.emf.ecore.resource.Resource | ||
9 | import org.eclipse.emf.ecore.resource.ResourceSet | ||
10 | import org.eclipse.emf.ecore.util.EcoreUtil | ||
11 | import org.eclipse.viatra.query.patternlanguage.PatternLanguageStandaloneSetup | ||
12 | import org.eclipse.viatra.query.patternlanguage.annotations.ExtensionBasedAnnotationValidatorLoader | ||
13 | import org.eclipse.viatra.query.patternlanguage.annotations.IAnnotationValidatorLoader | ||
14 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageRuntimeModule | ||
15 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup | ||
16 | import org.eclipse.viatra.query.patternlanguage.emf.GenmodelExtensionLoader | ||
17 | import org.eclipse.viatra.query.patternlanguage.emf.IGenmodelMappingLoader | ||
18 | import org.eclipse.viatra.query.patternlanguage.emf.eMFPatternLanguage.PatternModel | ||
19 | import org.eclipse.viatra.query.patternlanguage.emf.specification.SpecificationBuilder | ||
20 | import org.eclipse.xtext.resource.XtextResourceSet | ||
21 | import hu.bme.mit.inf.dslreasoner.application.execution.Context | ||
22 | import java.util.List | ||
23 | import java.util.HashMap | ||
24 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification | ||
25 | |||
26 | class MyModule extends EMFPatternLanguageRuntimeModule implements Module { | ||
27 | def public Class<? extends IAnnotationValidatorLoader> bindAnnotationValidatorLoader() { | ||
28 | return typeof(ExtensionBasedAnnotationValidatorLoader); | ||
29 | } | ||
30 | def public Class<? extends IGenmodelMappingLoader> bindGenmodelMappingLoader() { | ||
31 | return typeof(GenmodelExtensionLoader); | ||
32 | } | ||
33 | } | ||
34 | |||
35 | class VQLParser { | ||
36 | val Injector injector; | ||
37 | val SpecificationBuilder builder = new SpecificationBuilder | ||
38 | |||
39 | new() { | ||
40 | PatternLanguageStandaloneSetup.doSetup | ||
41 | EMFPatternLanguageStandaloneSetup.doSetup; | ||
42 | |||
43 | injector = internalCreateInjector | ||
44 | } | ||
45 | |||
46 | def protected Injector internalCreateInjector() { | ||
47 | new EMFPatternLanguageStandaloneSetup().createInjectorAndDoEMFRegistration(); | ||
48 | val Module module = new MyModule | ||
49 | val newInjector = Guice.createInjector(module) | ||
50 | return newInjector; | ||
51 | } | ||
52 | |||
53 | public def createResourceSet() { | ||
54 | injector.getInstance(XtextResourceSet); | ||
55 | } | ||
56 | |||
57 | /** | ||
58 | * Load patterns in two steps: first, the pattern models are are loaded to a resource set, then | ||
59 | * the linked patterns are loaded validated and translated to a {@link IQuerySpecification} object. | ||
60 | * @returns uri -> (name -> pattern) | ||
61 | */ | ||
62 | public def parse(List<String> uris, ResourceSet resourceSet, Context context) { | ||
63 | val res = new LinkedHashMap | ||
64 | val uri2resource = new LinkedHashMap | ||
65 | |||
66 | for(uri : uris) { | ||
67 | var Resource resource | ||
68 | var PatternModel patternModel | ||
69 | try { | ||
70 | resource = resourceSet.getResource(URI.createURI(uri),true); | ||
71 | patternModel = resource.getContents().get(0) as PatternModel; | ||
72 | uri2resource.put(uri,patternModel) | ||
73 | } catch(RuntimeException e) { | ||
74 | context.writeError('''Unable to load patterns from "«uri»"!''') | ||
75 | } | ||
76 | } | ||
77 | |||
78 | for(entry : uri2resource.entrySet) { | ||
79 | val uri = entry.key | ||
80 | val model = entry.value | ||
81 | EcoreUtil.resolveAll(model.eResource) | ||
82 | model.eResource.validate(uri, context) | ||
83 | |||
84 | val map = new LinkedHashMap | ||
85 | for(pattern : model.patterns) { | ||
86 | val IQuerySpecification<?> querySpecification = (this.builder as SpecificationBuilder).getOrCreateSpecification(pattern) | ||
87 | map.put(querySpecification.fullyQualifiedName.split('.').last,querySpecification) | ||
88 | } | ||
89 | res.put(uri,map) | ||
90 | } | ||
91 | |||
92 | return res | ||
93 | } | ||
94 | |||
95 | def private validate(Resource resource, String URI, Context context) { | ||
96 | val errors = resource.errors | ||
97 | errors.forEach[context.writeError('''Error in loading pattern "«URI»": «it»''')] | ||
98 | } | ||
99 | } \ No newline at end of file | ||