diff options
author | 2018-01-13 19:33:26 +0100 | |
---|---|---|
committer | 2018-01-13 19:33:26 +0100 | |
commit | 7e50434905cbb7f5d03636033b698e17a9075e9d (patch) | |
tree | 10e0968c20ac55dae4f5dc6077f39cf9947e3cb9 /Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/linking | |
parent | Test and measurement runners (diff) | |
download | VIATRA-Generator-7e50434905cbb7f5d03636033b698e17a9075e9d.tar.gz VIATRA-Generator-7e50434905cbb7f5d03636033b698e17a9075e9d.tar.zst VIATRA-Generator-7e50434905cbb7f5d03636033b698e17a9075e9d.zip |
Initial commit of the configuration language and application
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 | 56 |
1 files changed, 56 insertions, 0 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 new file mode 100644 index 00000000..15567f88 --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/linking/ApplicationConfigurationLinkingService.xtend | |||
@@ -0,0 +1,56 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.linking | ||
2 | |||
3 | import com.google.inject.Inject | ||
4 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ApplicationConfigurationPackage | ||
5 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.EPackageImport | ||
6 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ViatraImport | ||
7 | import java.util.Collections | ||
8 | import java.util.Optional | ||
9 | import org.eclipse.emf.ecore.EObject | ||
10 | import org.eclipse.emf.ecore.EReference | ||
11 | import org.eclipse.viatra.query.patternlanguage.emf.scoping.IMetamodelProvider | ||
12 | import org.eclipse.xtext.conversion.IValueConverterService | ||
13 | import org.eclipse.xtext.conversion.ValueConverterException | ||
14 | import org.eclipse.xtext.linking.impl.DefaultLinkingService | ||
15 | import org.eclipse.xtext.nodemodel.ILeafNode | ||
16 | import org.eclipse.xtext.nodemodel.INode | ||
17 | |||
18 | class ApplicationConfigurationLinkingService extends DefaultLinkingService{ | ||
19 | |||
20 | //@Inject Logger logger | ||
21 | |||
22 | @Inject IValueConverterService valueConverterService | ||
23 | |||
24 | @Inject IMetamodelProvider metamodelProvider | ||
25 | |||
26 | public static extension ApplicationConfigurationPackage pac = ApplicationConfigurationPackage.eINSTANCE | ||
27 | |||
28 | override getLinkedObjects(EObject context, EReference ref, INode node) { | ||
29 | if(context instanceof EPackageImport) { | ||
30 | if(ref == EPackageImport_ImportedPackage && node instanceof ILeafNode) { | ||
31 | return getEPackage(context as EPackageImport, node as ILeafNode) | ||
32 | } | ||
33 | } else if(context instanceof ViatraImport) { | ||
34 | super.getLinkedObjects(context, ref, node) | ||
35 | } | ||
36 | return super.getLinkedObjects(context, ref, node) | ||
37 | } | ||
38 | |||
39 | private def getEPackage(EPackageImport packageImport, ILeafNode node) { | ||
40 | getMetamodelNsUri(node).flatMap [ uri | | ||
41 | Optional.ofNullable(metamodelProvider.loadEPackage(uri, packageImport.eResource.resourceSet)) | ||
42 | ].map [ ePackage | | ||
43 | Collections.singletonList(ePackage as EObject) | ||
44 | ].orElse(emptyList) | ||
45 | } | ||
46 | |||
47 | private def getMetamodelNsUri(ILeafNode node) { | ||
48 | try { | ||
49 | val convertedValue = valueConverterService.toValue(node.text, | ||
50 | linkingHelper.getRuleNameFrom(node.grammarElement), node) | ||
51 | Optional.of(convertedValue as String) | ||
52 | } catch (ValueConverterException e) { | ||
53 | Optional.empty | ||
54 | } | ||
55 | } | ||
56 | } \ No newline at end of file | ||