From cc142b8ba0044c3e14d8d465761377c58d1a1347 Mon Sep 17 00:00:00 2001 From: OszkarSemerath Date: Tue, 30 Jan 2018 01:29:37 +0100 Subject: Qualified name Converter --- .../QualifiedNameValueConverter.xtend | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/valueconverter/QualifiedNameValueConverter.xtend (limited to 'Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme') 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 @@ +package hu.bme.mit.inf.dslreasoner.application.valueconverter + +import com.google.inject.Inject +import org.eclipse.emf.ecore.EObject +import org.eclipse.xtext.RuleCall +import org.eclipse.xtext.conversion.IValueConverterService +import org.eclipse.xtext.conversion.ValueConverterException +import org.eclipse.xtext.conversion.impl.AbstractValueConverter +import org.eclipse.xtext.nodemodel.INode + +class QualifiedNameValueConverter extends AbstractValueConverter{ + + @Inject + protected IValueConverterService valueConverterService; + + override toString(String value) throws ValueConverterException { + //println('''toString: «value»''') + return value + } + + override toValue(String string, INode node) throws ValueConverterException { + //println('''toValue: «string»''') + if (node != null) { + val segments = node.leafNodes.filter[grammarElement.isDelegateRuleCall].map[it.text] + val res = segments.join('.') + return res + } else { + val segments = string.split('\\.') + val translatedSegments = segments.map[valueConverterService.toValue(it,"ID",null)] + val res = translatedSegments.join('.') + return res + } + } + + def protected boolean isDelegateRuleCall(EObject grammarElement) { + if(grammarElement instanceof RuleCall) { + grammarElement.rule.name == "ID" + } else { + return false + } + } +} -- cgit v1.2.3-54-g00ecf