Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Regarding Validations in Xtext(Validation)
Regarding Validations in Xtext [message #1783806] Sun, 18 March 2018 11:39 Go to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 49
Registered: October 2017
Member
Hi,

I am working on validation module. However, when I put the correct name I am able to see the "name" attribute in the console and when I type against the rule I get null in the "name" attribute. Since I get "null" value in the attribute name, I am not able to show the error message. Below is a small example of my grammar.

Grammar:
//Goal Main Model OR Starting Rule
DomainModel: Compilation_Unit;

//Compilation Unit
Compilation_Unit:{Compilation_Unit} (module+=Module_decl)*
;

//Module_Decl
Module_decl:'module' name=QUALIFIED_TYPE_IDENTIFIER ';'

where
QUALIFIED_TYPE_IDENTIFIER:
(TYPE_IDENTIFIER'.')* TYPE_IDENTIFIER

terminal TYPE_IDENTIFIER:
(CAPITALLETTER)(CAPITALLETTER|SMALLLETTER|'_'|DIGIT)*
;

//Code in Validation module
@Check
def void checkNameStartsWithCapital(Module_decl module) {
println("Testing.......................")
println(module)
if (!Character.isUpperCase(module.name.charAt(0))) {
error("Module Name should start with a capital",
AbsPackage.Literals.MODULE_DECL__NAME);
}
}

Output:

//When I type the module name in small letters
Testing.......................
org.xtext.abs.impl.Module_declImpl@5ce521bb (name: null)

//When I write the module name in uppercase
Testing.......................
org.xtext.abs.impl.Module_declImpl@4244bd26 (name: Mymodule)

Thanks in advance.
Re: Regarding Validations in Xtext [message #1783808 is a reply to message #1783806] Sun, 18 March 2018 11:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
you can simply pass null as feature to mark the whole rule

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding Validations in Xtext [message #1783811 is a reply to message #1783808] Sun, 18 March 2018 12:08 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 49
Registered: October 2017
Member
Thanks but I have also for the time being done that just that I want not sure whether this would be correct.I was wondering why I am not getting the name attribute because It works fine for the default Greeting example.
Re: Regarding Validations in Xtext [message #1783812 is a reply to message #1783811] Sun, 18 March 2018 12:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
You can mark only things that are there.
If you don't have a name you can't underline it


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding Validations in Xtext [message #1783813 is a reply to message #1783812] Sun, 18 March 2018 12:19 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 49
Registered: October 2017
Member
Case1:
//When I type the module name in small letters in runtime
module smallmodule;

then I get
org.xtext.abs.impl.Module_declImpl@5ce521bb (name: null)

However, when I go as per the rule which states that the module name should be an upper case , I am able to get the name
Case 2:
module Smallmodule;

then I get
org.xtext.abs.impl.Module_declImpl@5ce521bb (name: Smallmodule)

The name is there in the module rule (i.e smallmodule in Case1 ) but since the name is against the rule(i.e. Name should start with a capital letter) I am getting null there. As, per my understing I should receive 'smallmodule' in the name attribute.
Re: Regarding Validations in Xtext [message #1783814 is a reply to message #1783813] Sun, 18 March 2018 13:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
This is cause you do the upper case thing in grammar and not in validation
So you will get a parade error and thus bill as name


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding Validations in Xtext [message #1783816 is a reply to message #1783814] Sun, 18 March 2018 14:39 Go to previous message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 49
Registered: October 2017
Member
Oh..okay .. I got it. Thank you so much once again... will get back to you soon ;-). Enjoy and thanks again.:)
Previous Topic:XBlockExpression is only variable or assignment?
Next Topic:Installing xtext
Goto Forum:
  


Current Time: Sun Sep 23 07:01:28 GMT 2018

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

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

Back to the top