Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Showing validation error at the right eStructural feature
Showing validation error at the right eStructural feature [message #1202968] Fri, 22 November 2013 07:10 Go to next message
Ashwini Nayak is currently offline Ashwini Nayak
Messages: 19
Registered: July 2013
Junior Member
Hello,

I am facing a problem while showing a validation error in my xText editor.

My xcore model looks like this:

class Application
{
String name
contains User[] users
}

class User
{
String name
String address
}


My xText grammar looks as below:

Application:
"system" name=ID
users+=User*
;

User:
"userName" userName=ID "{"
"address" address=STRING
"}"
;



I have a java validation method which looks as below:

@Check
public void testApplication(Application app){
//other code
for(User user :app.getUsers()){
//validation goes here
error("Error!!!", user.eClass().getEStructuralFeature(UserPackage.USER_NAME));
}
}

I need to show a validation error at the EStructural Feature, 'userName' in my editor. I am not able to show validation error at the right place.
I throws runtime exception : "The sources EClass 'Application' does not expose the feature 'User.userName'". I can show error at the right place if I pass 'User' as the parameter for my validation method.
But, for some reason, I take 'Application' as the parameter for my validation method.

Can anyone help me by suggesting how I can resolve this?

Thanks in advance Smile

Re: Showing validation error at the right eStructural feature [message #1213323 is a reply to message #1202968] Wed, 27 November 2013 02:35 Go to previous message
Sven Efftinge is currently offline Sven Efftinge
Messages: 1759
Registered: July 2009
Senior Member
Use
error("Error!!", user, UserPackage.Literals.USER_NAME)


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Previous Topic:Generator problems when using cross references in xtext
Next Topic:Using cross references in xtext
Goto Forum:
  


Current Time: Tue Jul 22 07:36:11 EDT 2014

Powered by FUDForum. Page generated in 0.02203 seconds