Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext Validation Error Markers
Xtext Validation Error Markers [message #1726527] Mon, 14 March 2016 12:37 Go to next message
Ronan B is currently offline Ronan BFriend
Messages: 273
Registered: July 2009
Senior Member
Hi,
I'm having problems setting errors on a multivalued list of type String. When there is an error, because more than one description is defined, the editor shows error underlining on everything in the container., see picture attached. The error markers in the margin are correct.

Considering the following grammar snippet:
Container returns my::Container:
	'container'name=OptionallyQuotedName'{'
		( 
	        ( 'config' configList+=Boolean ';' )
		| ( 'status' statusList+=StatusKind ';' )
		| ( 'description' descriptionList+=(ConcatenatedString|QuotedConcatenatedString) ';' )
		| ( 'reference' referenceList+=(ConcatenatedString|QuotedConcatenatedString) ';' )
		)*
	'}'
;


The check code is as follows. Note I don't pass the source as the API requires an EObject but the type is a String which isn't compatible. I do however pass the index.

@Check
    public void checkContainer(Container c) {
        if(c.getDescriptionList().size() > 1)
        {
        	for(int i=1;i<=c.getDescriptionList().size();i++)
        	{
        		error(ERROR_DESCRIPTION_MSG,MYPackage.Literals.CONTAINER__DESCRIPTION_LIST,i);
        	}	
        }
}


Thanks!
Ronan
Re: Xtext Validation Error Markers [message #1726533 is a reply to message #1726527] Mon, 14 March 2016 13:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi,

what happens if you use

error(String message, EObject source, EStructuralFeature feature, int index)

then you should Keep in mind that index is Zero based. thus the <= is bad


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext Validation Error Markers [message #1726537 is a reply to message #1726533] Mon, 14 March 2016 14:06 Go to previous message
Ronan B is currently offline Ronan BFriend
Messages: 273
Registered: July 2009
Senior Member
Hi Christian,
Aha it was actually my incorrect usage of the max index that caused the error marking to show up wrong. I start the loop at 1 as the first element can never cause the error and then forgot it was actually 0 based. I made your suggested change and it works perfectly.

for(int i=1;i<c.getDescriptionList().size();i++)
{
      error(ERROR_DESCRIPTION_MSG,MYPackage.Literals.CONTAINER__DESCRIPTION_LIST,i);
}	


Thanks!
Ronan
Previous Topic:Cannot generate artifacts with Xtext 2.9.2 from DSL made with 2.5.4
Next Topic:Xtext web editor -- as Orion plugin?
Goto Forum:
  


Current Time: Thu Apr 25 09:44:55 GMT 2024

Powered by FUDForum. Page generated in 0.03212 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top