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 08:17 Go to next message
C is currently offline C
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 08:19 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
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 08:35 Go to previous messageGo to next message
C is currently offline C
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 16:25 Go to previous message
Sven Efftinge is currently offline Sven Efftinge
Messages: 1759
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


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Previous Topic:JET as part of Java
Next Topic:How to implement <jet.compile2> using customBuildCallbacks.xml
Goto Forum:
  


Current Time: Thu Jul 24 16:08:27 EDT 2014

Powered by FUDForum. Page generated in 0.03903 seconds