Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Validation problem
Validation problem [message #1420246] Tue, 09 September 2014 14:31 Go to next message
Eclipse UserFriend
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 14:43 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

make sure you import DomainmodelPackage.

if you do so it should work fine.

(asuming there was a DomainmodelPackage class generated)
Re: Validation problem [message #1421020 is a reply to message #1420255] Wed, 10 September 2014 16:58 Go to previous messageGo to next message
Eclipse UserFriend
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 17:04 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

DomainModelPackage should have a inner class Literals that should have a static member ELEMENTI__NAME
Re: Validation problem [message #1421028 is a reply to message #1421023] Wed, 10 September 2014 17:09 Go to previous message
Eclipse UserFriend
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);
Previous Topic:[2.6.3 to 2.7.1] Using eclipse application is broken
Next Topic:Annotation with Enum values
Goto Forum:
  


Current Time: Sat Jul 05 06:43:47 EDT 2025

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

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

Back to the top