[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.tmf] Re: How to assign an Object attribute an Integer, or String?

Hi Michael,

Michael Scharf wrote:
Hi,

I have a given EMF model that uses java.lang.Object to represent a
value.

  class Value {
      attr Object value;
  }

I want to convert the value to Integer or String (or Double etc).
This does not work:

  Value returns my::Value:
    value=INT | value= STRING;

The I thought maybe I use a data type rule:

  LiteralInteger returns ecore::EIntegerObject:
    INT;
  LiteralString returns ecore::EString:
    STRING;

  Value returns my::Value:
    value=LiteralInteger | value= LiteralString;


You were on the right track. You should declare your rules as follows:

Value:
	value=MyInt | value=MyString;
	
MyInt returns ecore::EJavaObject:
	INT;

MyString returns ecore::EJavaObject:
	STRING;

No you just need to define value converters for the datatype rules MyInt and MyValue.

Hope that helps,

--knut