Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » ValueConverter
ValueConverter [message #1771567] Mon, 28 August 2017 07:48 Go to next message
Susie Agerholm is currently offline Susie AgerholmFriend
Messages: 54
Registered: April 2017
Member
Hi, I am trying to implement a value converter to convert a terminal to a float - but looks like xtext doesn-t see the converter. Should I register elsewhere?

The terminal is in my grammar:
SIGNED_NUMERIC:
('-')? (INT | FLOAT | SCIENTIFIC) | REFLECT
;

terminal REFLECT returns ecore::EFloat:
'reflect'
;

The ValueConverter is registeret in RuntimeModule:
 @Override
	override Class<? extends IValueConverterService> bindIValueConverterService() {
         URDFValueConverter
    }


An ValueConverter:

import com.google.inject.Inject;

public class URDFValueConverter extends DefaultTerminalConverters {
	
	 @ValueConverter(rule = "REFLECT")
	    public IValueConverter<Float> REFLECT() {
	        return new IValueConverter<Float>() {
	           
				@Override
				public Float toValue(String string, INode node) throws ValueConverterException {
					// TODO Auto-generated method stub
					String hej = "hello world";
					return Float.parseFloat("25");
				}

				@Override
				public String toString(Float value) throws ValueConverterException {
					// TODO Auto-generated method stub
					return null;
				}
	        };

	 }
}

Re: ValueConverter [message #1771569 is a reply to message #1771567] Mon, 28 August 2017 07:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11626
Registered: July 2009
Senior Member
method name and annotation should be SIGNED_NUMERIC if you want to add a value converter for that
SIGNED_NUMERIC is a dataytpe rule so value converters for REFLECT will be called only for places where it is used like value=REFLECT


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: ValueConverter [message #1771582 is a reply to message #1771569] Mon, 28 August 2017 10:06 Go to previous message
Susie Agerholm is currently offline Susie AgerholmFriend
Messages: 54
Registered: April 2017
Member
ok - makes sense. Thanks a lot :)
Previous Topic:[SOLVED] Simple "assert" support
Next Topic:ecore model location
Goto Forum:
  


Current Time: Mon Jan 22 22:35:47 GMT 2018

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

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