Skip to main content


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 17:31 Go to next message
Eclipse UserFriend
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 18:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtend2, dispatch end inject extension [message #725429 is a reply to message #725425] Wed, 14 September 2011 18:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
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.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtend2, dispatch end inject extension [message #725474 is a reply to message #725429] Wed, 14 September 2011 21:14 Go to previous messageGo to next message
Eclipse UserFriend
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 10:34 Go to previous message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
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
Previous Topic:Strange warnings
Next Topic:How to export elements from existing languages
Goto Forum:
  


Current Time: Thu Mar 28 09:46:55 GMT 2024

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

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

Back to the top