Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » ValueConverter class is not getting called during runtime
ValueConverter class is not getting called during runtime [message #1109283] Sun, 15 September 2013 02:14 Go to next message
Ashwini Nayak is currently offline Ashwini Nayak
Messages: 19
Registered: July 2013
Junior Member
Hi,

I am new to xtext and facing several issues while working on it. I have explained the issue below:

sample.xtext

Variable:
"variable" name=QualifiedName ("[" array=[Array] "]")? "{"
("description" description=STRING)?
("indexStartBit" (indexStartBit=NumberLiteral )|("index" indexStartBit=Index))
"}"
;

Index returns NumberLiteral:
{NumberLiteral} (INT | Double | IntRange | DoubleRange)
;

Double returns ecore::EDouble:
(INT '.' INT)
;

IntRange:
(INT '-' INT)
;

DoubleRange:
(Double '-' Double)
;

NumberLiteral returns Expression:
{NumberLiteral} value=Number
;

Numberhidden():
HEX | ('-')? (INT | DECIMAL) ('.' (INT | DECIMAL))?;

sample.xcore
class Variable {
String name
refers Array array
String description
contains resolving Expression indexStartBit
}

class NumberLiteral extends Expression
{
String value
}

The requirement is: In my dsl editor, I should be allowed to enter either "indexStartBit" or "index". When I enter a value for "indexStartBit", the value will be directly stored in the "indexStartBit" field. But, when I enter a value for "index", the index value should be converted to "indexStartbit" and stored in the field, "indexStartBit"(since there is no field called "index" in my xcore).

I have written a ValueConverter class for the rule Index.
I will be converting the value of "index" to "indexStartBit" in my Valueconverter class.

ValueConverter class:

public class ValueConvertor extends AbstractDeclarativeValueConverterService {

@ValueConverter(rule = "Index")
public IValueConverter<Integer> IndexValues() {
return new IValueConverter<Integer>() {
@Override
public Integer toValue(final String string, final INode node) throws ValueConverterException {

//my code goes here

}
}


I have binded the Valueconverter class by writing the below code in my RuntimeModule class.

@Override
public Class<? extends IValueConverterService> bindIValueConverterService() {
return ValueConvertor.class;
}

But, my ValueConverter class does not get called during runtime. Can anybody tell me if I there is something wrong in my "Index" rule? What do I need to change in my grammar so that my ValueConverter class gets called when I type a value for "index" in my editor.

Thanks in advance

[Updated on: Sun, 15 September 2013 02:16]

Report message to a moderator

Re: ValueConverter class is not getting called during runtime [message #1109322 is a reply to message #1109283] Sun, 15 September 2013 03:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6230
Registered: July 2009
Senior Member
Hi value converters are for Terminals / Datatype rules and Not for EObjects
Re: ValueConverter class is not getting called during runtime [message #1111485 is a reply to message #1109322] Wed, 18 September 2013 05:30 Go to previous message
Ashwini Nayak is currently offline Ashwini Nayak
Messages: 19
Registered: July 2013
Junior Member
Thanks Christian Smile
Previous Topic:Grammar
Next Topic:Content assist within strings?
Goto Forum:
  


Current Time: Fri Aug 29 04:08:44 EDT 2014

Powered by FUDForum. Page generated in 0.02150 seconds