diff options
author | 2019-02-17 19:34:52 +0100 | |
---|---|---|
committer | 2019-02-17 19:34:52 +0100 | |
commit | cb77845089f6c8171fc3c39a92690dee3671886a (patch) | |
tree | ea37e44ec4f2a3a55b01227813e2c23190aa1a60 /Application | |
parent | Solution store diversity requirement set to 1 as default (diff) | |
download | VIATRA-Generator-cb77845089f6c8171fc3c39a92690dee3671886a.tar.gz VIATRA-Generator-cb77845089f6c8171fc3c39a92690dee3671886a.tar.zst VIATRA-Generator-cb77845089f6c8171fc3c39a92690dee3671886a.zip |
Created new module to load referred patterns. hacked metamodel linking.
Diffstat (limited to 'Application')
6 files changed, 124 insertions, 108 deletions
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/PatternLanguageWithRSModule.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/PatternLanguageWithRSModule.xtend new file mode 100644 index 00000000..1269ec1f --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/PatternLanguageWithRSModule.xtend | |||
@@ -0,0 +1,46 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.execution | ||
2 | |||
3 | import com.google.inject.Binder | ||
4 | import com.google.inject.multibindings.Multibinder | ||
5 | import com.google.inject.name.Names | ||
6 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup.StandaloneParserWithSeparateModules | ||
7 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.EMFPatternLanguageImportNamespaceProvider | ||
8 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.IMetamodelProvider | ||
9 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.IMetamodelProviderInstance | ||
10 | import org.eclipse.xtext.scoping.IScopeProvider | ||
11 | import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider | ||
12 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.CompoundMetamodelProviderService | ||
13 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.MetamodelProviderService | ||
14 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.ResourceSetMetamodelProviderService | ||
15 | import org.eclipse.viatra.query.patternlanguage.emf.types.EMFTypeInferrer | ||
16 | import org.eclipse.viatra.query.patternlanguage.emf.types.EMFTypeSystem | ||
17 | import org.eclipse.viatra.query.patternlanguage.emf.types.ITypeInferrer | ||
18 | import org.eclipse.viatra.query.patternlanguage.emf.types.ITypeSystem | ||
19 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageRuntimeModule | ||
20 | |||
21 | class PatternLanguageWithRSModule extends EMFPatternLanguageRuntimeModule{ | ||
22 | |||
23 | override configureIScopeProviderDelegate(Binder binder) { | ||
24 | binder.bind(IScopeProvider).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)) | ||
25 | .to(EMFPatternLanguageImportNamespaceProvider); | ||
26 | Multibinder::newSetBinder(binder, IMetamodelProviderInstance); | ||
27 | } | ||
28 | |||
29 | override Class<? extends IMetamodelProvider> bindIMetamodelProvider() { | ||
30 | CompoundMetamodelProviderService | ||
31 | } | ||
32 | |||
33 | def configureMetamodelProviderInstance(Binder binder) { | ||
34 | val metamodelProviderBinder = Multibinder.newSetBinder(binder, IMetamodelProviderInstance) | ||
35 | metamodelProviderBinder.addBinding.to(MetamodelProviderService) | ||
36 | metamodelProviderBinder.addBinding.to(ResourceSetMetamodelProviderService) | ||
37 | } | ||
38 | |||
39 | override Class<? extends ITypeSystem> bindITypeSystem() { | ||
40 | return EMFTypeSystem; | ||
41 | } | ||
42 | |||
43 | override Class<? extends ITypeInferrer> bindITypeInferrer() { | ||
44 | return EMFTypeInferrer; | ||
45 | } | ||
46 | } \ No newline at end of file | ||
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/PatternLanguageWithRSSetup.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/PatternLanguageWithRSSetup.xtend new file mode 100644 index 00000000..dd5af673 --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/PatternLanguageWithRSSetup.xtend | |||
@@ -0,0 +1,15 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.execution | ||
2 | |||
3 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetupGenerated | ||
4 | import com.google.inject.Injector | ||
5 | import com.google.inject.Guice | ||
6 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageRuntimeModule | ||
7 | import com.google.inject.Guice; | ||
8 | import com.google.inject.Injector; | ||
9 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup | ||
10 | |||
11 | class PatternLanguageWithRSSetup extends EMFPatternLanguageStandaloneSetup{ | ||
12 | override Injector createInjector() { | ||
13 | return Guice::createInjector(new PatternLanguageWithRSModule()); | ||
14 | } | ||
15 | } \ No newline at end of file | ||
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/QueryLoader.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/QueryLoader.xtend index 8f8348b1..cfc91143 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/QueryLoader.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/QueryLoader.xtend | |||
@@ -22,6 +22,10 @@ import org.eclipse.xtext.EcoreUtil2 | |||
22 | 22 | ||
23 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | 23 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* |
24 | import org.eclipse.viatra.query.patternlanguage.emf.vql.PatternCall | 24 | import org.eclipse.viatra.query.patternlanguage.emf.vql.PatternCall |
25 | import org.eclipse.viatra.query.runtime.api.IPatternMatch | ||
26 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher | ||
27 | import java.util.LinkedHashMap | ||
28 | import java.util.LinkedList | ||
25 | 29 | ||
26 | class QueryLoader { | 30 | class QueryLoader { |
27 | //val parser = new VQLParser | 31 | //val parser = new VQLParser |
@@ -34,6 +38,9 @@ class QueryLoader { | |||
34 | patterns += getPatterns(entry) | 38 | patterns += getPatterns(entry) |
35 | } | 39 | } |
36 | 40 | ||
41 | //val errors = patterns.map[eResource].toSet.map[errors] | ||
42 | //errors.forEach[println(it)] | ||
43 | |||
37 | val allConcernedPatterns = patterns.allReferredPatterns | 44 | val allConcernedPatterns = patterns.allReferredPatterns |
38 | val pattern2Specification = allConcernedPatterns.translatePatterns() | 45 | val pattern2Specification = allConcernedPatterns.translatePatterns() |
39 | 46 | ||
@@ -108,7 +115,15 @@ class QueryLoader { | |||
108 | } | 115 | } |
109 | 116 | ||
110 | def private translatePatterns(Set<Pattern> xtextPattern) { | 117 | def private translatePatterns(Set<Pattern> xtextPattern) { |
111 | xtextPattern.toInvertedMap[builder.getOrCreateSpecification(it) as IQuerySpecification<?>] | 118 | val res = new LinkedHashMap<Pattern,IQuerySpecification<?>> |
119 | val patterns = new LinkedList<IQuerySpecification<?>> | ||
120 | for(pattern : xtextPattern) { | ||
121 | val querySpecification = builder.getOrCreateSpecification(pattern,patterns,true) | ||
122 | res.put(pattern,querySpecification) | ||
123 | patterns += querySpecification | ||
124 | } | ||
125 | |||
126 | return res | ||
112 | } | 127 | } |
113 | 128 | ||
114 | def private calculateDerivedFeatures(Set<EPackage> packages, Iterable<IQuerySpecification<?>> patterns) { | 129 | def private calculateDerivedFeatures(Set<EPackage> packages, Iterable<IQuerySpecification<?>> patterns) { |
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/StandaloneScriptExecutor.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/StandaloneScriptExecutor.xtend index f373d910..c612f0ea 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/StandaloneScriptExecutor.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/StandaloneScriptExecutor.xtend | |||
@@ -17,6 +17,11 @@ import org.eclipse.viatra.query.runtime.api.ViatraQueryEngineOptions | |||
17 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint | 17 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint |
18 | import org.eclipse.viatra.query.runtime.rete.util.ReteHintOptions | 18 | import org.eclipse.viatra.query.runtime.rete.util.ReteHintOptions |
19 | import org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine | 19 | import org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine |
20 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneCompilerSetup | ||
21 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetupGenerated | ||
22 | import org.eclipse.xtext.resource.XtextResourceSet | ||
23 | import com.google.inject.Injector | ||
24 | import com.google.inject.Guice | ||
20 | 25 | ||
21 | class StandaloneScriptExecutor { | 26 | class StandaloneScriptExecutor { |
22 | def static void main(String[] args) { | 27 | def static void main(String[] args) { |
@@ -32,9 +37,19 @@ class StandaloneScriptExecutor { | |||
32 | } | 37 | } |
33 | } | 38 | } |
34 | 39 | ||
40 | static def protected Injector internalCreateInjector() { | ||
41 | var newInjector = new EMFPatternLanguageStandaloneSetup().createInjectorAndDoEMFRegistration(); | ||
42 | val PatternLanguageWithRSModule module = new PatternLanguageWithRSModule | ||
43 | newInjector = Guice.createInjector(module) | ||
44 | //val XtextInjectorProvider x = null | ||
45 | return newInjector; | ||
46 | } | ||
47 | |||
48 | |||
35 | def static loadScript(String path) { | 49 | def static loadScript(String path) { |
36 | //Initialise extensions | 50 | //Initialise extensions |
37 | EMFPatternLanguageStandaloneSetup.doSetup | 51 | val i = (new PatternLanguageWithRSSetup).createInjectorAndDoEMFRegistration |
52 | //PatternLanguageWithRSSetup.createInjectorAndDoEMFRegistration | ||
38 | ApplicationConfigurationStandaloneSetup.doSetup | 53 | ApplicationConfigurationStandaloneSetup.doSetup |
39 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("xmi",new XMIResourceFactoryImpl) | 54 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("xmi",new XMIResourceFactoryImpl) |
40 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("logicproblem",new XMIResourceFactoryImpl) | 55 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("logicproblem",new XMIResourceFactoryImpl) |
@@ -43,7 +58,9 @@ class StandaloneScriptExecutor { | |||
43 | 58 | ||
44 | val ext = path.split("\\.").last | 59 | val ext = path.split("\\.").last |
45 | if(ext.equals("vsconfig")) { | 60 | if(ext.equals("vsconfig")) { |
46 | val resourceSet = new ResourceSetImpl | 61 | |
62 | val resourceSet = //new ResourceSetImpl | ||
63 | i.getInstance(XtextResourceSet); | ||
47 | var Resource resource | 64 | var Resource resource |
48 | 65 | ||
49 | try{ | 66 | try{ |
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 | ||
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/linking/ApplicationConfigurationLinkingService.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/linking/ApplicationConfigurationLinkingService.xtend index 41a89e6f..fc4b721a 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/linking/ApplicationConfigurationLinkingService.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/linking/ApplicationConfigurationLinkingService.xtend | |||
@@ -20,6 +20,8 @@ import org.eclipse.xtext.conversion.ValueConverterException | |||
20 | import org.eclipse.xtext.linking.impl.DefaultLinkingService | 20 | import org.eclipse.xtext.linking.impl.DefaultLinkingService |
21 | import org.eclipse.xtext.nodemodel.ILeafNode | 21 | import org.eclipse.xtext.nodemodel.ILeafNode |
22 | import org.eclipse.xtext.nodemodel.INode | 22 | import org.eclipse.xtext.nodemodel.INode |
23 | import org.eclipse.emf.ecore.resource.ResourceSet | ||
24 | import org.eclipse.emf.ecore.EPackage | ||
23 | 25 | ||
24 | class ApplicationConfigurationLinkingService extends DefaultLinkingService{ | 26 | class ApplicationConfigurationLinkingService extends DefaultLinkingService{ |
25 | 27 | ||
@@ -57,11 +59,32 @@ class ApplicationConfigurationLinkingService extends DefaultLinkingService{ | |||
57 | } | 59 | } |
58 | 60 | ||
59 | private def getEPackage(EPackageImport packageImport, ILeafNode node) { | 61 | private def getEPackage(EPackageImport packageImport, ILeafNode node) { |
60 | getNSUri(node).flatMap [ uri | | 62 | val x = getNSUri(node) |
61 | Optional.ofNullable(metamodelProvider.loadEPackage(uri, packageImport.eResource.resourceSet)) | 63 | if(x.isPresent) { |
62 | ].map [ ePackage | | 64 | val uriString = x.get |
63 | Collections.singletonList(ePackage as EObject) | 65 | val epackageByMetamodelProvider = metamodelProvider.loadEPackage(uriString, packageImport.eResource.resourceSet) |
64 | ].orElse(emptyList) | 66 | val epackageByMe = ePackageByMe(packageImport.eResource.resourceSet,uriString) |
67 | //println(epackageByMetamodelProvider) | ||
68 | //println(epackageByMe) | ||
69 | if(epackageByMetamodelProvider!==null) { | ||
70 | return Collections.singletonList(epackageByMetamodelProvider as EObject) | ||
71 | } else if(epackageByMe !== null) { | ||
72 | return Collections.singletonList(epackageByMe as EObject) | ||
73 | } else { | ||
74 | emptyList | ||
75 | } | ||
76 | } else { | ||
77 | return emptyList | ||
78 | } | ||
79 | } | ||
80 | |||
81 | private def ePackageByMe(ResourceSet rs, String uri) { | ||
82 | try { | ||
83 | val resource = rs.getResource(URI.createURI(uri), true); | ||
84 | return resource.contents.head as EPackage | ||
85 | } catch (Exception e) { | ||
86 | return null | ||
87 | } | ||
65 | } | 88 | } |
66 | 89 | ||
67 | private def getViatra(ViatraImport viatraImport, INode node) { | 90 | private def getViatra(ViatraImport viatraImport, INode node) { |