Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Type Inference with XBase
Type Inference with XBase [message #769512] Thu, 22 December 2011 08:12 Go to next message
peter  is currently offline peter Friend
Messages: 5
Registered: December 2011
Junior Member
Hy,
In my Xbase dsl I need to define some operations with no return type explicitly declared. I also need to use the inferer to map my concepts with Java.
I'm wondering which would be the best practice to determine an implicit XExpession return type so that it could be infered with Java.
I'm currently experimenting this on the domainmodel. On it's dsl I removed the "operation" rule return type:

Operation:
'op' name=ValidID '(' (params+=FullJvmFormalParameter (',' params+=FullJvmFormalParameter)*)? ')' '=' //initially there was ':' type=JvmTypeReference
body=XExpression; //initially there was body = XBlockEx..


The new operation return type should normally be the XExpression return type.
On DomainmodelJvmModelIferrer I injected an ITypeProvider and I changed the Operation code like this:

Operation : {
members += f.toMethod(f.name, f.body.type) [ //I request here the XExpression return type
documentation = f.documentation
for (p : f.params) {
parameters += p.toParameter("p", p.parameterType)
}
body = f.body
]
}

The problem is that f.body.type always returns "null" and consequently the infered return type of java operation is always void.

A model exemple, just in case:

package dmodel{

entity Person{
name: String
age: Integer


op getName0() = age //Integer

op getAge0() = age //String

op getAge1() = getAge0() //This should normally be a String
}

What should I consider in order to make this working?
This is quite similar with Xbase/Xtend type inference and i'm sure that it could be done somehow.
Thanks!




Re: Type Inference with XBase [message #769577 is a reply to message #769512] Thu, 22 December 2011 11:05 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
You should not resolve any cross references during JVM model inferrence.
To make this work in Xtend, we have implemented a special type proxy.

org.eclipse.xtext.xtend2.jvmmodel.Xtend2JvmModelInferrer.getTypeProxy(EObject)

Should give you an entry. I have a feeling this needs more documentation...


Am 22.12.11 09:12, schrieb peter:
> Hy,
> In my Xbase dsl I need to define some operations with no return type
> explicitly declared. I also need to use the inferer to map my concepts
> with Java.
> I'm wondering which would be the best practice to determine an implicit
> XExpession return type so that it could be infered with Java.
> I'm currently experimenting this on the domainmodel. On it's dsl I
> removed the "operation" rule return type:
>
> Operation:
> 'op' name=ValidID '(' (params+=FullJvmFormalParameter (','
> params+=FullJvmFormalParameter)*)? ')' '=' //initially there was ':'
> type=JvmTypeReference
> body=XExpression; //initially there was body = XBlockEx..
>
>
> The new operation return type should normally be the XExpression return
> type.
> On DomainmodelJvmModelIferrer I injected an ITypeProvider and I changed
> the Operation code like this:
>
> Operation : {
> members += f.toMethod(f.name, f.body.type) [ //I request here the
> XExpression return type
> documentation = f.documentation
> for (p : f.params) {
> parameters += p.toParameter("p", p.parameterType)
> }
> body = f.body
> ]
> }
>
> The problem is that f.body.type always returns "null" and consequently
> the infered return type of java operation is always void.
> A model exemple, just in case:
>
> package dmodel{
>
> entity Person{
> name: String
> age: Integer
>
>
> op getName0() = age //Integer
>
> op getAge0() = age //String
>
> op getAge1() = getAge0() //This should normally be a String
> }
>
> What should I consider in order to make this working?
> This is quite similar with Xbase/Xtend type inference and i'm sure that
> it could be done somehow. Thanks!
>
>
>
>
>


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: Type Inference with XBase [message #769584 is a reply to message #769577] Thu, 22 December 2011 11:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hello Jan,

this wont work neither cause org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.cloneWithProxies(JvmTypeReference)
doesnt like proxies so one might have to do some extra stuff.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Type Inference with XBase [message #769604 is a reply to message #769584] Thu, 22 December 2011 12:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Just gave it a deeper try and it actually works

(using a own DomainModelResource, a customized JvmTypesBuilder and some extra work to the Inferrer)

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Type Inference with XBase [message #769694 is a reply to message #769604] Thu, 22 December 2011 14:42 Go to previous message
peter  is currently offline peter Friend
Messages: 5
Registered: December 2011
Junior Member
Thanks a lot, i'll try to do some work around your advices.
Previous Topic:IContainer.Manager returns weird things i've never imported???
Next Topic:Combining importURI and importedNamespace
Goto Forum:
  


Current Time: Fri Apr 26 04:11:38 GMT 2024

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

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

Back to the top