[xtext] Retrieving root DSL EObject from the generated DSL editor [message #33397] |
Tue, 24 March 2009 05:36  |
Eclipse User |
|
|
|
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 #33665 is a reply to message #33529] |
Tue, 24 March 2009 12:43  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.05124 seconds