Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » EClassifier for primitive variables
EClassifier for primitive variables [message #52106] Tue, 04 March 2008 02:04 Go to next message
Stefan Schulze is currently offline Stefan SchulzeFriend
Messages: 70
Registered: July 2009
Member
Hi...

how can I define a context-variable of a primitive type like an integer? As
the most simple example, I want to evaluate "a+a" after setting "a" as an
integer-variable with value "1" in the (Evaluation)Environment.
If I set EcorePackage.Literals.EINT as variable-type, I get a
SemanticException about "Cannot find operation (+(EInt)) for the type
(EInt).
If I set TypesPackage.eINSTANCE.getPrimitiveType() as variable-type, I get a
SemanticException about "Cannot find operation (+(PrimitiveType)) for the
type (PrimitiveType).
I thought about using Environment#getOCLStandardLibrary().getInteger(), but
that didn't work, because the result is an EObject but I need an EClassifier
for Variable#setType(...).

Stefan
Re: EClassifier for primitive variables [message #52159 is a reply to message #52106] Tue, 04 March 2008 14:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Stefan,

The EcoreEnvironment maps EInt, EIntegerObject, and friends to the Integer
primitive type from the OCL Standard Library when used as the types of
ETypedElements in the model. That is automatic. Because OCL knows how to
define operations for its own data types, but EDataTypes generally cannot
express operations, this is important for '+' etc. to work.

The same type mapping is not done for Variables because OCL Variables cannot
occur in a model (in particular, they have no relation to the UML construct
of the same name). If you are creating your own Variables and adding them
to an Environment, then you need to use the OCL-defined standard types
where appropriate.

It sounds from your last remark that you are trying to do this
(OCLStandardLibrary::getInteger() is the right way). Why is it not
working? I don't know what you mean by the result being an EObject. The
OCL Integer type is not a class; its instances are not EObjects.

HTH,

Christian


Stefan Schulze wrote:

> Hi...
>
> how can I define a context-variable of a primitive type like an integer?
> As the most simple example, I want to evaluate "a+a" after setting "a" as
> an integer-variable with value "1" in the (Evaluation)Environment.
> If I set EcorePackage.Literals.EINT as variable-type, I get a
> SemanticException about "Cannot find operation (+(EInt)) for the type
> (EInt).
> If I set TypesPackage.eINSTANCE.getPrimitiveType() as variable-type, I get
> a SemanticException about "Cannot find operation (+(PrimitiveType)) for
> the type (PrimitiveType).
> I thought about using Environment#getOCLStandardLibrary().getInteger(),
> but that didn't work, because the result is an EObject but I need an
> EClassifier for Variable#setType(...).
>
> Stefan
Re: EClassifier for primitive variables [message #52184 is a reply to message #52159] Tue, 04 March 2008 15:15 Go to previous message
Stefan Schulze is currently offline Stefan SchulzeFriend
Messages: 70
Registered: July 2009
Member
"Christian W. Damus" <cdamus@ca.ibm.com> schrieb im Newsbeitrag
news:fqjma8$7gm$1@build.eclipse.org...
> It sounds from your last remark that you are trying to do this
> (OCLStandardLibrary::getInteger() is the right way). Why is it not
> working? I don't know what you mean by the result being an EObject. The
> OCL Integer type is not a class; its instances are not EObjects.

Hi Christian,

I'm not sure what I did that getInteger() returned an EObject. Probably I
simply mix it up.
After your post I tried it again and it works really fine. :)

Thanks for your help,
Stefan
Previous Topic:OCL constraints using Date attributes
Next Topic:converting a integer to a string.
Goto Forum:
  


Current Time: Thu Apr 25 22:25:51 GMT 2024

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

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

Back to the top