diff options
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 | 186 |
1 files changed, 91 insertions, 95 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 fc4b721a..ec79ac89 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 | |||
@@ -2,6 +2,7 @@ package hu.bme.mit.inf.dslreasoner.application.linking | |||
2 | 2 | ||
3 | import com.google.inject.Inject | 3 | import com.google.inject.Inject |
4 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ApplicationConfigurationPackage | 4 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ApplicationConfigurationPackage |
5 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.CftImport | ||
5 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript | 6 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript |
6 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.EPackageImport | 7 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.EPackageImport |
7 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PatternEntry | 8 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.PatternEntry |
@@ -11,8 +12,10 @@ import java.util.List | |||
11 | import java.util.Optional | 12 | import java.util.Optional |
12 | import org.eclipse.emf.common.util.URI | 13 | import org.eclipse.emf.common.util.URI |
13 | import org.eclipse.emf.ecore.EObject | 14 | import org.eclipse.emf.ecore.EObject |
15 | import org.eclipse.emf.ecore.EPackage | ||
14 | import org.eclipse.emf.ecore.EReference | 16 | import org.eclipse.emf.ecore.EReference |
15 | import org.eclipse.emf.ecore.resource.Resource | 17 | import org.eclipse.emf.ecore.resource.Resource |
18 | import org.eclipse.emf.ecore.resource.ResourceSet | ||
16 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.IMetamodelProvider | 19 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.IMetamodelProvider |
17 | import org.eclipse.xtext.EcoreUtil2 | 20 | import org.eclipse.xtext.EcoreUtil2 |
18 | import org.eclipse.xtext.conversion.IValueConverterService | 21 | import org.eclipse.xtext.conversion.IValueConverterService |
@@ -20,105 +23,98 @@ import org.eclipse.xtext.conversion.ValueConverterException | |||
20 | import org.eclipse.xtext.linking.impl.DefaultLinkingService | 23 | import org.eclipse.xtext.linking.impl.DefaultLinkingService |
21 | import org.eclipse.xtext.nodemodel.ILeafNode | 24 | import org.eclipse.xtext.nodemodel.ILeafNode |
22 | import org.eclipse.xtext.nodemodel.INode | 25 | import org.eclipse.xtext.nodemodel.INode |
23 | import org.eclipse.emf.ecore.resource.ResourceSet | ||
24 | import org.eclipse.emf.ecore.EPackage | ||
25 | 26 | ||
26 | class ApplicationConfigurationLinkingService extends DefaultLinkingService{ | 27 | class ApplicationConfigurationLinkingService extends DefaultLinkingService { |
28 | @Inject IValueConverterService valueConverterService | ||
29 | @Inject IMetamodelProvider metamodelProvider | ||
27 | 30 | ||
28 | //@Inject Logger logger | 31 | public static extension ApplicationConfigurationPackage pac = ApplicationConfigurationPackage.eINSTANCE |
29 | 32 | ||
30 | @Inject IValueConverterService valueConverterService | 33 | override getLinkedObjects(EObject context, EReference ref, INode node) { |
31 | @Inject IMetamodelProvider metamodelProvider | 34 | if (context instanceof EPackageImport) { |
32 | 35 | if (ref == EPackageImport_ImportedPackage && node instanceof ILeafNode) { | |
33 | public static extension ApplicationConfigurationPackage pac = ApplicationConfigurationPackage.eINSTANCE | 36 | return getEPackage(context, node as ILeafNode) |
37 | } | ||
38 | } else if (context instanceof ViatraImport) { | ||
39 | if (ref == viatraImport_ImportedViatra) { | ||
40 | return getViatra(context, node) | ||
41 | } | ||
42 | } else if (context instanceof CftImport) { | ||
43 | if (ref == cftImport_ImportedCft) { | ||
44 | return getCftModel(context, node) | ||
45 | } | ||
46 | } | ||
47 | return super.getLinkedObjects(context, ref, node) | ||
48 | } | ||
49 | |||
50 | private def getEPackage(EPackageImport packageImport, ILeafNode node) { | ||
51 | val x = getNSUri(node) | ||
52 | if (x.isPresent) { | ||
53 | val uriString = x.get | ||
54 | val epackageByMetamodelProvider = metamodelProvider.loadEPackage(uriString, | ||
55 | packageImport.eResource.resourceSet) | ||
56 | val epackageByMe = ePackageByMe(packageImport.eResource.resourceSet, uriString) | ||
57 | if (epackageByMetamodelProvider !== null) { | ||
58 | return Collections.singletonList(epackageByMetamodelProvider as EObject) | ||
59 | } else if (epackageByMe !== null) { | ||
60 | return Collections.singletonList(epackageByMe as EObject) | ||
61 | } else { | ||
62 | emptyList | ||
63 | } | ||
64 | } else { | ||
65 | return emptyList | ||
66 | } | ||
67 | } | ||
34 | 68 | ||
35 | override getLinkedObjects(EObject context, EReference ref, INode node) { | 69 | private def ePackageByMe(ResourceSet rs, String uri) { |
36 | if(context instanceof EPackageImport) { | 70 | try { |
37 | if(ref == EPackageImport_ImportedPackage && node instanceof ILeafNode) { | 71 | val resource = rs.getResource(URI.createURI(uri), true); |
38 | return getEPackage(context as EPackageImport, node as ILeafNode) | 72 | return resource.contents.head as EPackage |
39 | } | 73 | } catch (Exception e) { |
40 | } else if(context instanceof ViatraImport) { | 74 | return null |
41 | if(ref == viatraImport_ImportedViatra) { | 75 | } |
42 | return getViatra(context as ViatraImport, node) | 76 | } |
43 | } | 77 | |
44 | } else if(context instanceof PatternEntry) { | 78 | private def getViatra(ViatraImport viatraImport, INode node) { |
45 | if(ref === patternEntry_Package) { | 79 | getByUri(viatraImport, viatraImport_ImportedViatra, node) |
46 | return getViatraPackage(context as PatternEntry,node) | 80 | } |
47 | } | ||
48 | } | ||
49 | return super.getLinkedObjects(context, ref, node) | ||
50 | } | ||
51 | 81 | ||
52 | def getViatraPackage(PatternEntry entry, INode node) { | 82 | private def getByUri(EObject context, EReference ref, INode node) { |
53 | val document = EcoreUtil2.getContainerOfType(entry,ConfigurationScript) | 83 | val uri = getNSUri(node) |
54 | val nodeString = valueConverterService.toValue(node.text, | 84 | if (uri.present) { |
55 | linkingHelper.getRuleNameFrom(node.grammarElement), node).toString.replaceAll("\\s","") | 85 | var URI createdURI |
56 | val patternModels = document.imports.filter(ViatraImport).map[it.importedViatra].filterNull | 86 | try { |
57 | val List<EObject> patternModelsWithSameNamespace = patternModels.filter[nodeString.equals(it.packageName)].filter(EObject).toList | 87 | createdURI = URI.createURI(uri.get) |
58 | return patternModelsWithSameNamespace | 88 | } catch (IllegalArgumentException e) { |
89 | return super.getLinkedObjects(context, ref, node) | ||
90 | } | ||
91 | var Resource res | ||
92 | try { | ||
93 | res = context.eResource.resourceSet.getResource(createdURI, true); | ||
94 | } catch (RuntimeException e) { | ||
95 | return super.getLinkedObjects(context, ref, node) | ||
96 | } | ||
97 | if (res !== null && res.contents !== null) { | ||
98 | return res.contents.filter[ref.EType.isInstance(it)].toList | ||
99 | } else { | ||
100 | return super.getLinkedObjects(context, ref, node) | ||
101 | } | ||
102 | } else { | ||
103 | return super.getLinkedObjects(context, ref, node) | ||
104 | } | ||
59 | } | 105 | } |
60 | 106 | ||
61 | private def getEPackage(EPackageImport packageImport, ILeafNode node) { | 107 | private def getNSUri(INode node) { |
62 | val x = getNSUri(node) | 108 | try { |
63 | if(x.isPresent) { | 109 | val convertedValue = valueConverterService.toValue(node.text, |
64 | val uriString = x.get | 110 | linkingHelper.getRuleNameFrom(node.grammarElement), node) |
65 | val epackageByMetamodelProvider = metamodelProvider.loadEPackage(uriString, packageImport.eResource.resourceSet) | 111 | Optional.of(convertedValue as String) |
66 | val epackageByMe = ePackageByMe(packageImport.eResource.resourceSet,uriString) | 112 | } catch (ValueConverterException e) { |
67 | //println(epackageByMetamodelProvider) | 113 | Optional.empty |
68 | //println(epackageByMe) | 114 | } |
69 | if(epackageByMetamodelProvider!==null) { | 115 | } |
70 | return Collections.singletonList(epackageByMetamodelProvider as EObject) | 116 | |
71 | } else if(epackageByMe !== null) { | 117 | private def getCftModel(CftImport context, INode node) { |
72 | return Collections.singletonList(epackageByMe as EObject) | 118 | getByUri(context, cftImport_ImportedCft, node) |
73 | } else { | 119 | } |
74 | emptyList | 120 | } |
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 | } | ||
88 | } | ||
89 | |||
90 | private def getViatra(ViatraImport viatraImport, INode node) { | ||
91 | val uri = getNSUri(node) | ||
92 | if(uri.present) { | ||
93 | var URI createdURI | ||
94 | try{ | ||
95 | createdURI = URI.createURI(uri.get) | ||
96 | }catch(IllegalArgumentException e) { | ||
97 | return super.getLinkedObjects(viatraImport, viatraImport_ImportedViatra, node) | ||
98 | } | ||
99 | var Resource res | ||
100 | try{ | ||
101 | res = viatraImport.eResource.resourceSet.getResource(createdURI,true); | ||
102 | } catch(RuntimeException e){ | ||
103 | return super.getLinkedObjects(viatraImport, viatraImport_ImportedViatra, node) | ||
104 | } | ||
105 | if(res!==null && !res.contents.nullOrEmpty) { | ||
106 | return #[res.contents.head] | ||
107 | } else { | ||
108 | return super.getLinkedObjects(viatraImport, viatraImport_ImportedViatra, node) | ||
109 | } | ||
110 | } else { | ||
111 | return super.getLinkedObjects(viatraImport, viatraImport_ImportedViatra, node) | ||
112 | } | ||
113 | } | ||
114 | |||
115 | private def getNSUri(INode node) { | ||
116 | try { | ||
117 | val convertedValue = valueConverterService.toValue(node.text, | ||
118 | linkingHelper.getRuleNameFrom(node.grammarElement), node) | ||
119 | Optional.of(convertedValue as String) | ||
120 | } catch (ValueConverterException e) { | ||
121 | Optional.empty | ||
122 | } | ||
123 | } | ||
124 | } \ No newline at end of file | ||