Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Custom validation failure messages
Custom validation failure messages [message #671951] Thu, 19 May 2011 08:43 Go to next message
Darie Moldovan is currently offline Darie Moldovan
Messages: 67
Registered: November 2010
Location: Darmstadt, Germany
Member
Hi,

after reading the discussion here, I tried the feature of defining custom messages for the validation myself. Although I followed the steps mentioned there, I still didn't get to see my message when constraints are violated.

I checked this bug and read pages 87-88 from this presentation, to be sure I'm not omitting something. The custom messages are simply not shown in my xtext editor.

Here's what I tried: after defining an invariant, I wanted to show a custom message when the validation returns an error, something like (in oclinecore)

invariant OrdinalIsUnique('Ordinals must be unique.'): 
	ElemA.allInstances()->excluding(self).ordinal->excludes(ordinal);


or, in Ecore

<eAnnotations source="http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot">
  <details key="OrdinalIsUnique" value="(((ElemA.allInstances())->excluding(self))->collect(ordinal))->excludes(ordinal)"/>
  <details key="OrdinalIsUnique$message" value="'Ordinals must be unique.'"/>
</eAnnotations>


but the custom message is not shown in the xtext editor. If I define

ElemA one (
    ordinal 0
)

ElemA two (
    ordinal 1
)

ElemA three(
    ordinal 0 // not valid, according to the invariant
)


the marker is shown at the right line and the validation returns the following error:

The 'OrdinalIsUnique' constraint is violated on 'MyDSL.impl.ElemAImpl @ 677646{platform:/resource/TestOCLXtext2/src/basic.MyDSL#//@elements.0}'

which is correct, because the constraint is, indeed, violated. But why isn't my message shown? As I said, my generated validator inherits OCLinEcoreEObjectValidator, I checked that the class is not generated and I added org.eclipse.ocl.examples.xtext.oclinecore as a dependency in the manifest. In my case, it does not work.

Tested with:

Eclipse Indigo Build id: 20110505-1223
Xtext 2.0.0.v201105170444
OCL 3.1.0.v20110502-1445

Any clues why this might still not work?

Thanks in advance.

Darie
Re: Custom validation failure messages [message #671954 is a reply to message #671951] Thu, 19 May 2011 08:56 Go to previous messageGo to next message
Darie Moldovan is currently offline Darie Moldovan
Messages: 67
Registered: November 2010
Location: Darmstadt, Germany
Member
Updating the OCL to the RC1 from the update site http://download.eclipse.org/modeling/mdt/ocl/updates/milestones/3.1.0 didn't help either. The custom message still does not appear in the xtext editor.
Re: Custom validation failure messages [message #672196 is a reply to message #671954] Fri, 20 May 2011 05:26 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 3151
Registered: July 2009
Senior Member
Hi Darie

Sorry for the slow reply. I've been testing the RC1 tooling by using it
to modelize the OCL specification as a preliminary to auto-generation
thereof; pretty successfully though I have quite a few good-to-do's for RC2.

I'll try to make sure any bit rot that has set in on custom messages is
fixed for RC2 too. New tutorials and example projects should then appear
in RC3.

Regards

Ed Willink


On 19/05/2011 13:56, Darie wrote:
> Updating the OCL to the RC1 from the update site
> http://download.eclipse.org/modeling/mdt/ocl/updates/milestones/3.1.0
> didn't help either. The custom message still does not appear in the
> xtext editor.
Re: Custom validation failure messages [message #672370 is a reply to message #672196] Fri, 20 May 2011 16:38 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 3151
Registered: July 2009
Senior Member
Hi Darie

Yes, the bit rot had set in.

The NoEObjectCompositeEValidator class was a workaround because I didn't
know how to exploit field injection. Once Sven explained that

public Class<? extends CompositeEValidator> bindCompositeEValidator() {
return NoEObjectCompositeEValidator.class;
}

could be replaced by

@Override
public void configure(Binder binder) {
super.configure(binder);

binder.bindConstant().annotatedWith(Names.named(org.eclipse.xtext.validation.CompositeEValidator.USE_EOBJECT_VALIDATOR)).to(false);
}

I deleted the redundant class, so the tutorial is broken on M7 and RC1.

You may do the replacement above in your XXXRuntimeModule, or wait till
RC2 for which I've re-instated but deprecated NoEObjectCompositeEValidator.

Sorry for the trouble. Thanks for the notification.

Regards

Ed Willink


On 20/05/2011 10:26, Ed Willink wrote:
> Hi Darie
>
> Sorry for the slow reply. I've been testing the RC1 tooling by using
> it to modelize the OCL specification as a preliminary to
> auto-generation thereof; pretty successfully though I have quite a few
> good-to-do's for RC2.
>
> I'll try to make sure any bit rot that has set in on custom messages
> is fixed for RC2 too. New tutorials and example projects should then
> appear in RC3.
>
> Regards
>
> Ed Willink
>
>
> On 19/05/2011 13:56, Darie wrote:
>> Updating the OCL to the RC1 from the update site
>> http://download.eclipse.org/modeling/mdt/ocl/updates/milestones/3.1.0
>> didn't help either. The custom message still does not appear in the
>> xtext editor.
>
Re: Custom validation failure messages [message #672472 is a reply to message #672370] Sat, 21 May 2011 03:29 Go to previous messageGo to next message
Darie Moldovan is currently offline Darie Moldovan
Messages: 67
Registered: November 2010
Location: Darmstadt, Germany
Member
Hi Ed,

thank you very much for your time. It's no big deal doing that replacement, but I think I'll wait for the RC2. Anyway, thanks for the tip!

Have a nice weekend.

Darie
Re: Custom validation failure messages [message #673599 is a reply to message #672472] Tue, 24 May 2011 04:31 Go to previous messageGo to next message
Darie Moldovan is currently offline Darie Moldovan
Messages: 67
Registered: November 2010
Location: Darmstadt, Germany
Member
Hi Ed,

I made the replacement, just to see if it works. And it does, indeed. The custom messages are shown as warnings. By the way, is there a possibility to customize the type of the message (i.e. warning/error/information)? It's really not important, it just came into my head.

Regards,

Darie
Re: Custom validation failure messages [message #673625 is a reply to message #673599] Tue, 24 May 2011 05:39 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 3151
Registered: July 2009
Senior Member
Hi Darie

Yes. See the asError() wrapper that exploits the 'value' of the invariant.

def: asError(verdict : Boolean) : Boolean =
if verdict then true else null endif

true = success
false = warning
null = failure
invalid = disaster

Regards

Ed Willink

On 24/05/2011 09:31, Darie wrote:
> Hi Ed,
>
> I made the replacement, just to see if it works. And it does, indeed.
> The custom messages are shown as warnings. By the way, is there a
> possibility to customize the type of the message (i.e.
> warning/error/information)? It's really not important, it just came
> into my head.
>
> Regards,
>
> Darie
Re: Custom validation failure messages [message #673692 is a reply to message #673625] Tue, 24 May 2011 09:38 Go to previous messageGo to next message
Darie Moldovan is currently offline Darie Moldovan
Messages: 67
Registered: November 2010
Location: Darmstadt, Germany
Member
Hi Ed,

thank you very much!

Regards,

Darie
Re: Custom validation failure messages [message #1059449 is a reply to message #672370] Sat, 18 May 2013 13:20 Go to previous message
Reinaldo Junior is currently offline Reinaldo Junior
Messages: 32
Registered: March 2011
Member

Ed Willink wrote on Fri, 20 May 2011 17:38

@Override
public void configure(Binder binder) {
super.configure(binder);

binder.bindConstant().annotatedWith(Names.named(org.eclipse.xtext.validation.CompositeEValidator.USE_EOBJECT_VALIDATOR)).to(false);
}


Is it still valid on Juno SR2? I can't make it work with the following tooling, and can't find out if it's either incompatibility or a silly mistake:

* Eclipse Juno
Version: 4.2.2
Build id: M20130204-1200

* Eclipse Modeling Framework Runtime and Tools
Version: 2.8.3.v20130125-0826
Build id: R201301250826

* Xtext SDK
Version: 2.4.1.v201304180855

* OCL (Object Constraint Language)
Version: 3.2.2.v20130128-1158
Build id: M201301281158


The source code (and more details) is available at this github repo: https://github.com/juniorz/playing-with-eclipse-mdt

Thanks for any help!
Previous Topic:How to specify integer value in an invariant?
Goto Forum:
  


Current Time: Mon May 20 00:58:14 EDT 2013

Powered by FUDForum. Page generated in 0.01742 seconds