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