Custom OCL messages [message #1460384] |
Mon, 03 November 2014 09:10  |
Eclipse User |
|
|
|
Hi,
I am trying to use custom OCL messages, but have no success.
I have checked this thread: https://www.eclipse.org/forums/index.php/t/392067/ (as I understood this issue were resolved in releases after indigo).
My invariant:
invariant nonEmptyType('Type must be any non-empty'): self.type->notEmpty();
But my generated validator does not use my custom messages and I am getting standard message:
Constraint is violated for .... ...
I am using luna release. How I can fix this?
|
|
|
|
|
|
|
Re: Custom OCL messages [message #1462228 is a reply to message #1462090] |
Wed, 05 November 2014 05:51  |
Eclipse User |
|
|
|
Hi
https://wiki.eclipse.org/OCL/ForumNetiquette
Regards
Ed Willink
On 05/11/2014 07:34, Igor Zapletnev wrote:
> Thanks for response. But I still could not find way how to use custom
> error messages. Documentation looks weird for me.
>
> http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FIntegration.html&cp=49_1_7
>
> Quote:
>> invariant SufficientCopies('There are ' + library.loans->select((book
>> = self))->size().toString() + ' loans for the ' + copies.toString() +
>> ' copies of \'' + name + '\''):
>> library.loans->select((book = self))->size() <= copies;
>>
>> Unfortunately, in the Indigo release, EMF does not support this
>> customization. This must be activated explicitly using an EValidator
>> that is aware of the ValidationDelegateExtension extended API. This is
>> available by using the OCLinEcoreEObjectValidator.
>
>
> I have tried this syntax, but have no success. I am using Luna and I
> don't need any manually modifications.
>
> But I also tried to use OCLinEcoreEObjectValidator.java class and my
> invariants could not be found, because it's using some annotations on
> eOperation:
>
> String expression = EcoreUtil.getAnnotation(eOperation,
> validationDelegate, "body");
>
> But my OCLinEditor doesn't generate it.
>
> class MyModel
> {
> property type : ecore::EClassifier[?];
> invariant nonEmptyType('Type must be any non-empty'):
> self.type->notEmpty();
> }
>
> Produced code:
>
> <eClassifiers xsi:type="ecore:EClass" name="NamedVariable">
> <eAnnotations source="http://www.eclipse.org/emf/2002/Ecore">
> <details key="constraints" value="nonEmptyType"/>
> </eAnnotations>
> <eAnnotations source="http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot">
> <details key="nonEmptyType" value="self.type->notEmpty()"/>
> <details key="nonEmptyType$message" value="'Type must be any
> non-empty'"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EReference" name="type"
> eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EClassifier"/>
> </eClassifiers>
>
>
> Can I find anywhere stable example and/or tutorial?
|
|
|
Powered by
FUDForum. Page generated in 0.04545 seconds