Skip to main content



      Home
Home » Modeling » TMF (Xtext) » [xtext] Retrieving root DSL EObject from the generated DSL editor
[xtext] Retrieving root DSL EObject from the generated DSL editor [message #33397] Tue, 24 March 2009 05:36 Go to next message
Eclipse UserFriend
Originally posted by: mayer.pst.ifi.lmu.de

Dear all,

I'd like to retrieve the "live" instance of the (parsed) EMF DSL model
programmatically, while I edit a file in the generated DSL editor. Can
someone point me to the relevant methods?

Somehow I was unable to find them in XTextEditor / XTextDocument.

Thanks,

Philip
Re: [xtext] Retrieving root DSL EObject from the generated DSL editor [message #33461 is a reply to message #33397] Tue, 24 March 2009 06:02 Go to previous messageGo to next message
Eclipse UserFriend
Hi Philip,

please see
IXtextDocument.readOnly(UnitOfWork<T>) and
IXtextDocument.modify(UnitOfWork<T>)

You'll get a XtextResource passed into your UnitOfWork.

Hope that helps,
Sebastian


Philip Mayer schrieb:
> Dear all,
>
> I'd like to retrieve the "live" instance of the (parsed) EMF DSL model
> programmatically, while I edit a file in the generated DSL editor. Can
> someone point me to the relevant methods?
>
> Somehow I was unable to find them in XTextEditor / XTextDocument.
>
> Thanks,
>
> Philip
Re: [xtext] Retrieving root DSL EObject from the generated DSL editor [message #33495 is a reply to message #33461] Tue, 24 March 2009 07:06 Go to previous messageGo to next message
Eclipse UserFriend
Dear Sebastian,

> please see
> IXtextDocument.readOnly(UnitOfWork<T>) and
> IXtextDocument.modify(UnitOfWork<T>)

Thank you, that was most helpful! :)

A related question would be how to retrieve the (non-live) EMF instance
for a File, String, Input Stream... containing source code written in my
dsl. The aim is to code something like:

EObject content= getModel(someStringWithDSLCode);

? :)

Thanks!

Philip
Re: [xtext] Retrieving root DSL EObject from the generated DSL editor [message #33529 is a reply to message #33495] Tue, 24 March 2009 09:16 Go to previous messageGo to next message
Eclipse UserFriend
Philip,

you should create a new XtextResource, add it to an XtextResourceFactory
and use something like this (pseudo code assumes you get an instance of
this class via injection):

class ModelLoader {
@Inject
Provider<XtextResourceSet> rsProvider;

@Inject
XtextResourceFactory factory;

EObject getModel(InputStream in) {
XtextResourceSet rs = rsProvider.get();
XtextResource r = factory.createResource(/* my dummy uri */);
r.load(in);
return r.getParseResult().getParseResult().getRootASTElement();
}
}

Maybe should have a look at AbstractXtextTests. It has a utility method
which does exactly what your are looking for.

Regards,
Sebastian


Philip Mayer schrieb:
>
> Dear Sebastian,
>
>> please see
>> IXtextDocument.readOnly(UnitOfWork<T>) and
>> IXtextDocument.modify(UnitOfWork<T>)
>
> Thank you, that was most helpful! :)
>
> A related question would be how to retrieve the (non-live) EMF instance
> for a File, String, Input Stream... containing source code written in my
> dsl. The aim is to code something like:
>
> EObject content= getModel(someStringWithDSLCode);
>
> ? :)
>
> Thanks!
>
> Philip
Re: [xtext] Retrieving root DSL EObject from the generated DSL editor [message #33665 is a reply to message #33529] Tue, 24 March 2009 12:43 Go to previous message
Eclipse UserFriend
Originally posted by: mayer.pst.ifi.lmu.de

Dear Sebastian,

I had a look at AbstractXtextTests and it was straightforward from there.

Thanks very much! :)

Philip

Sebastian Zarnekow wrote:
> Philip,
>
> you should create a new XtextResource, add it to an XtextResourceFactory
> and use something like this (pseudo code assumes you get an instance of
> this class via injection):
>
> class ModelLoader {
> @Inject
> Provider<XtextResourceSet> rsProvider;
>
> @Inject
> XtextResourceFactory factory;
>
> EObject getModel(InputStream in) {
> XtextResourceSet rs = rsProvider.get();
> XtextResource r = factory.createResource(/* my dummy uri */);
> r.load(in);
> return r.getParseResult().getParseResult().getRootASTElement();
> }
> }
>
> Maybe should have a look at AbstractXtextTests. It has a utility method
> which does exactly what your are looking for.
>
> Regards,
> Sebastian
>
>
> Philip Mayer schrieb:
>>
>> Dear Sebastian,
>>
>>> please see
>>> IXtextDocument.readOnly(UnitOfWork<T>) and
>>> IXtextDocument.modify(UnitOfWork<T>)
>>
>> Thank you, that was most helpful! :)
>>
>> A related question would be how to retrieve the (non-live) EMF
>> instance for a File, String, Input Stream... containing source code
>> written in my dsl. The aim is to code something like:
>>
>> EObject content= getModel(someStringWithDSLCode);
>>
>> ? :)
>>
>> Thanks!
>>
>> Philip
Previous Topic:How start to use xText
Next Topic:TMF and GMF
Goto Forum:
  


Current Time: Mon Jul 07 11:42:49 EDT 2025

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

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

Back to the top