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

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;

Or I use a terminal like in the ecoreDsl:

  SINT returns ecore::EIntegerObject :
       '-'? INT;

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

Then I tried to change my Value object:

  class Value {
      attr Object value;
      transient volatile attr String stringValue;
      transient volatile attr int intValue;
  }
  Value returns my::Value:
	intValue=SINT | stringValue= STRING;

This did not work either :-(

The last resort is to have fake string attributes in
my Value object to set a string value which then
converted to the object value in ValueImpl

  class Value {
      attr Object value;
      transient volatile attr String xtextHackStringValue;
      transient volatile attr String xtextHackIntValue;
  }

But this means I have to change my Existing EMF model
which I don't really like.....


Michael -- Michael Scharf Wind River Systems GmbH http://www.WindRiver.com http://MichaelScharf.blogspot.com/