Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Custom error message for unordered groups
Custom error message for unordered groups [message #1006306] Wed, 30 January 2013 18:35 Go to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
Hi,

since the normal error message for incomplete unordered groups is not really helpful for the user, I would like to change it to a more meaningful.
SyntaxErrorMessageProvider is the way to go, I know so far, but there are hardly any examples or existing documentation which helped me so far.
Has anyone already succesfully changed this kind of error msg?
Re: Custom error message for unordered groups [message #1006316 is a reply to message #1006306] Wed, 30 January 2013 19:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
Hi,

if your are in such a situation the use of the the debugger is always a good starting point.
this will show:
- org.eclipse.xtext.parser.antlr.AbstractInternalAntlrParser.UnorderedGroupErrorContext.getDefaultMessage() is called
- this calls getRecognitionException and getRecognitionException
- the first one delivers a FailedPredicateException which contains the message info for the exception
- but there is other stuff to call too. e.g. getMissingMandatoryElements

The rest is up to you Wink

~Christian
Re: Custom error message for unordered groups [message #1006331 is a reply to message #1006316] Wed, 30 January 2013 21:17 Go to previous messageGo to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
Big thanks! I was able to change the error msg now.
Here is the code, for all which are interested:

class EfvmSyntaxErrorMessageProvider extends SyntaxErrorMessageProvider {

	public static String INCOMPLETE_UNORDERED_GROUP = "INCOMPLETE_UNORDERED_GROUP";

	@Override
	public SyntaxErrorMessage getSyntaxErrorMessage(IParserErrorContext context) {
		if (context.getRecognitionException() instanceof FailedPredicateException) {
			return new SyntaxErrorMessage(
					"The following elements are necassary for an adapter inctance: Name, Tool and Model",
					INCOMPLETE_UNORDERED_GROUP);
		}
		return super.getSyntaxErrorMessage(context);
	}
}


You talked about getMissingMandatoryElements ect. - in which case and how could I use this?

Cheers
Re: Custom error message for unordered groups [message #1006335 is a reply to message #1006331] Wed, 30 January 2013 21:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
What about if you have 10 unordered groups, or you want to say what exactly is missing

[Updated on: Wed, 30 January 2013 21:29]

Report message to a moderator

Re: Custom error message for unordered groups [message #1006343 is a reply to message #1006335] Wed, 30 January 2013 22:29 Go to previous messageGo to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
You're right, but how should I access this methods from IParserErrorContext? UnorderedGroupErrorContext is a subclass of ParserErrorContext. Or am I wrong?
Re: Custom error message for unordered groups [message #1006345 is a reply to message #1006343] Wed, 30 January 2013 22:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
UnorderedGroupErrorContext extends ParserErrorContext implements IUnorderedGroupErrorContext
Re: Custom error message for unordered groups [message #1006348 is a reply to message #1006345] Wed, 30 January 2013 23:09 Go to previous messageGo to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
Sry, I don't get it, how to access UnorderedGroupErrorContext from IParserErrorContext..It's a little bit confusing for me right now..
You mean something like: if (context.getRecognitionException() instanceof IUnorderedGroupErrorContext) ??
Re: Custom error message for unordered groups [message #1006350 is a reply to message #1006348] Wed, 30 January 2013 23:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
yes downcast to IUnorderedGroupErrorContext
Re: Custom error message for unordered groups [message #1006440 is a reply to message #1006350] Thu, 31 January 2013 11:11 Go to previous messageGo to next message
Phil H is currently offline Phil H
Messages: 267
Registered: November 2012
Senior Member
OK, I've got my AbstractElements now, but I don't now how to make the type check. This doesn't work:
if( abstractelment instanceof ConfigurationName){
dosomething...
}


Where ConfigurationName is a mandatory element of the unordered group.
Re: Custom error message for unordered groups [message #1006445 is a reply to message #1006440] Thu, 31 January 2013 11:22 Go to previous message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6377
Registered: July 2009
Senior Member
Hi I cannot say what to do (doing your work) so use the debugger and
see what you get

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Previous Topic:IIncompatible implicit return type on short or byte with numeric constants
Next Topic:Run xtext workflow from another plugin project
Goto Forum:
  


Current Time: Mon Oct 20 11:38:33 GMT 2014

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

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