Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Conversion between OCL datatypes and Ecore datatypes(Conversion from ecore::EByte to Integer seems to be broken)
Conversion between OCL datatypes and Ecore datatypes [message #728415] Fri, 23 September 2011 08:56 Go to next message
Vlad Gheorghe is currently offline Vlad GheorgheFriend
Messages: 127
Registered: May 2011
Senior Member
Hi list,

I'm using OCL to write constraints for an Ecore model.

In order to build OCL queries with attributes having Ecore datatypes, these need to be converted to OCL datatypes (e.g. Integer).


(I'm using OCL from Indigo -
OCL Interpreter Console 3.1.0.v20110606-1427 org.eclipse.ocl.examples.feature.group):


class A {
     ab : ecore::EByte;
     as : ecore::EShort;
     ai : ecore::EInt;
}


1) Conversion from ecore datatype to OCL numeric datatype
Evaluating:
self.ab + 1
Results:
Cannot find operation (+(Integer)) for the type (EByte)

Evaluating:
Set { 1 .. self.ab}
Results:
First and last type mismatch: (1 .. self.ab)


Evaluating:
self.as  + 1
Results:
4

Evaluating:
Set { 1.. self.as  }
Results:
OclInvalid 
--java.lang.ClassCastException: java.lang.Short cannot be cast to java.lang.Integer




These seem like quite inconsistent results for different cases of converting EByte and EShort to OCL Integer (I presume..).



2) conversion from OCL Integer to ecore datatype

Evaluating:
let a : ecore::EByte = 1 in a
Results:
Init expression type does not conform to type of variable (a).

Evaluating:
let a : ecore::EShort = 1 in a
Results:
1

Evaluating:
let a : ecore::EInt = 1 in a
Results:
1


It seems that this conversion should work, but it's broken for EByte.

Any suggestions please ?

Greets,
Vlad

Re: Conversion between OCL datatypes and Ecore datatypes [message #728430 is a reply to message #728415] Fri, 23 September 2011 09:26 Go to previous messageGo to next message
Axel Uhl is currently offline Axel UhlFriend
Messages: 41
Registered: July 2009
Member
Hi Vlad,

see https://bugs.eclipse.org/bugs/show_bug.cgi?id=344368 where another aspect of this problem is being discussed. Personally, I would find it just intuitive to transparently allow use of the Ecore numeric types as OCL Integer. As you can see from the bug, this unfortunately is not general consensus across the MDT/OCL committer base. Maybe you want to comment on the bug itself to add to and influence the discussion.

Best,
-- Axel
Re: Conversion between OCL datatypes and Ecore datatypes [message #728532 is a reply to message #728415] Fri, 23 September 2011 12:31 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Vald

Thank you for a very simple repro of what is a double bug.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=358712

is your immediate problem. The code to handle "byte" is missing and so the parsing analysis fails to find a suitable operation.

If you switch to the OCL Xtext Console the parsing succeeds but

https://bugs.eclipse.org/bugs/show_bug.cgi?id=358713

there is missing code to handle EByte values during evaluation.

The obvious workaround for now is to avoid bytes.

Regards

Ed Willink


On 23/09/2011 09:56, Vlad Gheorghe wrote:
> Hi list,
>
> I'm using OCL to write constraints for an Ecore model.
>
> In order to build OCL queries with attributes having Ecore datatypes,
> these need to be converted to OCL datatypes (e.g. Integer).
>
>
> (I'm using OCL from Indigo -
> OCL Interpreter Console 3.1.0.v20110606-1427
> org.eclipse.ocl.examples.feature.group):
>
>
>
> class A {
> ab : ecore::EByte;
> as : ecore::EShort;
> ai : ecore::EInt;
> }
>
>
> 1) Conversion from ecore datatype to OCL numeric datatype
>
> Evaluating:
> self.ab + 1
> Results:
> Cannot find operation (+(Integer)) for the type (EByte)
>
> Evaluating:
> Set { 1 .. self.ab}
> Results:
> First and last type mismatch: (1 .. self.ab)
>
>
> Evaluating:
> self.as + 1
> Results:
> 4
>
> Evaluating:
> Set { 1.. self.as }
> Results:
> OclInvalid --java.lang.ClassCastException: java.lang.Short cannot be
> cast to java.lang.Integer
>
>
>
>
> These seem like quite inconsistent results for different cases of
> converting EByte and EShort to OCL Integer (I presume..).
>
>
>
> 2) conversion from OCL Integer to ecore datatype
>
> Evaluating:
> let a : ecore::EByte = 1 in a
> Results:
> Init expression type does not conform to type of variable (a).
>
> Evaluating:
> let a : ecore::EShort = 1 in a
> Results:
> 1
>
> Evaluating:
> let a : ecore::EInt = 1 in a
> Results:
> 1
>
>
> It seems that this conversion should work, but it's broken for EByte.
>
> Any suggestions please ?
>
> Greets,
> Vlad
>
>
Previous Topic:Query Evaluate method
Next Topic:[Announce] Final Eclipse OCL 3.1.1 (Indigo Service Release 1) is now available
Goto Forum:
  


Current Time: Fri Apr 19 15:06:58 GMT 2024

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

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

Back to the top