Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Modify error message from IResourceValidator
Modify error message from IResourceValidator [message #1754033] Tue, 14 February 2017 03:09 Go to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
I am using cross-reference from xcore. If an entry does not have a valid reference, xcore will throw an error like this:
Couldn't resolve reference to Test 'trial'.


I don't want xcore to specify the grammar name 'Test' in the error message as the user does not really care about the grammar part. "Couldn't resolve reference to 'trial'" is enough for me.

How can I modify the error message that the validator is throwing?
Re: Modify error message from IResourceValidator [message #1754034 is a reply to message #1754033] Tue, 14 February 2017 04:05 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 10892
Registered: July 2009
Senior Member
The extension point is ILinkingDiagnosticMessageProvider

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Modify error message from IResourceValidator [message #1754044 is a reply to message #1754034] Tue, 14 February 2017 06:59 Go to previous messageGo to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
I created my own custom diagnostic message provider.
class CustomDiagnostic extends LinkingDiagnosticMessageProvider {
	override DiagnosticMessage getUnresolvedProxyMessage(ILinkingDiagnosticContext context) {
		val DiagnosticMessage diagnostic = super.getUnresolvedProxyMessage(context)
                String msg = "my custom msg"
		return new DiagnosticMessage(msg, diagnostic.getSeverity(),
			diagnostic.getIssueCode(), diagnostic.getIssueData())
	}
}


But when I bind it with my runtime module, I get the error saying "The method bindILinkingDiagnosticMessageProvider() must override a superclass method."

I added this in my runtime module:
	override Class<? extends ILinkingDiagnosticMessageProvider> bindILinkingDiagnosticMessageProvider() {
		return CustomDiagnostic 
	}

Re: Modify error message from IResourceValidator [message #1754048 is a reply to message #1754044] Tue, 14 February 2017 07:24 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 10892
Registered: July 2009
Senior Member
why not simply

def Class<? extends ILinkingDiagnosticMessageProvider> bindILinkingDiagnosticMessageProvider() {
return CustomDiagnostic
}


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Modify error message from IResourceValidator [message #1754058 is a reply to message #1754048] Tue, 14 February 2017 08:26 Go to previous message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
it works now! thanks! it did not work the first time i tried to use "def" but restarting eclipse seems to fix it.
Previous Topic:After Migtation from xtext 2.10 to xtext 2.11. Cannot open text editor for my DSL
Next Topic:How to fix warning on bidirectional reference
Goto Forum:
  


Current Time: Mon Jul 24 05:00:00 GMT 2017

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

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