diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/util/ParseUtil.xtend | 91 |
1 files changed, 77 insertions, 14 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 index 6febe0a6..00342d8b 100644 --- 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 | |||
@@ -1,53 +1,92 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.util | 1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.util |
2 | 2 | ||
3 | import com.google.inject.Binder | ||
3 | import com.google.inject.Guice | 4 | import com.google.inject.Guice |
4 | import com.google.inject.Injector | 5 | import com.google.inject.Injector |
5 | import com.google.inject.Module | 6 | import com.google.inject.Module |
7 | import com.google.inject.multibindings.Multibinder | ||
8 | import com.google.inject.name.Names | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage | 9 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguagePackage |
7 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicproblemPackage | 10 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicproblemPackage |
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationPackage | 11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationPackage |
9 | import java.io.ByteArrayInputStream | 12 | import java.io.ByteArrayInputStream |
10 | import java.io.InputStream | 13 | import java.io.InputStream |
11 | import java.util.LinkedHashMap | 14 | import java.util.LinkedHashMap |
15 | import java.util.LinkedList | ||
16 | import java.util.List | ||
12 | import org.eclipse.emf.common.util.URI | 17 | import org.eclipse.emf.common.util.URI |
18 | import org.eclipse.emf.ecore.EClassifier | ||
19 | import org.eclipse.emf.ecore.EObject | ||
20 | import org.eclipse.emf.ecore.EPackage | ||
13 | import org.eclipse.emf.ecore.resource.Resource | 21 | import org.eclipse.emf.ecore.resource.Resource |
22 | import org.eclipse.emf.ecore.resource.ResourceSet | ||
14 | import org.eclipse.emf.ecore.util.EcoreUtil | 23 | import org.eclipse.emf.ecore.util.EcoreUtil |
15 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageRuntimeModule | ||
16 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup | 24 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup |
17 | import org.eclipse.viatra.query.patternlanguage.emf.GenmodelExtensionLoader | 25 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup.StandaloneParserWithSeparateModules |
18 | import org.eclipse.viatra.query.patternlanguage.emf.IGenmodelMappingLoader | 26 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.BaseMetamodelProviderService |
27 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.EMFPatternLanguageImportNamespaceProvider | ||
28 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.IMetamodelProvider | ||
29 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.IMetamodelProviderInstance | ||
19 | import org.eclipse.viatra.query.patternlanguage.emf.specification.SpecificationBuilder | 30 | import org.eclipse.viatra.query.patternlanguage.emf.specification.SpecificationBuilder |
20 | import org.eclipse.viatra.query.patternlanguage.emf.vql.PatternModel | 31 | import org.eclipse.viatra.query.patternlanguage.emf.vql.PatternModel |
32 | import org.eclipse.xtext.resource.IResourceFactory | ||
33 | import org.eclipse.xtext.resource.IResourceServiceProvider | ||
21 | import org.eclipse.xtext.resource.XtextResourceSet | 34 | import org.eclipse.xtext.resource.XtextResourceSet |
35 | import org.eclipse.xtext.scoping.IScopeProvider | ||
36 | import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider | ||
22 | 37 | ||
23 | class MyModule extends EMFPatternLanguageRuntimeModule implements Module{ | 38 | class MyModule extends StandaloneParserWithSeparateModules implements Module{ |
24 | // def public Class<? extends IAnnotationValidatorLoader> bindAnnotationValidatorLoader() { | 39 | // def public Class<? extends IAnnotationValidatorLoader> bindAnnotationValidatorLoader() { |
25 | // return typeof(ExtensionBasedAnnotationValidatorLoader); | 40 | // return typeof(ExtensionBasedAnnotationValidatorLoader); |
26 | // } | 41 | // } |
27 | def public Class<? extends IGenmodelMappingLoader> bindGenmodelMappingLoader() { | 42 | // def public Class<? extends IGenmodelMappingLoader> bindGenmodelMappingLoader() { |
28 | return typeof(GenmodelExtensionLoader); | 43 | // return typeof(GenmodelExtensionLoader); |
44 | // } | ||
45 | |||
46 | override configureIScopeProviderDelegate(Binder binder) { | ||
47 | binder.bind(IScopeProvider).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)) | ||
48 | .to(EMFPatternLanguageImportNamespaceProvider); | ||
49 | // .to(XImportSectionNamespaceScopeProvider.class); | ||
50 | //val Multibinder<IMetamodelProviderInstance> metamodelProviderBinder = | ||
51 | Multibinder::newSetBinder(binder, IMetamodelProviderInstance); | ||
52 | // metamodelProviderBinder.addBinding().to(MetamodelProviderService.class); | ||
53 | // metamodelProviderBinder.addBinding().to(ResourceSetMetamodelProviderService.class); | ||
29 | } | 54 | } |
55 | |||
56 | override Class<? extends IMetamodelProvider> bindIMetamodelProvider() { | ||
57 | MetamodelProviderForModelGeneration | ||
58 | } | ||
59 | // def configureFixedMetamodelProviderService(FixedMetamodelProviderService s) { | ||
60 | // println('''Configured «s.class.simpleName» with «s.packages.toList»''') | ||
61 | // s.packages += PartialinterpretationPackage.eINSTANCE | ||
62 | // s.packages += LogicproblemPackage.eINSTANCE | ||
63 | // s.packages += LogiclanguagePackage.eINSTANCE | ||
64 | // println('''Configured «s.class.simpleName» with «s.packages.toList»''') | ||
65 | // } | ||
30 | } | 66 | } |
31 | 67 | ||
32 | class ParseUtil { | 68 | class ParseUtil { |
33 | val Injector injector; | 69 | val Injector injector; |
34 | new() { | 70 | new() { |
35 | EMFPatternLanguageStandaloneSetup.doSetup; | 71 | //EMFPatternLanguageStandaloneSetup.doSetup; |
36 | PartialinterpretationPackage.eINSTANCE.class; | 72 | PartialinterpretationPackage.eINSTANCE.class; |
37 | LogicproblemPackage.eINSTANCE.class; | 73 | LogicproblemPackage.eINSTANCE.class; |
38 | LogiclanguagePackage.eINSTANCE.class; | 74 | LogiclanguagePackage.eINSTANCE.class; |
39 | 75 | ||
40 | injector = internalCreateInjector//(new EMFPatternLanguageStandaloneSetup()).createInjectorAndDoEMFRegistration(); | 76 | injector = internalCreateInjector//(new EMFPatternLanguageStandaloneSetup()).createInjectorAndDoEMFRegistration(); |
77 | |||
78 | val IResourceFactory resourceFactory = injector.getInstance(IResourceFactory); | ||
79 | val IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider); | ||
80 | |||
81 | Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("vql_deactivated", resourceFactory); | ||
82 | IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("vql_deactivated", serviceProvider); | ||
41 | } | 83 | } |
42 | 84 | ||
43 | def protected Injector internalCreateInjector() { | 85 | def protected Injector internalCreateInjector() { |
44 | var newInjector = new EMFPatternLanguageStandaloneSetup().createInjectorAndDoEMFRegistration(); | 86 | var newInjector = new EMFPatternLanguageStandaloneSetup().createInjectorAndDoEMFRegistration(); |
45 | //XXX the following line enforce the tests to be run in an Eclipse environment | 87 | val Module module = new MyModule |
46 | val Module module = new MyModule | 88 | newInjector = Guice.createInjector(module) |
47 | newInjector = Guice.createInjector(module) | 89 | return newInjector; |
48 | //ViatraQueryLoggingUtil.setExternalLogger(newInjector.getInstance(Logger.class)); | ||
49 | //EMFPatternLanguagePlugin.getInstance().addCompoundInjector(newInjector,EMFPatternLanguagePlugin.TEST_INJECTOR_PRIORITY); | ||
50 | return newInjector; | ||
51 | } | 90 | } |
52 | 91 | ||
53 | // @Inject | 92 | // @Inject |
@@ -57,7 +96,7 @@ class ParseUtil { | |||
57 | public def parse(CharSequence vqlFileContent) { | 96 | public def parse(CharSequence vqlFileContent) { |
58 | //val patternModel = this.parseHelper.parse(vqlFileContent) | 97 | //val patternModel = this.parseHelper.parse(vqlFileContent) |
59 | val XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet); | 98 | val XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet); |
60 | val Resource resource = resourceSet.createResource(URI.createURI("dummy:/example.vql")); | 99 | val Resource resource = resourceSet.createResource(URI.createURI("dummy:/example.vql_deactivated")); |
61 | val InputStream in = new ByteArrayInputStream(vqlFileContent.toString.getBytes()); | 100 | val InputStream in = new ByteArrayInputStream(vqlFileContent.toString.getBytes()); |
62 | resource.load(in, resourceSet.getLoadOptions()); | 101 | resource.load(in, resourceSet.getLoadOptions()); |
63 | val patternModel = resource.getContents().get(0) as PatternModel; | 102 | val patternModel = resource.getContents().get(0) as PatternModel; |
@@ -82,4 +121,28 @@ class ParseUtil { | |||
82 | println('''------------''') | 121 | println('''------------''') |
83 | } | 122 | } |
84 | } | 123 | } |
124 | } | ||
125 | |||
126 | abstract class FixedMetamodelProviderService extends BaseMetamodelProviderService { | ||
127 | |||
128 | protected val List<EPackage> packages = new LinkedList | ||
129 | |||
130 | override protected doGetQualifiedClassName(EClassifier classifier, EObject context) { | ||
131 | classifier.name | ||
132 | } | ||
133 | |||
134 | override protected getProvidedMetamodels() { | ||
135 | return packages.map[it.nsURI] | ||
136 | } | ||
137 | |||
138 | override loadEPackage(String uri, ResourceSet resourceSet) { | ||
139 | packages.filter[it.nsURI.equals(uri)].head | ||
140 | } | ||
141 | } | ||
142 | class MetamodelProviderForModelGeneration extends FixedMetamodelProviderService { | ||
143 | new() { | ||
144 | packages += PartialinterpretationPackage.eINSTANCE | ||
145 | packages += LogicproblemPackage.eINSTANCE | ||
146 | packages += LogiclanguagePackage.eINSTANCE | ||
147 | } | ||
85 | } \ No newline at end of file | 148 | } \ No newline at end of file |