Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Integrating Xbase with EMF and own language
Integrating Xbase with EMF and own language [message #689316] Mon, 27 June 2011 12:16 Go to next message
Eclipse UserFriend
Originally posted by:

Hi,

I'm currently using Javascript for expressions and statements in a DSL.
In the grammar I handle this by using {{ and }} as delimiters, but of
course it would be nicer to have native expression/statement syntax and
better editor support. AFAIU, Xbase provides this.

I have two questions:
1) Javascript support EMF directly by means of js4emf. Does Xbase
supports Ecore types i.e. EClassifers without the generated Java
counterpart (I must suppor dynamic eobjects). Can this be easily added?
2) I would like to add another type, similar to a function with multiple
input (argument) and output (return) values. Is it possible/easy to do this?

Hallvard
Re: Integrating Xbase with EMF and own language [message #690397 is a reply to message #689316] Wed, 29 June 2011 13:12 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Am 6/27/11 2:16 PM, schrieb Hallvard Trætteberg:
> Hi,
>
> I'm currently using Javascript for expressions and statements in a DSL.
> In the grammar I handle this by using {{ and }} as delimiters, but of
> course it would be nicer to have native expression/statement syntax and
> better editor support. AFAIU, Xbase provides this.
>
> I have two questions:
> 1) Javascript support EMF directly by means of js4emf. Does Xbase
> supports Ecore types i.e. EClassifers without the generated Java
> counterpart (I must suppor dynamic eobjects).

No dynamic EMF is not supported. Everything runs against Java types.

> Can this be easily added?

Not too easily but it's possible.
What you need to do is, to create an instance of the JVMTypes ecore
model which reflects the java signatures of your dynamic ecore model.
In addition to that you need to tell the interpreter how to execute
these features (i.e. how to get and set a property).

> 2) I would like to add another type, similar to a function with multiple
> input (argument) and output (return) values. Is it possible/easy to do
> this?

I don't get what you mean here. Why is the function type not working for
you?

Sven


--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Re: Integrating Xbase with EMF and own language [message #690418 is a reply to message #690397] Wed, 29 June 2011 13:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by:

On 29.06.11 15.12, Sven Efftinge wrote:
> Am 6/27/11 2:16 PM, schrieb Hallvard Trætteberg:
>> Hi,
>>
>> I'm currently using Javascript for expressions and statements in a DSL.
>> In the grammar I handle this by using {{ and }} as delimiters, but of
>> course it would be nicer to have native expression/statement syntax and
>> better editor support. AFAIU, Xbase provides this.
>>
>> I have two questions:
>> 1) Javascript support EMF directly by means of js4emf. Does Xbase
>> supports Ecore types i.e. EClassifers without the generated Java
>> counterpart (I must suppor dynamic eobjects).
>
> No dynamic EMF is not supported. Everything runs against Java types.
>
>> Can this be easily added?
>
> Not too easily but it's possible.
> What you need to do is, to create an instance of the JVMTypes ecore
> model which reflects the java signatures of your dynamic ecore model.

So XBase maintains instances of JVMTypes ecore model for the Java code
and libraries in the class path. And I need to create such an instance
with the signatures I would get if I had generated Java code? That
should be doable (at least if I assume the genmodel defaults).

> In addition to that you need to tell the interpreter how to execute
> these features (i.e. how to get and set a property).

And invoke eOperations, I guess.

>> 2) I would like to add another type, similar to a function with multiple
>> input (argument) and output (return) values. Is it possible/easy to do
>> this?
>
> I don't get what you mean here. Why is the function type not working for
> you?

My language includes objects that are similar to processes with typed
ports. I would like to utilize the existing type inference mechanism,
including support for (sub)type checking and generics. Imagine declaring
process (instance) variables like this:

process type <T> singleSelection(input List<T> iss, int index; output
List<T> oss);
process singleSelection<String> p1;

The signature of p1 will be process type(input List<String> iss, int
index; output List<String> oss), and references to p1.oss will be of
type List<String>). I'm (desperately) hoping XBase has most of the
necessary logic for this kind of reasoning, and that this logic can be
utilized by implementing some interface that makes processes look like
something XBase understands.

Hallvard
Re: Integrating Xbase with EMF and own language [message #690630 is a reply to message #690418] Wed, 29 June 2011 21:09 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Am 6/29/11 3:45 PM, schrieb Hallvard Trætteberg:
>>> I have two questions:
>>> 1) Javascript support EMF directly by means of js4emf. Does Xbase
>>> supports Ecore types i.e. EClassifers without the generated Java
>>> counterpart (I must suppor dynamic eobjects).
>>
>> No dynamic EMF is not supported. Everything runs against Java types.
>>
>>> Can this be easily added?
>>
>> Not too easily but it's possible.
>> What you need to do is, to create an instance of the JVMTypes ecore
>> model which reflects the java signatures of your dynamic ecore model.
>
> So XBase maintains instances of JVMTypes ecore model for the Java code
> and libraries in the class path. And I need to create such an instance
> with the signatures I would get if I had generated Java code? That
> should be doable (at least if I assume the genmodel defaults).

Xbae is referencing those elements and you have to put them into the
index somehow. Assuming th genmodel defaults is a good idea :-)

>
>> In addition to that you need to tell the interpreter how to execute
>> these features (i.e. how to get and set a property).
>
> And invoke eOperations, I guess.

Yes.

>
>>> 2) I would like to add another type, similar to a function with multiple
>>> input (argument) and output (return) values. Is it possible/easy to do
>>> this?
>>
>> I don't get what you mean here. Why is the function type not working for
>> you?
>
> My language includes objects that are similar to processes with typed
> ports. I would like to utilize the existing type inference mechanism,
> including support for (sub)type checking and generics. Imagine declaring
> process (instance) variables like this:
>
> process type <T> singleSelection(input List<T> iss, int index; output
> List<T> oss);
> process singleSelection<String> p1;
>
> The signature of p1 will be process type(input List<String> iss, int
> index; output List<String> oss), and references to p1.oss will be of
> type List<String>). I'm (desperately) hoping XBase has most of the
> necessary logic for this kind of reasoning, and that this logic can be
> utilized by implementing some interface that makes processes look like
> something XBase understands.

You only need to translate your type to a Java type similar as we do
with Functions in Xbase. So there are no real function types in Xbase
but they are just mapped to interfaces. You could do the same, so your
process could be translated to something like

class singleSelection<T> implements Functions.Function2<List<T>,
Integer, List<T>> {
List<T> apply(List<T> iss, Integer idex)
}

That again could just be an inmemory instance of the JVMTypes ecore
model, so you don't need to really generate that Java type.

Sven

--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Re: Integrating Xbase with EMF and own language [message #690807 is a reply to message #690630] Thu, 30 June 2011 08:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by:

On 29.06.11 23.09, Sven Efftinge wrote:
> Am 6/29/11 3:45 PM, schrieb Hallvard Trætteberg:
>>>> I have two questions:
>>>> 1) Javascript support EMF directly by means of js4emf. Does Xbase
>>>> supports Ecore types i.e. EClassifers without the generated Java
>>>> counterpart (I must suppor dynamic eobjects).
>>>
>>> No dynamic EMF is not supported. Everything runs against Java types.
>>>
>>>> Can this be easily added?
>>>
>>> Not too easily but it's possible.
>>> What you need to do is, to create an instance of the JVMTypes ecore
>>> model which reflects the java signatures of your dynamic ecore model.
>>
>> So XBase maintains instances of JVMTypes ecore model for the Java code
>> and libraries in the class path. And I need to create such an instance
>> with the signatures I would get if I had generated Java code? That
>> should be doable (at least if I assume the genmodel defaults).
>
> Xbase is referencing those elements and you have to put them into the
> index somehow. Assuming th genmodel defaults is a good idea :-)

So in general, if (part of) a model can be transformed to a JVMTypes
instance (instead of transforming to Java source), it can be referred to
in an XBase-based model.

But, you say the JVMTypes model must _somehow_ be put into the index. I
can think of two ways: 1) using API directly or 2) saving the JVMTypes
model to a resource in the classpath and then let a builder index it as
if this JVMTypes model was generated from Java source.

> You only need to translate your type to a Java type similar as we do
> with Functions in Xbase. So there are no real function types in Xbase
> but they are just mapped to interfaces. You could do the same, so your
> process could be translated to something like
>
> class singleSelection<T> implements Functions.Function2<List<T>,
> Integer, List<T>> {
> List<T> apply(List<T> iss, Integer idex)
> }
>
> That again could just be an inmemory instance of the JVMTypes ecore
> model, so you don't need to really generate that Java type.

So again, if an object in your model can be transformed to a JVMTypes
instance, it can be used by XBase, without the Java source counterpart.
In my case, a process type is translated to an EClass with the typed
ports as EStructuralFeatures, so if I use the technique described above
for translating an Ecore model to a JVMTypes model, it should work as
expected.

I guess an important concern in the transformation is what XBase syntax
it will enable. E.g. if you want to use <something>.name you must make
sure the type of <something> includes name as a field or property (pair
of get/set methods). And as you say, you must be prepared to implement
the corresponding semantics in the interpreter. BTW, any hints for this?

Hallvard
Re: Integrating Xbase with EMF and own language [message #690870 is a reply to message #690807] Thu, 30 June 2011 10:02 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Am 6/30/11 10:46 AM, schrieb Hallvard Trætteberg:
> On 29.06.11 23.09, Sven Efftinge wrote:
>> Am 6/29/11 3:45 PM, schrieb Hallvard Trætteberg:
>>>>> I have two questions:
>>>>> 1) Javascript support EMF directly by means of js4emf. Does Xbase
>>>>> supports Ecore types i.e. EClassifers without the generated Java
>>>>> counterpart (I must suppor dynamic eobjects).
>>>>
>>>> No dynamic EMF is not supported. Everything runs against Java types.
>>>>
>>>>> Can this be easily added?
>>>>
>>>> Not too easily but it's possible.
>>>> What you need to do is, to create an instance of the JVMTypes ecore
>>>> model which reflects the java signatures of your dynamic ecore model.
>>>
>>> So XBase maintains instances of JVMTypes ecore model for the Java code
>>> and libraries in the class path. And I need to create such an instance
>>> with the signatures I would get if I had generated Java code? That
>>> should be doable (at least if I assume the genmodel defaults).
>>
>> Xbase is referencing those elements and you have to put them into the
>> index somehow. Assuming th genmodel defaults is a good idea :-)
>
> So in general, if (part of) a model can be transformed to a JVMTypes
> instance (instead of transforming to Java source), it can be referred to
> in an XBase-based model.
>
> But, you say the JVMTypes model must _somehow_ be put into the index. I
> can think of two ways: 1) using API directly or 2) saving the JVMTypes
> model to a resource in the classpath and then let a builder index it as
> if this JVMTypes model was generated from Java source.

If your model is an Xtext model, you could compute the JVMType model on
load and add it into the resource's contents list in second position.
That way it is ignored by Xtext and effectively transient, but the
elements get indexed and have a stable URI.

>
>> You only need to translate your type to a Java type similar as we do
>> with Functions in Xbase. So there are no real function types in Xbase
>> but they are just mapped to interfaces. You could do the same, so your
>> process could be translated to something like
>>
>> class singleSelection<T> implements Functions.Function2<List<T>,
>> Integer, List<T>> {
>> List<T> apply(List<T> iss, Integer idex)
>> }
>>
>> That again could just be an inmemory instance of the JVMTypes ecore
>> model, so you don't need to really generate that Java type.
>
> So again, if an object in your model can be transformed to a JVMTypes
> instance, it can be used by XBase, without the Java source counterpart.
> In my case, a process type is translated to an EClass with the typed
> ports as EStructuralFeatures, so if I use the technique described above
> for translating an Ecore model to a JVMTypes model, it should work as
> expected.

Yes, at least you can refer to your elements. You'll still have to
explain hwo to execute the expressions.

>
> I guess an important concern in the transformation is what XBase syntax
> it will enable. E.g. if you want to use <something>.name you must make
> sure the type of <something> includes name as a field or property (pair
> of get/set methods). And as you say, you must be prepared to implement
> the corresponding semantics in the interpreter. BTW, any hints for this?

Subclass XbaseInterpreter and override the dispatch method for
XFeatureCall. Therein you'll have to find out whether the feature is the
sort of dynamic feature we are talking about and then use eGet / eSet /
eInvoke.

Sven

--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Re: Integrating Xbase with EMF and own language [message #690906 is a reply to message #690870] Thu, 30 June 2011 11:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by:

On 30.06.11 12.02, Sven Efftinge wrote:
> Am 6/30/11 10:46 AM, schrieb Hallvard Trætteberg:
>>
>> So in general, if (part of) a model can be transformed to a JVMTypes
>> instance (instead of transforming to Java source), it can be referred to
>> in an XBase-based model.
>>
>> But, you say the JVMTypes model must _somehow_ be put into the index. I
>> can think of two ways: 1) using API directly or 2) saving the JVMTypes
>> model to a resource in the classpath and then let a builder index it as
>> if this JVMTypes model was generated from Java source.
>
> If your model is an Xtext model, you could compute the JVMType model on
> load and add it into the resource's contents list in second position.
> That way it is ignored by Xtext and effectively transient, but the
> elements get indexed and have a stable URI.

I think the natural usage will be to import the EPackage URI and expect
to be able to refer to the types defined in it (the contained
EClassifiers). This will require loading the corresponding JVMTypes
before the linking phase, won't it? Will adding the JVMTypes model as a
resource in the same ResourceSet work as well?

>> So again, if an object in your model can be transformed to a JVMTypes
>> instance, it can be used by XBase, without the Java source counterpart.
>> In my case, a process type is translated to an EClass with the typed
>> ports as EStructuralFeatures, so if I use the technique described above
>> for translating an Ecore model to a JVMTypes model, it should work as
>> expected.
>
> Yes, at least you can refer to your elements. You'll still have to
> explain hwo to execute the expressions.

Currently, I translate the expressions to Javascript and use them as
bodies of EOperations of the generated EClasses, and use EMF's delegate
mechanism and js4emf to handle invocations. Perhaps it's possible to
refer to the Xtext resource containing the expressions in annotations on
the EOperations and invoke the XBaseInterpreter. EMF's delegate
mechanism is based on textual expressions, but the text could just as
well be URIs to XBase model elements. You haven't by any chance
implemented an XBase-based EMF delegate?

>> I guess an important concern in the transformation is what XBase syntax
>> it will enable. E.g. if you want to use<something>.name you must make
>> sure the type of<something> includes name as a field or property (pair
>> of get/set methods). And as you say, you must be prepared to implement
>> the corresponding semantics in the interpreter. BTW, any hints for this?
>
> Subclass XbaseInterpreter and override the dispatch method for
> XFeatureCall. Therein you'll have to find out whether the feature is the
> sort of dynamic feature we are talking about and then use eGet / eSet /
> eInvoke.

Thanks for all the explanations! I'll post any interesting findings.

Hallvard
Re: Integrating Xbase with EMF and own language [message #691995 is a reply to message #690906] Sun, 03 July 2011 04:16 Go to previous messageGo to next message
Erik Nijkamp is currently offline Erik NijkampFriend
Messages: 3
Registered: June 2011
Junior Member
Hi Hallvard,

I ran into the same issue. Plan is to map the existing model to virtual jvm-types and keep the references in a resource object.

Did this trick work for you? Would you share any code or further insights?

Thanks!

Cheers,
Erik
Re: Integrating Xbase with EMF and own language [message #692410 is a reply to message #691995] Mon, 04 July 2011 11:34 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
You might want to read the new section on Xtext and Java, especially on
inferring a JVM model in the docs.

http://www.eclipse.org/Xtext/documentation/2_0_0/199-xtext-and-java.php


Am 03.07.11 06:16, schrieb Erik Nijkamp:
> Hi Hallvard,
>
> I ran into the same issue. Plan is to map the existing model to virtual
> jvm-types and keep the references in a resource object.
>
> Did this trick work for you? Would you share any code or further insights?
>
> Thanks!
>
> Cheers,
> Erik


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


---
Get professional support from the Xtext committers at www.typefox.io
Previous Topic:Using some Xtext features in a SWT Widget
Next Topic:Using Xbase in own grammar
Goto Forum:
  


Current Time: Thu Sep 24 09:29:31 GMT 2020

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

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

Back to the top