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