Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtend2, dispatch end inject extension
Xtend2, dispatch end inject extension [message #725420] Wed, 14 September 2011 13:31 Go to next message
Eclipse User
Originally posted by:

Hi,

I'm trying to get a combination of dispatch methods and injection of
extension methods to work.

I have a "main" xtend class named GenX that defines a dispatch method
foo(X, Y) and calls it with x.foo(y). X has n subclasses X1..Xn and for
each of these I have an xtend class GenXn that defines a dispatch method
foo(Xn, Y). Each of these are injected into GenX with
@Inject extension GenXn. However, the foo methods in the GenXn classes
do not seem to be noticed/used by GenX. The generated Java code only
includes the dispatch method in GenX, not the ones in GenXn. From
reading
http://www.eclipse.org/Xtext/documentation/2_0_0/02-Xtend_Classes_Functions.php#Functions
I got the impression that this should work.

Hallvard
Re: Xtend2, dispatch end inject extension [message #725425 is a reply to message #725420] Wed, 14 September 2011 14:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6205
Registered: July 2009
Senior Member
Hi,

I guess this Xpand Hack is not intended to work with Xtexts Xtend: all dispatch methods have to Be defined in the same file.

Regards Christian
Re: Xtend2, dispatch end inject extension [message #725429 is a reply to message #725425] Wed, 14 September 2011 14:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6205
Registered: July 2009
Senior Member
Hi, the docs actually say

For a set of visible dispatch functions in the current type hierarchy, the compiler infers a common signature using the common super type of all declared arguments and generates a Java method made up of if-else cascades.

So it can Be in supertypes of the Class too.
Re: Xtend2, dispatch end inject extension [message #725474 is a reply to message #725429] Wed, 14 September 2011 17:14 Go to previous messageGo to next message
Eclipse User
Originally posted by:

On 14.09.11 20.34, Christian Dietrich wrote:
>
> For a set of visible dispatch functions in the current type hierarchy,
> the compiler infers a common signature using the common super type of
> all declared arguments and generates a Java method made up of if-else
> cascades.
> So it can Be in supertypes of the Class too.

Yes, I read that. But the docs also says: "Generally function binding
works just like method binding in Java. That is function calls are bound
based on the static types of arguments. Sometimes this is not what you
want. Especially in the context of extension methods one would like to
have polymorphic behavior." This gives me the impression that extension
functions are also considered. Perhaps it refers to the case where you
want to extend several classes with the same method?

I can't see the reason for not allowing combining a dispatch method with
dispatch methods in an extension class.

Hallvard
Re: Xtend2, dispatch end inject extension [message #726327 is a reply to message #725474] Sat, 17 September 2011 06:34 Go to previous message
Sven Efftinge is currently offline Sven Efftinge
Messages: 1761
Registered: July 2009
Senior Member
Generally this sounds like a good idea.
Unfortunately dispatch methods are usually of protected visibility so
they wouldn't be visible from another class. Advocating a style where
those methods are always public and beeing put into the public API of a
type (might also be an interface) seems wrong.

If you still think this feature is worth being further discussed, please
file an enhancement request in the bugzilla.

Extension methods are polymorphic if you put all dispatch methods into
the type (hierarchy) of an extension field.

Sven


Am 9/14/11 11:14 PM, schrieb Hallvard Trætteberg:
> On 14.09.11 20.34, Christian Dietrich wrote:
>>
>> For a set of visible dispatch functions in the current type hierarchy,
>> the compiler infers a common signature using the common super type of
>> all declared arguments and generates a Java method made up of if-else
>> cascades.
>> So it can Be in supertypes of the Class too.
>
> Yes, I read that. But the docs also says: "Generally function binding
> works just like method binding in Java. That is function calls are bound
> based on the static types of arguments. Sometimes this is not what you
> want. Especially in the context of extension methods one would like to
> have polymorphic behavior." This gives me the impression that extension
> functions are also considered. Perhaps it refers to the case where you
> want to extend several classes with the same method?
>
> I can't see the reason for not allowing combining a dispatch method with
> dispatch methods in an extension class.
>
> Hallvard


--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Previous Topic:Strange warnings
Next Topic:How to export elements from existing languages
Goto Forum:
  


Current Time: Thu Aug 21 14:18:48 EDT 2014

Powered by FUDForum. Page generated in 0.02124 seconds