diff options
author | 2017-06-10 19:05:05 +0200 | |
---|---|---|
committer | 2017-06-10 19:05:05 +0200 | |
commit | 60f01f46ba232ed6416054f0a6115cb2a9b70b4e (patch) | |
tree | 5edf8aeb07abc51f3fec63bbd15c926e1de09552 /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/util/ParseUtil.xtend | |
parent | Initial commit, migrating from SVN (diff) | |
download | VIATRA-Generator-60f01f46ba232ed6416054f0a6115cb2a9b70b4e.tar.gz VIATRA-Generator-60f01f46ba232ed6416054f0a6115cb2a9b70b4e.tar.zst VIATRA-Generator-60f01f46ba232ed6416054f0a6115cb2a9b70b4e.zip |
Migrating Additional projects
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/util/ParseUtil.xtend')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/util/ParseUtil.xtend | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/util/ParseUtil.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/util/ParseUtil.xtend new file mode 100644 index 00000000..005304ea --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/util/ParseUtil.xtend | |||
@@ -0,0 +1,89 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.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.logic.model.logiclanguage.LogiclanguagePackage | ||
7 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicproblemPackage | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationPackage | ||
9 | import java.io.ByteArrayInputStream | ||
10 | import java.io.InputStream | ||
11 | import java.util.LinkedHashMap | ||
12 | import org.eclipse.emf.common.util.URI | ||
13 | import org.eclipse.emf.ecore.resource.Resource | ||
14 | import org.eclipse.emf.ecore.util.EcoreUtil | ||
15 | import org.eclipse.viatra.query.patternlanguage.PatternLanguageStandaloneSetup | ||
16 | import org.eclipse.viatra.query.patternlanguage.annotations.ExtensionBasedAnnotationValidatorLoader | ||
17 | import org.eclipse.viatra.query.patternlanguage.annotations.IAnnotationValidatorLoader | ||
18 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageRuntimeModule | ||
19 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup | ||
20 | import org.eclipse.viatra.query.patternlanguage.emf.GenmodelExtensionLoader | ||
21 | import org.eclipse.viatra.query.patternlanguage.emf.IGenmodelMappingLoader | ||
22 | import org.eclipse.viatra.query.patternlanguage.emf.eMFPatternLanguage.PatternModel | ||
23 | import org.eclipse.viatra.query.patternlanguage.emf.specification.SpecificationBuilder | ||
24 | import org.eclipse.xtext.resource.XtextResourceSet | ||
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 ParseUtil { | ||
36 | val Injector injector; | ||
37 | new() { | ||
38 | PatternLanguageStandaloneSetup.doSetup | ||
39 | EMFPatternLanguageStandaloneSetup.doSetup; | ||
40 | PartialinterpretationPackage.eINSTANCE.class; | ||
41 | LogicproblemPackage.eINSTANCE.class; | ||
42 | LogiclanguagePackage.eINSTANCE.class; | ||
43 | |||
44 | injector = internalCreateInjector//(new EMFPatternLanguageStandaloneSetup()).createInjectorAndDoEMFRegistration(); | ||
45 | } | ||
46 | |||
47 | def protected Injector internalCreateInjector() { | ||
48 | var newInjector = new EMFPatternLanguageStandaloneSetup().createInjectorAndDoEMFRegistration(); | ||
49 | //XXX the following line enforce the tests to be run in an Eclipse environment | ||
50 | val Module module = new MyModule | ||
51 | newInjector = Guice.createInjector(module) | ||
52 | //ViatraQueryLoggingUtil.setExternalLogger(newInjector.getInstance(Logger.class)); | ||
53 | //EMFPatternLanguagePlugin.getInstance().addCompoundInjector(newInjector,EMFPatternLanguagePlugin.TEST_INJECTOR_PRIORITY); | ||
54 | return newInjector; | ||
55 | } | ||
56 | |||
57 | // @Inject | ||
58 | // var ParseHelper<PatternModel> parseHelper; | ||
59 | val builder = new SpecificationBuilder | ||
60 | |||
61 | public def parse(CharSequence vqlFileContent) { | ||
62 | //val patternModel = this.parseHelper.parse(vqlFileContent) | ||
63 | val XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet); | ||
64 | val Resource resource = resourceSet.createResource(URI.createURI("dummy:/example.vql")); | ||
65 | val InputStream in = new ByteArrayInputStream(vqlFileContent.toString.getBytes()); | ||
66 | resource.load(in, resourceSet.getLoadOptions()); | ||
67 | val patternModel = resource.getContents().get(0) as PatternModel; | ||
68 | |||
69 | EcoreUtil.resolveAll(resource) | ||
70 | resource.validate | ||
71 | val res = new LinkedHashMap | ||
72 | for(pattern : patternModel.patterns) { | ||
73 | val querySpecification = builder.getOrCreateSpecification(pattern) | ||
74 | res.put(querySpecification.fullyQualifiedName,querySpecification) | ||
75 | //println('''«querySpecification.fullyQualifiedName» -> «querySpecification»''') | ||
76 | } | ||
77 | resource.validate | ||
78 | return res | ||
79 | } | ||
80 | |||
81 | def private validate(Resource resource) { | ||
82 | val errors = resource.errors | ||
83 | if(!errors.isEmpty) { | ||
84 | println('''-- Errors --''') | ||
85 | errors.forEach[println('''> «it»''')] | ||
86 | println('''------------''') | ||
87 | } | ||
88 | } | ||
89 | } \ No newline at end of file | ||