Unique Id Constraint does not validate [message #1744332] |
Sun, 25 September 2016 19:35  |
Eclipse User |
|
|
|
Hello everyone,
I have the following example ECore metamodel with some OCL constraints:
...
/*
* OCL Constraint: UniqueIdentifiableInstance
* Every EClass that implements Identifiable interface has an identifier attribute. The value of this attribute must be unique for each instance.
*
*/
abstract class Identifiable { interface }
{
attribute identifier : String[1];
attribute name : String[?];
attribute description : String[?];
invariant UniqueIdentifiableInstance: self.oclType().allInstances()->forAll(id1, id2 |id1 <> id2 implies id1.identifier <> id2.identifier);
}
class SomeOtherEClass extends ParentClass,Identifiable;
...
Interestingly, I have used exactly the same Identifiable EClass in some other metamodel with the same OCL constraint, it is working correctly with that metamodel. But, this constraint does not work with the given example metamodel. By the way, this metamodel includes other EClasses with other OCL constraints that are correctly working.
Note: In Eclipse, I write the OCL constraints by right-clicking on the ECore file and choosing the OCLinECore editor. After creating a model of the metamodel, I right-click on the root element of the model and click "Validate" option (Live Validation is also on.).
|
|
|
|
Re: Unique Id Constraint does not validate [message #1744336 is a reply to message #1744334] |
Mon, 26 September 2016 01:15  |
Eclipse User |
|
|
|
Hi
You report a flaky behavior but only provide a partial metamodel and no models. Not nearly enough to investigate.
https://wiki.eclipse.org/OCL/ForumNetiquette may help.
What version are you using; IIRC an inheritance issue was fixed in Neon.
...->isUnique(identifier)
should be more efficient and readable.
self.oclType().allInstances()->
means you actually use the current type so for a ParentClass you actually execute ParentClass::allInstances()->.... Simpler to just
Identifiable::allInstances()->isUnique(identifier)
But that is unlikely to address the flaky behavior. Full repro needed.
Regards
Ed Willink
|
|
|
Powered by
FUDForum. Page generated in 0.03736 seconds