Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Is it possible to write ValueConverter for EClass elements?
Is it possible to write ValueConverter for EClass elements? [message #1795903] Tue, 02 October 2018 07:48
Venkata Chittem is currently offline Venkata ChittemFriend
Messages: 13
Registered: October 2018
Junior Member
Hi buddies,
I am able to follow the procedure explained in the link below and write successfully a Value Converter for a ecore::EInt datatype.

However i have a case in which I would like to call a backend converter to convert string in the rule to the EMF EClass Object.

CustomEClass is EClass from my custom EMF Ecore model.

Below are the Xtext Rules:
CustomEClass_RULE returns CustomEClass:
('BoolVal' VALID_STRING ('true'|'false')) |

terminal VALID_STRING: (('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*);
UNSIGNED_INT: (('0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9')+);

Class Registering converter (
public class MyTerminalConverters
extends DefaultTerminalConverters
implements IValueConverterService {

private CustomEClassConverter customEClassConverter;
@ValueConverter(rule = "CustomEClass_RULE")
public IValueConverter<CustomEClass> CustomEClassConverter() {
return customEClassConverter;

Value Converter class (
public class customEClassConverter implements IValueConverter<customEClass> {

public customEClass toValue(String string, INode node) throws ValueConverterException {
if (Strings.isEmpty(string)) {
throw new ValueConverterException("Numerical value can not be empty string", node, null);
} else {
try {
customEClass retVal = myEmfFactory.eINSTANCE.createcustomEClass();
//TODO: retVal.setType(...) based on input "string"
//TODO: retVal.setValue(...) based on input "string"
return retVal;
} catch (NumberFormatException e1) {
throw new ValueConverterException("Couldn't convert '"+string+"' to Double/Floating Point Value ", node, null);

public String toString(customEClass value) throws ValueConverterException {
return null;

There is no problem in xtext generation and also in building the code, however In the runtime customEClassConverter is not being called for converting the user input string to customEClass type object.

Best Regards,
Previous Topic:Testing: Different start symbol for parsing
Next Topic:Is it possible to write ValueConverter for EClass elements?
Goto Forum:

Current Time: Fri Aug 19 21:17:29 GMT 2022

Powered by FUDForum. Page generated in 0.02022 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top