Conversion between OCL datatypes and Ecore datatypes [message #728415] |
Fri, 23 September 2011 04:56  |
Eclipse User |
|
|
|
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 #728532 is a reply to message #728415] |
Fri, 23 September 2011 08:31  |
Eclipse User |
|
|
|
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
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.04095 seconds