Custom validation failure messages [message #671951] |
Thu, 19 May 2011 08:43  |
Eclipse User |
|
|
|
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 #1059820 is a reply to message #1059632] |
Tue, 21 May 2013 14:01   |
Eclipse User |
|
|
|
Hi
You need to use the OCLinEcoreEObjectValidator , which you are
source-wise, but you also need to use it at run-time, so you must run in
a nested Eclipse.
When I do that and fix JRE consistency, rebuild to expose the icons, I
get failures from a CDO CCE. I've never seen CDO in action so I'll look
a little further, but ...
https://bugs.eclipse.org/bugs/show_bug.cgi?id=408615 raised against CDO.
That fixed it still doesn't work. Changing the nsURI and rebuilding
fixes it.
Using the same URI for your example as for the original tutorial is very
very foolish (and 'illegal'; org.eclipse... is reserved for Eclipse
Foundation usage).
Regards
Ed Willink
On 21/05/2013 01:39, Reinaldo Junior wrote:
> I guess I haven't elaborated it properly.
>
> I'm able to violate the OCL constraint (by creating multiple loans) on
> both xmi and xtext files but I'm not able to see the custom message
> ("not enough copies") as specified in the ecore file
> (https://github.com/juniorz/playing-with-eclipse-mdt/blob/master/org.eclipse.oclinecore.tutorial/model/Library.ecore#L24)
>
> I've followed the instructions provided in the presentation (and
> summarised in this topic):
>
> 1. Change the Xtext validator to inherit from
> OCLinEcoreEObjectValidator -
> https://github.com/juniorz/playing-with-eclipse-mdt/blob/master/org.eclipse.oclinecore.tutorial/src/tutorial/util/TutorialValidator.java#L27
> 2. Override the configure method on XXXRuntimeModule[/url] -
> https://github.com/juniorz/playing-with-eclipse-mdt/blob/master/org.eclipse.oclinecore.tutorial.xtext/src/org/eclipse/oclinecore/tutorial/xtext/LibraryDslRuntimeModule.java#L15
>
> If I override the configure method, I have no validation at all. If I
> don't do it, I see the usual "The 'CONSTRAINT_NAME' constraint is
> violated on 'OBJECT NAME'" message.
>
> I'm using the latest Eclipse modeling release (a version different
> from the used in the tutorial).
>
> Thank you
|
|
|
Re: Custom validation failure messages [message #1059822 is a reply to message #1059820] |
Tue, 21 May 2013 14:05   |
Eclipse User |
|
|
|
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Hi<br>
<br>
You've also missed the<br>
<br>
Note the <span class="bold"><strong>@generated not</strong></span>
that indicates that the class interface is manually defined. Do
not use <span class="bold"><strong>@generated NOT</strong></span>
since that indicates that the whole class is manually defined.<br>
<br>
comment in the (current) documentation.<br>
<br>
Regards<br>
<br>
Ed Willink<br>
<br>
On 21/05/2013 19:01, Ed Willink wrote:<br>
</div>
<blockquote cite="mid:kngcps$ui4$1@xxxxxxxxe.org" type="cite">Hi
<br>
<br>
You need to use the OCLinEcoreEObjectValidator , which you are
source-wise, but you also need to use it at run-time, so you must
run in a nested Eclipse.
<br>
<br>
When I do that and fix JRE consistency, rebuild to expose the
icons, I get failures from a CDO CCE. I've never seen CDO in
action so I'll look a little further, but ...
<a class="moz-txt-link-freetext" href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=408615">https://bugs.eclipse.org/bugs/show_bug.cgi?id=408615</a> raised
against CDO.
<br>
<br>
That fixed it still doesn't work. Changing the nsURI and
rebuilding fixes it.
<br>
<br>
Using the same URI for your example as for the original tutorial
is very very foolish (and 'illegal'; org.eclipse... is reserved
for Eclipse Foundation usage).
<br>
<br>
Regards
<br>
<br>
Ed Willink
<br>
<br>
<br>
On 21/05/2013 01:39, Reinaldo Junior wrote:
<br>
<blockquote type="cite">I guess I haven't elaborated it properly.
<br>
<br>
I'm able to violate the OCL constraint (by creating multiple
loans) on both xmi and xtext files but I'm not able to see the
custom message ("not enough copies") as specified in the ecore
file
(<a class="moz-txt-link-freetext" href="https://github.com/juniorz/playing-with-eclipse-mdt/blob/master/org.eclipse.oclinecore.tutorial/model/Library.ecore#L24">https://github.com/juniorz/playing-with-eclipse-mdt/blob/master/org.eclipse.oclinecore.tutorial/model/Library.ecore#L24</a>)<br>
<br>
I've followed the instructions provided in the presentation (and
summarised in this topic):
<br>
<br>
1. Change the Xtext validator to inherit from
OCLinEcoreEObjectValidator -
<a class="moz-txt-link-freetext" href="https://github.com/juniorz/playing-with-eclipse-mdt/blob/master/org.eclipse.oclinecore.tutorial/src/tutorial/util/TutorialValidator.java#L27">https://github.com/juniorz/playing-with-eclipse-mdt/blob/master/org.eclipse.oclinecore.tutorial/src/tutorial/util/TutorialValidator.java#L27</a><br>
2. Override the configure method on XXXRuntimeModule[/url] -
<a class="moz-txt-link-freetext" href="https://github.com/juniorz/playing-with-eclipse-mdt/blob/master/org.eclipse.oclinecore.tutorial.xtext/src/org/eclipse/oclinecore/tutorial/xtext/LibraryDslRuntimeModule.java#L15">https://github.com/juniorz/playing-with-eclipse-mdt/blob/master/org.eclipse.oclinecore.tutorial.xtext/src/org/eclipse/oclinecore/tutorial/xtext/LibraryDslRuntimeModule.java#L15</a><br>
<br>
If I override the configure method, I have no validation at all.
If I don't do it, I see the usual "The 'CONSTRAINT_NAME'
constraint is violated on 'OBJECT NAME'" message.
<br>
<br>
I'm using the latest Eclipse modeling release (a version
different from the used in the tutorial).
<br>
<br>
Thank you
<br>
</blockquote>
<br>
</blockquote>
<br>
</body>
</html>
|
|
|
|
|
|
Re: Custom validation failure messages [message #1059894 is a reply to message #1059830] |
Wed, 22 May 2013 02:47   |
Eclipse User |
|
|
|
Hi
I don't understand how you are using your code so I don't understand why
you need three Eclipses. I endeavour to make dynamic EMF work so that
you can often use just one for modeling. But if your tooling generates
Java you need one for the producer and one for the consumer.
The U in URI is for Unique, If you have duplicates, all bets are off.
The namespace reservation of java.* for Java, org.eclipse.* for Eclipse
etc is to make duplicates easy to avoid.
Regards
Ed Willink
On 21/05/2013 20:01, Reinaldo Junior wrote:
> Ed Willink wrote on Tue, 21 May 2013 15:01
>> Hi
>>
>> You need to use the OCLinEcoreEObjectValidator , which you are
>> source-wise, but you also need to use it at run-time, so you must run
>> in a nested Eclipse.
>
>
> Thank you Ed,
>
> Does it mean I have to build my Xtext project from a nested Eclipse
> (started from running my Ecore project as an Eclipse application)? Why
> isn't enough to add the plugins which provides
> OCLinEcoreEObjectValidator as a dependency? Do you have any additional
> reference on that?
>
> Quote:
>> That fixed it still doesn't work. Changing the nsURI and rebuilding
>> fixes it.
>>
>> Using the same URI for your example as for the original tutorial is
>> very very foolish (and 'illegal'; org.eclipse... is reserved for
>> Eclipse Foundation usage).
>
>
> I would never imagine this could make any harm.
|
|
|
|
Re: Custom validation failure messages [message #1059898 is a reply to message #1059849] |
Wed, 22 May 2013 02:58  |
Eclipse User |
|
|
|
Hi
JRE version matching is a regular nightmare.
Java is generous in not requiring everyone to rebuild everything for
each new version, but there are limitation to its generosity. In
particular a 1.5 class may not invoke a 1.6 class. If you are running
Eclipse with a 1.7 JRE, this may show up when you invoke a standalone
application/nested Eclipse with a configured JRE.
Most Eclipse code is built with 1.5 class compatibility, so you are ok
if you set your compatibility to 1.5 too.
- in the Window Preferences = 1.5
- in genmodel >= 1.5 (important pre-Juno when default could be 1.4)
- in the Manifest JRE requirement (and update classpath after any change)
However some 1.6 features are hard to resist and so some plugins need 1.6.
1.5 is increasingly old and some non-Eclipse libraries such as Google
Guava have moved to 1.6. I'm seriously considering raising the lower
bound for at least the newer OCL code to 1.6 after Kepler.
Regards
Ed Willink
On 21/05/2013 23:24, Reinaldo Junior wrote:
> This is what I've tried:
>
> 1) Change the package name and URI for both the Ecore and Xtext projects.
> 2) Run the Ecore project as an "Eclipse Application" to start a nested
> eclipse (that is what I've understood from "using
> OCLinEcoreEObjectValidator at run-time")
> 3) From inside this first Eclipse-inception, create the Xtext project.
> 4) Imported my Ecore in the Xtext using the URI (and not the
> "platform:/resource/..." path) and 5) Change the JRE of every Xtext
> project (was J2SE-1.5) to the same JRE used on the Ecore projects
> (JavaSE-1.7)
> That is what I've understood from "[fixing] JRE consistency". Rebuild
> 6) Run the Xtext project as an "Eclipse Application" (second
> Eclipse-inception)
> 7) Created a new project to test my DSL.
>
> AND IT WORKED.
>
> I had tried all the steps except (5) and it didn't work. It's really
> tricky...
>
> One last question: is all this Eclipse-inception really required? I
> mean, It's not comfortable to have 3 eclipses running to be able to
> test something DSL.
>
> Thank you.
|
|
|
Powered by
FUDForum. Page generated in 0.26216 seconds