Xtend Validation [message #1401422] |
Tue, 15 July 2014 15:39 |
Andrea Hern Messages: 1 Registered: July 2014 |
Junior Member |
|
|
Hello, i'm a beginner in EMF, and i'm doing an exercise with xtend.
I'm modeling a game, attached you will find the model.
We have the grammar rules (xtext). e.g.
Game:
b=Board d=Die fields+=Field* players+=Player* pieces+=Piece*
;
Board:
'board' name=ID '{'
'field' ':' field+=[Field] (',' field+=[Field])* ';'
'die' ':' die=[Die]';'
'player' ':' player+=[Player] (',' player+=[Player])+ ';'
'}'
;
Field :
Runway | Home | Yard
;
Runway:
'runway' name=ID '{'
'number' ':' number=INT ';'
'next' ':' next=[Field] ';'
'isOccupied' ':' isOccupied=[Piece] ';'
'nextHome' ':' (nextHome=[Home] | 'null') ';'
'}'
| Entry
Entry:
'entry' name=ID '{'
'color' ':' c=COLOR ';'
'number' ':' number=INT ';'
'next' ':' next=[Field]? ';'
'isOccupied' ':' isOccupied=[Piece]? ';'
'}'
;
etc...
I need to validate the model using Xtend.
How can i validate that my board has exactly 4 entries?
I alredy have this code, only for validate the name (must be uppercase), but i don't know how to work with the entities, since they are part of a field.
@Check
def void checkBoard(Board myboard){
if (!Character.isUpperCase(myboard.name.charAt(0))) {
warning("Name should start with a capital",
DomainmodelPackage.Literals.BOARD__NAME);
}
}
Should i validate it in the same method (checkBoard)? or in a new one?
I hope someone can help me!!!
Thank you
-
Attachment: model.png
(Size: 76.04KB, Downloaded 161 times)
|
|
|
Re: Xtend Validation [message #1401506 is a reply to message #1401422] |
Tue, 15 July 2014 18:18 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Andrea,
You'll want to ask on the eclipse.modeling.tmf forum to ask about Xtend.
On 15/07/2014 8:07 PM, Andrea Hern wrote:
> Hello, i'm a beginner in EMF, and i'm doing an exercise with xtend.
>
> I'm modeling a game, attached you will find the model.
>
> We have the grammar rules (xtext). e.g.
>
> Game:
> b=Board d=Die fields+=Field* players+=Player* pieces+=Piece*
> ;
>
> Board:
> 'board' name=ID '{'
> 'field' ':' field+=[Field] (',' field+=[Field])* ';'
> 'die' ':' die=[Die]';'
> 'player' ':' player+=[Player] (',' player+=[Player])+ ';'
> '}'
> ;
> Field :
> Runway | Home | Yard
> ;
> Runway:
> 'runway' name=ID '{'
> 'number' ':' number=INT ';'
> 'next' ':' next=[Field] ';'
> 'isOccupied' ':' isOccupied=[Piece] ';'
> 'nextHome' ':' (nextHome=[Home] | 'null') ';'
> '}'
> | Entry
>
> Entry:
> 'entry' name=ID '{'
> 'color' ':' c=COLOR ';'
> 'number' ':' number=INT ';'
> 'next' ':' next=[Field]? ';'
> 'isOccupied' ':' isOccupied=[Piece]? ';'
> '}'
> ;
>
> etc...
>
> I need to validate the model using Xtend.
>
> How can i validate that my board has exactly 4 entries?
>
> I alredy have this code, only for validate the name (must be uppercase), but i don't know how to work with the entities, since they are part of a field.
>
> @Check
> def void checkBoard(Board myboard){
>
> if (!Character.isUpperCase(myboard.name.charAt(0))) {
> warning("Name should start with a capital",
> DomainmodelPackage.Literals.BOARD__NAME);
> }
> }
>
> Should i validate it in the same method (checkBoard)? or in a new one?
>
> I hope someone can help me!!!
>
> Thank you
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03421 seconds