Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Xtend Validation(Validate number of instances)
Xtend Validation [message #1401422] Tue, 15 July 2014 15:39 Go to next message
Andrea Hern is currently offline Andrea HernFriend
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 118 times)
Re: Xtend Validation [message #1401506 is a reply to message #1401422] Tue, 15 July 2014 18:18 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30366
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
>
Previous Topic:[CDO] getOldValue call on notification return null if auditing is disabled
Next Topic:[CDO] Security manager failing with 'mem' store ?
Goto Forum:
  


Current Time: Thu Aug 22 22:22:02 GMT 2019

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

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

Back to the top