Implicit type conversion for Xbase [message #1421002] |
Wed, 10 September 2014 20:20 |
Cioran Naroic Messages: 18 Registered: December 2013 |
Junior Member |
|
|
Hi everyone,
I'm trying to implement a little tricky extension for Xbase. Given the following code:
val a = new A // a.toC() yields a C
val b = new B // b.toC() yields a C
// Doesn't work: Type mismatch
function_that_accepts_C_as_argument(a) // passing a.toC() would work, but I want it to be implicit
// Doesn't work: Type mismatch
function_that_accepts_C_as_argument(b) // passing b.toC() would work, but I want it to be implicit
A and B aren't subtypes of C, so I can't call the function_that_accept_... directly. However, I know that they contains the toC() method that yields a C, so everything will be ok if the compiler adds the toC() automatically.
More generally, I would like to be able to tell something like "I know this looks weird, but let me try" to the Xbase typesystem/validator, and override the compiler to add the ".toC()" in the generated Java code.
Even more generally, I would like to be able to detect any kind of type mismatch in Xbase code and explore the context to see if I got the appropriate toX() method.
Do you have some ideas on where and how I should override the Xbase typesystem / validator / compiler to implement this? Just pointing the relevant classes in the API would help me a lot.
Thanks a lot,
Cioran
[Updated on: Wed, 10 September 2014 20:25] Report message to a moderator
|
|
|
Re: Implicit type conversion for Xbase [message #1421067 is a reply to message #1421002] |
Wed, 10 September 2014 22:31 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hey Cioran,
you may want to override
org.eclipse.xtext.xbase.typesystem.computation.SynonymTypesProvider and
provide custom conversions there. You don't get the expected type but
the original type which can be explored to find all toX methods.
In the compiler, look for internalToConvertedExpression(..) where you
get the expected type and the actual type. There you can insert the #toX
calls into the generated code.
Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 10.09.14 22:20, schrieb Cioran Naroic:
> Hi everyone,
>
> I'm trying to implement a little tricky extension for Xbase. Given the
> following code:
>
>
> val a = new A // a.toC() yields a C
> val b = new B // b.toC() yields a C
>
> // Doesn't work
> function_that_accepts_C_as_argument(a) // passing a.toC() would work,
> but I want it to be implicit
>
> // Doesn't work
> function_that_accepts_C_as_argument(b) // passing b.toC() would work,
> but I want it to be implicit
>
>
> A and B aren't subtypes of C, so I can't call the
> function_that_accept_... directly. However, I know that they contains
> the toC() method that yields a C, so everything will be ok if the
> compiler adds the toC() automatically.
>
> More generally, I would like to be able to tell something like "I know
> this looks weird, but let me try" to the Xbase typesystem/validator, and
> override the compiler to add the ".toC()" in the generated Java code.
>
> Even more generally, I would like to be able to detect any kind of type
> mismatch in Xbase code and explore the context to see if I got the
> appropriate toX() method.
>
> Do you have some ideas on where and how I should override the Xbase
> typesystem / validator / compiler to implement this?
>
> Thanks a lot,
>
> Cioran
>
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03531 seconds