diff options
author | 2018-01-30 01:29:37 +0100 | |
---|---|---|
committer | 2018-01-30 01:29:37 +0100 | |
commit | cc142b8ba0044c3e14d8d465761377c58d1a1347 (patch) | |
tree | 150f115cf4e2d38fa70148310789a664adf63380 /Application/hu.bme.mit.inf.dslreasoner.application/src | |
parent | Validators refactored (diff) | |
download | VIATRA-Generator-cc142b8ba0044c3e14d8d465761377c58d1a1347.tar.gz VIATRA-Generator-cc142b8ba0044c3e14d8d465761377c58d1a1347.tar.zst VIATRA-Generator-cc142b8ba0044c3e14d8d465761377c58d1a1347.zip |
Qualified name Converter
Diffstat (limited to 'Application/hu.bme.mit.inf.dslreasoner.application/src')
-rw-r--r-- | Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/valueconverter/QualifiedNameValueConverter.xtend | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/valueconverter/QualifiedNameValueConverter.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/valueconverter/QualifiedNameValueConverter.xtend new file mode 100644 index 00000000..e47d8962 --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/valueconverter/QualifiedNameValueConverter.xtend | |||
@@ -0,0 +1,42 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.valueconverter | ||
2 | |||
3 | import com.google.inject.Inject | ||
4 | import org.eclipse.emf.ecore.EObject | ||
5 | import org.eclipse.xtext.RuleCall | ||
6 | import org.eclipse.xtext.conversion.IValueConverterService | ||
7 | import org.eclipse.xtext.conversion.ValueConverterException | ||
8 | import org.eclipse.xtext.conversion.impl.AbstractValueConverter | ||
9 | import org.eclipse.xtext.nodemodel.INode | ||
10 | |||
11 | class QualifiedNameValueConverter extends AbstractValueConverter<String>{ | ||
12 | |||
13 | @Inject | ||
14 | protected IValueConverterService valueConverterService; | ||
15 | |||
16 | override toString(String value) throws ValueConverterException { | ||
17 | //println('''toString: «value»''') | ||
18 | return value | ||
19 | } | ||
20 | |||
21 | override toValue(String string, INode node) throws ValueConverterException { | ||
22 | //println('''toValue: «string»''') | ||
23 | if (node != null) { | ||
24 | val segments = node.leafNodes.filter[grammarElement.isDelegateRuleCall].map[it.text] | ||
25 | val res = segments.join('.') | ||
26 | return res | ||
27 | } else { | ||
28 | val segments = string.split('\\.') | ||
29 | val translatedSegments = segments.map[valueConverterService.toValue(it,"ID",null)] | ||
30 | val res = translatedSegments.join('.') | ||
31 | return res | ||
32 | } | ||
33 | } | ||
34 | |||
35 | def protected boolean isDelegateRuleCall(EObject grammarElement) { | ||
36 | if(grammarElement instanceof RuleCall) { | ||
37 | grammarElement.rule.name == "ID" | ||
38 | } else { | ||
39 | return false | ||
40 | } | ||
41 | } | ||
42 | } | ||