Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » How to define Xtend method like: collection.retainAll(e|expression with e) ?(I want to define in Xtend a method that modify the content of a list according to a boolean expression.)
How to define Xtend method like: collection.retainAll(e|expression with e) ? [message #491384] Wed, 14 October 2009 12:17 Go to next message
C is currently offline CFriend
Messages: 3
Registered: October 2009
Junior Member
I want to define in Xtend a method that modify the content of a list according to a boolean expression applied to each element in the list.

Basically, I want to be able to define in Xtend a method that:
* takes a boolean expression as argument (like Collection.select)
* actually modify the provided collection (and returns Void)

I want to call this Xtend method from an Xpand template of this kind:

create Set[MyType] result getXYZ(MyOtherType this) :
result.retainAll(e|e.associationFromMyType == this);

And I don't know how to define such a parameter in Xtend:

Void retainAll(Collection this, ??? conditionArgument) :
let temp = this.select(conditionArgument) :
?set this to temp?;

Is this any possible?
Re: How to define Xtend method like: collection.retainAll(e|expression with e) ? [message #491388 is a reply to message #491384] Wed, 14 October 2009 12:19 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi C,

the higher order collection functions are hardcoded. It is currently not
possible to declare and implement something similar in your own extensions.

Sorry for inconvenience,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

C schrieb:
> I want to define in Xtend a method that modify the content of a list
> according to a boolean expression applied to each element in the list.
>
> Basically, I want to be able to define in Xtend a method that:
> * takes a boolean expression as argument (like Collection.select)
> * actually modify the provided collection (and returns Void)
>
> I want to call this Xtend method from an Xpand template of this kind:
>
> create Set[MyType] result getXYZ(MyOtherType this) :
> result.retainAll(e|e.associationFromMyType == this);
>
> And I don't know how to define such a parameter in Xtend:
>
> Void retainAll(Collection this, ??? conditionArgument) :
> let temp = this.select(conditionArgument) :
> ?set this to temp?;
>
> Is this any possible?
Re: How to define Xtend method like: collection.retainAll(e|expression with e) ? [message #491391 is a reply to message #491388] Wed, 14 October 2009 12:35 Go to previous messageGo to next message
C is currently offline CFriend
Messages: 3
Registered: October 2009
Junior Member
Hi Sebastian, thanks for fast answer.

Would it be possible then to subclass the java code that implements it?

What is the Java class that implements the high order collection functions?

Cheers,
Cédric
Re: How to define Xtend method like: collection.retainAll(e|expression with e) ? [message #491509 is a reply to message #491391] Wed, 14 October 2009 20:25 Go to previous message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
It's not possible to introduce new higher order functions, since
you'ld have to extend the parser.

Maybe

result.removeAll(result.select(e|e.associationFromMyType != this));

is sufficient?

Cheers,
Sven

C schrieb:
> Hi Sebastian, thanks for fast answer.
>
> Would it be possible then to subclass the java code that implements it?
>
> What is the Java class that implements the high order collection functions?
>
> Cheers,
> Cédric


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Previous Topic:JET as part of Java
Next Topic:How to implement <jet.compile2> using customBuildCallbacks.xml
Goto Forum:
  


Current Time: Thu Oct 10 04:58:50 GMT 2024

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

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

Back to the top