Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [xtend2] filter() and class selection(Using filter() to select instances of a class)
[xtend2] filter() and class selection [message #758681] Thu, 24 November 2011 08:33 Go to next message
Klaus Birken is currently offline Klaus BirkenFriend
Messages: 4
Registered: November 2011
Junior Member
Hi,

I started using Xtend2 for transformation and generation recently, it is a great and elegant language!

However, I guess I didn't understand all language concepts so far. The following question arises: In order to select all elements from a list which are instances of a certain class I am using this code:

var List<MyBaseClass> all = ...
all.filter(m | m instanceof SomeClass).map(m | m as SomeClass)


The filter selects the elements, but returns a Iterable<MyBaseClass>. The map() casts this to Iterable<SomeClass>, which is what I want to have.

---

I guess there might be a shorter way to do this... reading the online doc I think
all.filter(SomeClass)
should work. But it doesn't ("Couldn't resolve reference to JvmIdentifiableElement 'SomeClass'.").

What do I get wrong here?

Thanks in advance, regards,
Klaus

[Updated on: Thu, 24 November 2011 08:35]

Report message to a moderator

Re: [xtend2] filter() and class selection [message #758682 is a reply to message #758681] Thu, 24 November 2011 08:38 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
all.filter(typeof(SomeClass))


Re: [xtend2] filter() and class selection [message #758683 is a reply to message #758681] Thu, 24 November 2011 08:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13416
Registered: July 2009
Senior Member
all.filter(typeof(SomeClass))

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [xtend2] filter() and class selection [message #758685 is a reply to message #758683] Thu, 24 November 2011 09:04 Go to previous messageGo to next message
Klaus Birken is currently offline Klaus BirkenFriend
Messages: 4
Registered: November 2011
Junior Member
Thanks to both of you, it works. Actually, I found it in the xtend reference, at least now Smile
Re: [xtend2] filter() and class selection [message #758686 is a reply to message #758685] Thu, 24 November 2011 09:16 Go to previous message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Good, you're actually reading the reference and it took you less than 5 hours! Smile (This is actually about another thread Wink)

Previous Topic:ClassNotFoundException: org.eclipse.xtext.ui.refactoring.ui.RenameElementHandler
Next Topic:[Xbase] extending scope for XVariableDeclaration
Goto Forum:
  


Current Time: Wed Apr 01 22:24:26 GMT 2020

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

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

Back to the top