How to iterate in a collection using Xtend? [message #911044] |
Mon, 10 September 2012 17:49  |
Eclipse User |
|
|
|
Hi,
I have this model:
Examples:
'Examples:'
table=Table
;
Table hidden(WS, SL_COMMENT):
{Table}
(rows+=TableRow (NEWLINE rows+=TableRow)*)
NEWLINE?
;
TableRow:
{TableRow}
('|' (cells += TableCell ('|' cells += TableCell)*) '|')
;
TableCell:
name = Content
;
and this text:
Examples:
|h1|h2|h3|
|cell11|cell12|cell13|
|cell21|cell22|cell23|
I need to to assert that each cell has the corrected value.
Could someone point me how to do this with Xtend?
I tried the docs and know that exists IterableExtensions but couldn't find any example how to use it properly.
thanks in advance.
Cristiano
|
|
|
|
Re: How to iterate in a collection using Xtend? [message #911083 is a reply to message #911065] |
Mon, 10 September 2012 20:03   |
Eclipse User |
|
|
|
Hi Sebastian,
Thanks for the tip.
I've found an interesting example here.
And I'm trying this but can find a way to increment the counter.
val values = "h1,h2,h3&cell11,cell12,cell13&cell21,cell22,cell23".split("&")
if (!tableRows.nullOrEmpty) {
val i = 0
for(row: tableRows)
{
val rowCellValues = row.cells.map[name.toString].join(",")
assertEquals(values.get(i), rowCellValues)
i=i+1
}
}
There is a error being indicated in the "i=i+1" sentence.
can't I create local variable with xtend? how should I do that ?
thanks,
Cristiano
|
|
|
Re: How to iterate in a collection using Xtend? [message #911224 is a reply to message #911083] |
Tue, 11 September 2012 03:54   |
Eclipse User |
|
|
|
Cristiano,
The val keyword indicated final locals where you would use 'var' for
variable.
Please refer to the docs for details.
Best regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 11.09.12 02:03, schrieb Cristiano Gaviao:
> Hi Sebastian,
>
> Thanks for the tip. I've found an interesting example
> http://www.slideshare.net/meysholdt/testdriven-development-of-xtext-dsls.
>
> And I'm trying this but can find a way to increment the counter.
> val values =
> "h1,h2,h3&cell11,cell12,cell13&cell21,cell22,cell23".split("&")
> if (!tableRows.nullOrEmpty) {
> val i = 0
> for(row: tableRows)
> {
> val rowCellValues = row.cells.map[name.toString].join(",")
> assertEquals(values.get(i), rowCellValues)
> i=i+1
> }
> }
>
> There is a error being indicated in the "i=i+1" sentence.
>
> can't I create local variable with xtend? how should I do that ?
>
> thanks,
>
> Cristiano
|
|
|
|
Powered by
FUDForum. Page generated in 0.24013 seconds