|Xtend2, dispatch end inject extension [message #725420]
||Wed, 14 September 2011 17:31
Originally posted by: |
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
I got the impression that this should work.
|Re: Xtend2, dispatch end inject extension [message #726327 is a reply to message #725474]
||Sat, 17 September 2011 10:34
| Sven Efftinge
Registered: July 2009
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.
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
>> 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.
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
Powered by FUDForum
. Page generated in 0.03491 seconds