Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Unique Id Constraint does not validate
Unique Id Constraint does not validate [message #1744332] Sun, 25 September 2016 23:35 Go to next message
Eclipse UserFriend
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 #1744334 is a reply to message #1744332] Sun, 25 September 2016 23:44 Go to previous messageGo to next message
Eclipse UserFriend
One additional information. I achieve to run it in "ValidityView". But right-clicking and validating only works for some of the constraints.

Still, the constraint works by right-clicking and validating in the other metamodel.

Re: Unique Id Constraint does not validate [message #1744336 is a reply to message #1744334] Mon, 26 September 2016 05:15 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
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
Previous Topic:news.eclipse.org is shutting down.
Next Topic:Is Collection(T) covariant on T?
Goto Forum:
  


Current Time: Tue Apr 16 23:12:07 GMT 2024

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

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

Back to the top