Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to obtain the Eclipse automatically-updated EMF model?
How to obtain the Eclipse automatically-updated EMF model? [message #1005011] Thu, 24 January 2013 10:10 Go to next message
Marco Naddeo is currently offline Marco NaddeoFriend
Messages: 62
Registered: November 2012
Member
Hi all. Smile

If I understood well, Eclipse has a component called reconciler which is a background process in my DSL editor responsible for updating the model when the user takes a break from typing; the kinds of things it should update include elements displayed in the outline view, error markers, folding regions, etc.

So, the EMF model representing the source code that the programmer modifies in the editor is continuously updated by this process, so much so that typing in the editor and modifying for example a method signature, you can see the outline view updated in real time.

Now, I have 2 questions about this:

1) this process of "reconciliation" is done by default incrementally on regions of code that have been modified, or the parser is always triggered on the whole source, so that the EMF model is continuously replaced by new result of parsing?

2) how can I obtain this updated model to work on it? I know that, starting form an editor part, I'm able to obtain the model in this way:

IFile file = (IFile) editorPart.getEditorInput().getAdapter(IFile.class);
IProject project = file.getProject();
URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
ResourceSet rs = resourceSetProvider.get(project);
Resource r = rs.getResource(uri, true);
DSLModel model = (DSLModel) r.getContents().get(0);


but in this way I obtain the model updated to the last file saving Confused, and not to the actual content of the editor in this moment! My only idea was to parse from zero the source code in the editor to obtain an updated EMF model representation... but since this model is continuously updated from Eclipse, I want to know if there's a way to obtain it!

Thanks in advance,
Marco
Re: How to obtain the Eclipse automatically-updated EMF model? [message #1005043 is a reply to message #1005011] Thu, 24 January 2013 11:16 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Marco,

If you have the XtextEditor instance you can use this to get read access
to the resource containing your model

xtextEditor.getDocument().readOnly
(new IUnitOfWork.Void<XtextResource>()
{
@Override
public void process(XtextResource state) throws Exception
{
// Read state of model here...
}
});


On 24/01/2013 11:10 AM, Marco Naddeo wrote:
> Hi all. :)
>
> If I understood well, Eclipse has a component called reconciler which
> is a background process in my DSL editor responsible for updating the
> model when the user takes a break from typing; the kinds of things it
> should update include elements displayed in the outline view, error
> markers, folding regions, etc.
>
> So, the EMF model representing the source code that the programmer
> modifies in the editor is continuously updated by this process, so
> much so that typing in the editor and modifying for example a method
> signature, you can see the outline view updated in real time.
>
> Now, I have 2 questions about this:
>
> 1) this process of "reconciliation" is done by default incrementally
> on regions of code that have been modified, or the parser is always
> triggered on the whole source, so that the EMF model is continuously
> replaced by new result of parsing?
>
> 2) how can I obtain this updated model to work on it? I know that,
> starting form an editor part, I'm able to obtain the model in this way:
>
> IFile file = (IFile) editorPart.getEditorInput().getAdapter(IFile.class);
> IProject project = file.getProject();
> URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(),
> true);
> ResourceSet rs = resourceSetProvider.get(project);
> Resource r = rs.getResource(uri, true);
> DSLModel model = (DSLModel) r.getContents().get(0);
>
> but in this way I obtain the model updated to the last file saving :?,
> and not to the actual content of the editor in this moment! My only
> idea was to parse from zero the source code in the editor to obtain an
> updated EMF model representation... but since this model is
> continuously updated from Eclipse, I want to know if there's a way to
> obtain it!
>
> Thanks in advance,
> Marco


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to obtain the Eclipse automatically-updated EMF model? [message #1005332 is a reply to message #1005011] Thu, 24 January 2013 22:11 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
1) We do partial parsing on the smallest possible region and thus try to
replace the smallest possible subtree in the model. Note that the
efficiency of this approach depends a lot on how you design your
grammar. As a rule of thumb, it's more efficient if you keep the
parser's lookahead low.

2) You can get the model as Ed suggested, or register an
IXtextModelListener to the editor. In addition, we have our own dirty
state management. Explore the code around the classes
IExternalContentSupport and IDirtyStateManager if you want to learn more.

Am 24.01.13 11:10, schrieb Marco Naddeo:
> Hi all. :)
>
> If I understood well, Eclipse has a component called reconciler which is
> a background process in my DSL editor responsible for updating the model
> when the user takes a break from typing; the kinds of things it should
> update include elements displayed in the outline view, error markers,
> folding regions, etc.
>
> So, the EMF model representing the source code that the programmer
> modifies in the editor is continuously updated by this process, so much
> so that typing in the editor and modifying for example a method
> signature, you can see the outline view updated in real time.
>
> Now, I have 2 questions about this:
>
> 1) this process of "reconciliation" is done by default incrementally on
> regions of code that have been modified, or the parser is always
> triggered on the whole source, so that the EMF model is continuously
> replaced by new result of parsing?
>
> 2) how can I obtain this updated model to work on it? I know that,
> starting form an editor part, I'm able to obtain the model in this way:
>
> IFile file = (IFile) editorPart.getEditorInput().getAdapter(IFile.class);
> IProject project = file.getProject();
> URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(),
> true);
> ResourceSet rs = resourceSetProvider.get(project);
> Resource r = rs.getResource(uri, true);
> DSLModel model = (DSLModel) r.getContents().get(0);
>
> but in this way I obtain the model updated to the last file saving :?,
> and not to the actual content of the editor in this moment! My only idea
> was to parse from zero the source code in the editor to obtain an
> updated EMF model representation... but since this model is continuously
> updated from Eclipse, I want to know if there's a way to obtain it!
>
> Thanks in advance,
> Marco


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


---
Get professional support from the Xtext committers at www.typefox.io
Re: How to obtain the Eclipse automatically-updated EMF model? [message #1005469 is a reply to message #1005332] Fri, 25 January 2013 15:03 Go to previous messageGo to next message
Marco Naddeo is currently offline Marco NaddeoFriend
Messages: 62
Registered: November 2012
Member
Thanks, Ed and Jan! Smile

And is it possible to disable temporarily the automatic update of the EMF model in an editor (on user typing)?

I need to update on an action the source code, and its model, manually, and then restore the automatic management.


Marco
Re: How to obtain the Eclipse automatically-updated EMF model? [message #1005581 is a reply to message #1005469] Sat, 26 January 2013 18:45 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
That would be a bad idea, as many UI components rely on the semantic
model to be intact (outline, validation, etc.)

Am 25.01.13 16:03, schrieb Marco Naddeo:
> Thanks, Ed and Jan! :)
>
> And is it possible to disable temporarily the automatic update of the
> EMF model in an editor (on user typing)?
>
> I need to update on an action the source code, and its model, manually,
> and then restore the automatic management.
>
>
> Marco


--
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:Access to Resource URI within QuickfixProvider
Next Topic:include Xtext in Rcp app
Goto Forum:
  


Current Time: Tue Apr 23 17:13:26 GMT 2024

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

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

Back to the top