Validation problem [message #1420246] |
Tue, 09 September 2014 14:31  |
Eclipse User |
|
|
|
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 #1421028 is a reply to message #1421023] |
Wed, 10 September 2014 17:09  |
Eclipse User |
|
|
|
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);
|
|
|
Powered by
FUDForum. Page generated in 0.04053 seconds