diff options
author | 2018-01-17 00:54:44 +0100 | |
---|---|---|
committer | 2018-01-17 00:54:44 +0100 | |
commit | 0a31d5448e92d915c7163c3985fa0807f67d3f06 (patch) | |
tree | 1a106505c98df6398f2b5fe183771fc315f1e87a /Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/linking/ApplicationConfigurationLinkingService.xtend | |
parent | Scope patched for metamodel specification (diff) | |
download | VIATRA-Generator-0a31d5448e92d915c7163c3985fa0807f67d3f06.tar.gz VIATRA-Generator-0a31d5448e92d915c7163c3985fa0807f67d3f06.tar.zst VIATRA-Generator-0a31d5448e92d915c7163c3985fa0807f67d3f06.zip |
Scoping and linking of Viatra Packages and Patterns is completed
Diffstat (limited to 'Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/linking/ApplicationConfigurationLinkingService.xtend')
-rw-r--r-- | Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/linking/ApplicationConfigurationLinkingService.xtend | 54 |
1 files changed, 51 insertions, 3 deletions
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 15567f88..35d4008b 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 | |||
@@ -6,6 +6,7 @@ import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.EPackageI | |||
6 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ViatraImport | 6 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ViatraImport |
7 | import java.util.Collections | 7 | import java.util.Collections |
8 | import java.util.Optional | 8 | import java.util.Optional |
9 | import org.eclipse.emf.common.util.URI | ||
9 | import org.eclipse.emf.ecore.EObject | 10 | import org.eclipse.emf.ecore.EObject |
10 | import org.eclipse.emf.ecore.EReference | 11 | import org.eclipse.emf.ecore.EReference |
11 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.IMetamodelProvider | 12 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.IMetamodelProvider |
@@ -14,6 +15,13 @@ import org.eclipse.xtext.conversion.ValueConverterException | |||
14 | import org.eclipse.xtext.linking.impl.DefaultLinkingService | 15 | import org.eclipse.xtext.linking.impl.DefaultLinkingService |
15 | import org.eclipse.xtext.nodemodel.ILeafNode | 16 | import org.eclipse.xtext.nodemodel.ILeafNode |
16 | import org.eclipse.xtext.nodemodel.INode | 17 | import org.eclipse.xtext.nodemodel.INode |
18 | import org.eclipse.emf.ecore.resource.Resource | ||
19 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PatternEntry | ||
20 | import org.eclipse.emf.ecore.util.EcoreUtil | ||
21 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript | ||
22 | import org.eclipse.xtext.EcoreUtil2 | ||
23 | import java.util.List | ||
24 | import org.eclipse.xtext.conversion.impl.QualifiedNameValueConverter | ||
17 | 25 | ||
18 | class ApplicationConfigurationLinkingService extends DefaultLinkingService{ | 26 | class ApplicationConfigurationLinkingService extends DefaultLinkingService{ |
19 | 27 | ||
@@ -31,20 +39,60 @@ class ApplicationConfigurationLinkingService extends DefaultLinkingService{ | |||
31 | return getEPackage(context as EPackageImport, node as ILeafNode) | 39 | return getEPackage(context as EPackageImport, node as ILeafNode) |
32 | } | 40 | } |
33 | } else if(context instanceof ViatraImport) { | 41 | } else if(context instanceof ViatraImport) { |
34 | super.getLinkedObjects(context, ref, node) | 42 | if(ref == viatraImport_ImportedViatra && node instanceof ILeafNode) { |
43 | return getViatra(context as ViatraImport, node as ILeafNode) | ||
44 | } | ||
45 | } else if(context instanceof PatternEntry) { | ||
46 | if(ref === patternEntry_Package) { | ||
47 | return getViatraPackage(context as PatternEntry,node) | ||
48 | } | ||
35 | } | 49 | } |
36 | return super.getLinkedObjects(context, ref, node) | 50 | return super.getLinkedObjects(context, ref, node) |
37 | } | 51 | } |
52 | |||
53 | def getViatraPackage(PatternEntry entry, INode node) { | ||
54 | val document = EcoreUtil2.getContainerOfType(entry,ConfigurationScript) | ||
55 | val nodeString = valueConverterService.toValue(node.text, | ||
56 | linkingHelper.getRuleNameFrom(node.grammarElement), node).toString.replaceAll("\\s","") | ||
57 | val patternModels = document.imports.filter(ViatraImport).map[it.importedViatra].filterNull | ||
58 | val List<EObject> patternModelsWithSameNamespace = patternModels.filter[nodeString.equals(it.packageName)].filter(EObject).toList | ||
59 | return patternModelsWithSameNamespace | ||
60 | } | ||
38 | 61 | ||
39 | private def getEPackage(EPackageImport packageImport, ILeafNode node) { | 62 | private def getEPackage(EPackageImport packageImport, ILeafNode node) { |
40 | getMetamodelNsUri(node).flatMap [ uri | | 63 | getNSUri(node).flatMap [ uri | |
41 | Optional.ofNullable(metamodelProvider.loadEPackage(uri, packageImport.eResource.resourceSet)) | 64 | Optional.ofNullable(metamodelProvider.loadEPackage(uri, packageImport.eResource.resourceSet)) |
42 | ].map [ ePackage | | 65 | ].map [ ePackage | |
43 | Collections.singletonList(ePackage as EObject) | 66 | Collections.singletonList(ePackage as EObject) |
44 | ].orElse(emptyList) | 67 | ].orElse(emptyList) |
45 | } | 68 | } |
69 | |||
70 | private def getViatra(ViatraImport viatraImport, ILeafNode node) { | ||
71 | val uri = getNSUri(node) | ||
72 | if(uri.present) { | ||
73 | var URI createdURI | ||
74 | try{ | ||
75 | createdURI = URI.createURI(uri.get) | ||
76 | }catch(IllegalArgumentException e) { | ||
77 | return super.getLinkedObjects(viatraImport, viatraImport_ImportedViatra, node) | ||
78 | } | ||
79 | var Resource res | ||
80 | try{ | ||
81 | res = viatraImport.eResource.resourceSet.getResource(createdURI,true); | ||
82 | } catch(RuntimeException e){ | ||
83 | return super.getLinkedObjects(viatraImport, viatraImport_ImportedViatra, node) | ||
84 | } | ||
85 | if(res!==null && !res.contents.empty) { | ||
86 | return #[res.contents.head] | ||
87 | } else { | ||
88 | return super.getLinkedObjects(viatraImport, viatraImport_ImportedViatra, node) | ||
89 | } | ||
90 | } else { | ||
91 | return super.getLinkedObjects(viatraImport, viatraImport_ImportedViatra, node) | ||
92 | } | ||
93 | } | ||
46 | 94 | ||
47 | private def getMetamodelNsUri(ILeafNode node) { | 95 | private def getNSUri(ILeafNode node) { |
48 | try { | 96 | try { |
49 | val convertedValue = valueConverterService.toValue(node.text, | 97 | val convertedValue = valueConverterService.toValue(node.text, |
50 | linkingHelper.getRuleNameFrom(node.grammarElement), node) | 98 | linkingHelper.getRuleNameFrom(node.grammarElement), node) |