Bug 461430 - Cannot mark all elements of a list as erroneous during validation
Summary: Cannot mark all elements of a list as erroneous during validation
Status: NEW
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.7.3   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-04 14:11 EST by Stephan Herrmann CLA
Modified: 2016-08-04 07:30 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Herrmann CLA 2015-03-04 14:11:18 EST
It seems that org.eclipse.xtext.validation.DiagnosticConverterImpl.getLocationData(Diagnostic) doesn't respect the specification of 'index' in org.eclipse.xtext.validation.ValidationMessageAcceptor.acceptError(String, EObject, EStructuralFeature, int, String, String...), where it says:

 * @param index the index of the erroneous value or <code>-1</code> if all values are considered to be invalid. The index is ignored if
 *   the feature is null or the feature is a single value feature.


I was trying to use a value of -1 to mark all elements in a list as erroneous (in my case: for a validation saying that the number of elements is wrong). The logic in getLocationData(), however, converts this -1 back into 0 and then just uses the first node in the list.

We already have the list of nodes in hands, so one only needs to extract the range from first to last, in order to get the desired IssueLocation.
Comment 1 Christian Dietrich CLA 2016-08-04 02:35:21 EDT
can be reproduced
Comment 2 Jan Koehnlein CLA 2016-08-04 04:40:04 EDT
I guess that's more a multiplicity problem here.

If your grammar is like

Foo: 
   bars+=Bar 'lots' 'of' 'other' 'Stuff' bars+=Bar;

it may not be acceptable to mark everything between the first and the last Bar as erroneous. Shouldn't we rather create a diagnostic for each element in the list?
Comment 3 Stephan Herrmann CLA 2016-08-04 07:30:21 EDT
(In reply to Jan Koehnlein from comment #2)
> I guess that's more a multiplicity problem here.
> 
> If your grammar is like
> 
> Foo: 
>    bars+=Bar 'lots' 'of' 'other' 'Stuff' bars+=Bar;
> 
> it may not be acceptable to mark everything between the first and the last
> Bar as erroneous. Shouldn't we rather create a diagnostic for each element
> in the list?

Technically you're correct, but I'd argue that your example is a corner case and in the majority of cases lists are contiguous and it would be much preferable to issue just one diagnostic from start to end. Just think of a dozen of bars on the same source line and how the hover on the error annotation in the rule would repeat the same information a dozen times.

When checking if a list is contiguous I actually wouldn't consider unassigned keywords as interruption to avoid that already a separator (',' or such) forces splitting. Only assignments should count IMHO.