Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Validation problem
Validation problem [message #1420246] Tue, 09 September 2014 18:31 Go to next message
Daniele P. is currently offline Daniele P.Friend
Messages: 18
Registered: August 2014
Junior Member
Hi,

i'm studying the validation of a grammar. I would like to do something of simple for understanding the concept.
For example i have this simple grammar:

Model:
elements+=Elementi*
;

Elementi:
	Function | Variabili
;

Function:
	type=JvmTypeReference name = ID
    '('(params+=FullJvmFormalParameter (',' params+=FullJvmFormalParameter)*)? ')'   
    body=XBlockExpression
;	

Variabili:
	type = JvmTypeReference name = ID ';'	
;


I would like to check if exist a particulary method, for example the 'main'.
I wrote this code for the scope, but i don't know how to refer to the function name.

@Check(CheckType.NORMAL)
	def void checkIfMainExist(Model function) {
		var found = false
		 
		for(elem : function.elements){
				switch(elem)
				{
					Function:{
						if(elem.name == "main")
						{
							found = true;												
						}						
					}			
				}
		}
		if(!found)
		{
			warning('Method Main is not defined', DomainmodelPackage$Literals::ELEMENTI__NAME);			
		}
	}


The code have an exception on the warning because domainmodelPackage$Literals::ELEMENTI__NAME" is not correct.
Following some tutorial, i've checked in other grammar the correctness for example supertype or the occurrence of the same name.
Please, could you help me to understand the error and the basic of validation process?
Thanks you
Re: Validation problem [message #1420255 is a reply to message #1420246] Tue, 09 September 2014 18:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

make sure you import DomainmodelPackage.

if you do so it should work fine.

(asuming there was a DomainmodelPackage class generated)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Validation problem [message #1421020 is a reply to message #1420255] Wed, 10 September 2014 20:58 Go to previous messageGo to next message
Daniele P. is currently offline Daniele P.Friend
Messages: 18
Registered: August 2014
Junior Member
DomainmodelPackage has been generated and imported.
In the editor if i don't write "main" like a function, i have this error "Error executing EValidator".
In DomainMode Package (that it's autogenerated) i found "ELEMENTI__NAME" like int (=1)
The check during the writing of a simple programm with this grammar is corrected only if I use a function with main otherwise i have the error above instead of "Method Main is not defined".
Could you help me?
Thanks in advance
Re: Validation problem [message #1421023 is a reply to message #1421020] Wed, 10 September 2014 21:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

DomainModelPackage should have a inner class Literals that should have a static member ELEMENTI__NAME


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Validation problem [message #1421028 is a reply to message #1421023] Wed, 10 September 2014 21:09 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

with warning('Method Main is not defined', DomainmodelPackage$Literals::ELEMENTI__NAME);
you call the warning method for the type the check method is definded

you should pass the element explcitely or pass a feature of Model and not one of Elementi

warning('Method Main is not defined', elem, DomainmodelPackage$Literals::ELEMENTI__NAME);


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:[2.6.3 to 2.7.1] Using eclipse application is broken
Next Topic:Annotation with Enum values
Goto Forum:
  


Current Time: Thu Mar 28 10:18:51 GMT 2024

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

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

Back to the top