Home » Modeling » TMF (Xtext) » [Xtext] Custom Validation of (E)List Elements
[Xtext] Custom Validation of (E)List Elements [message #631194] |
Wed, 06 October 2010 14:24 |
|
Hi all,
I'm trying to add some custom validations to an Xtext generated editor
using a (generated) sub-subclass of AbstractDeclarativeValidator, e.g.,
MyJavaValidator. It is working, however I have a problem of assigning
warnings or errors to elements of an EList.
Example: Assume the following grammar snippet:
Call: "call" ... argtypes+=[TypeDecl] ("," argtypes+=[TypeDecl])* ...
That is, the language contains a call with references to type
declaration, such as "call ... type1, type2, type3"
Now I want to validate the "argtypes". So I have a method
@Check public void checkArgTypes(Call call) {
...
for (TypeDecl typeDecl: call.getArgtypes()) {
// .. do some validation ...
if (error) {
error("Error in ref to type " + typeDecl.getName() ,
MyPackage.CALL__ARG_TYPES);
}
}
The problem is: How can I identify the element (of the feature
CALL__ARG_TYPES) causing the error? I cannot pass an index or something
to the o.e.xtext.validation.AbstractDeclarativeValidator.error(..)
methods. Thus, as in the call above, in case of errors always the first
item is marked (underlined), even if another item causes the error. At
least I would expect to see all items marked.
I probably could add a workaround by not referencing the TypeDecl
directly, but using a reference element, such as
Call: "call" ... argtypes+=TypeRef ("," argtypes+=TypeRef)* ...
TypeRef: type=[TypeDecl];
However, I don't like the idea of bloating the grammar if it is not
really necessary.
Do you know of a solution w/o changing the grammar?
Cheers,
Jens
|
|
| | |
Re: [Xtext] Custom Validation of (E)List Elements [message #631245 is a reply to message #631194] |
Wed, 06 October 2010 16:20 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hi Jens,
you are facing this one which will be fixed in the 2.x stream:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=307721
Please note that it is usually not that bad to have a type reference
that wraps the actual cross reference in an own instance.
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 06.10.10 16:24, schrieb Jens v.P.:
> Hi all,
>
> I'm trying to add some custom validations to an Xtext generated editor
> using a (generated) sub-subclass of AbstractDeclarativeValidator, e.g.,
> MyJavaValidator. It is working, however I have a problem of assigning
> warnings or errors to elements of an EList.
>
> Example: Assume the following grammar snippet:
>
> Call: "call" ... argtypes+=[TypeDecl] ("," argtypes+=[TypeDecl])* ...
>
> That is, the language contains a call with references to type
> declaration, such as "call ... type1, type2, type3"
>
> Now I want to validate the "argtypes". So I have a method
>
> @Check public void checkArgTypes(Call call) {
> ...
> for (TypeDecl typeDecl: call.getArgtypes()) {
> // .. do some validation ...
> if (error) {
> error("Error in ref to type " + typeDecl.getName() ,
> MyPackage.CALL__ARG_TYPES);
> }
> }
>
> The problem is: How can I identify the element (of the feature
> CALL__ARG_TYPES) causing the error? I cannot pass an index or something
> to the o.e.xtext.validation.AbstractDeclarativeValidator.error(..)
> methods. Thus, as in the call above, in case of errors always the first
> item is marked (underlined), even if another item causes the error. At
> least I would expect to see all items marked.
>
> I probably could add a workaround by not referencing the TypeDecl
> directly, but using a reference element, such as
>
> Call: "call" ... argtypes+=TypeRef ("," argtypes+=TypeRef)* ...
> TypeRef: type=[TypeDecl];
>
> However, I don't like the idea of bloating the grammar if it is not
> really necessary.
>
> Do you know of a solution w/o changing the grammar?
>
> Cheers,
>
> Jens
|
|
| |
Goto Forum:
Current Time: Thu Apr 25 11:28:33 GMT 2024
Powered by FUDForum. Page generated in 0.03212 seconds
|