Skip to main content



      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 03:33 Go to next message
Eclipse UserFriend
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 03:35] by Moderator

Re: [xtend2] filter() and class selection [message #758682 is a reply to message #758681] Thu, 24 November 2011 03:38 Go to previous messageGo to next message
Eclipse UserFriend
all.filter(typeof(SomeClass))
Re: [xtend2] filter() and class selection [message #758683 is a reply to message #758681] Thu, 24 November 2011 03:38 Go to previous messageGo to next message
Eclipse UserFriend
all.filter(typeof(SomeClass))
Re: [xtend2] filter() and class selection [message #758685 is a reply to message #758683] Thu, 24 November 2011 04:04 Go to previous messageGo to next message
Eclipse UserFriend
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 04:16 Go to previous message
Eclipse UserFriend
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: Sun Jul 27 09:58:32 EDT 2025

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

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

Back to the top