Skip to main content



      Home
Home » Modeling » TMF (Xtext) » How to modify a model which is not opened in an editor ?
How to modify a model which is not opened in an editor ? [message #1732811] Fri, 20 May 2016 07:43 Go to next message
Eclipse UserFriend
Dear all,

I have an XtextResource, and I would like to modify the model it contains. As this resource is not opened in an editor, XtextDocumentUtil.get(iFile) (with iFile = ResourceUtil.getFile(new URIEditorInput(resourceUri));) returns null. Thus, I don't know how to get an IXtextDocument associated to my resource, on which I could call org.eclipse.xtext.util.concurrent.IWriteAccess.modify(IUnitOfWork<T, P>).

What is the right way to modify a model which is not opened in an editor ?

Thanks in advance !
Flo
Re: How to modify a model which is not opened in an editor ? [message #1732819 is a reply to message #1732811] Fri, 20 May 2016 08:46 Go to previous messageGo to next message
Eclipse UserFriend
is this in the context of a quickfix or independent from?
Re: How to modify a model which is not opened in an editor ? [message #1732937 is a reply to message #1732819] Mon, 23 May 2016 04:37 Go to previous messageGo to next message
Eclipse UserFriend
We have the problem in several contexts, including quickfixes but also commands that we apply to a whole project (for instance "organize imports in every files of the project").
Re: How to modify a model which is not opened in an editor ? [message #1732939 is a reply to message #1732937] Mon, 23 May 2016 04:49 Go to previous messageGo to next message
Eclipse UserFriend
for commands you can simply load everything into a resourceset created with IResourceSetProvider.

for the quickfix your could try to open another editor using IURIEditorOpener
Re: How to modify a model which is not opened in an editor ? [message #1732943 is a reply to message #1732939] Mon, 23 May 2016 05:28 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for your quick answer and the idea of using IURIEditorOpener for the quickfixes.

Concerning the commands, I succeed in getting the resources that I want to modify, and to apply IUnitOfWork.exec(XtextResource) to modify them. My problem is how to reserialize them: if I call org.eclipse.emf.ecore.resource.Resource.save(Map<?, ?>), the whole model is reserialized, whereas (to ensure the formatting stability of non-impacted parts of the model), I would like to reserialize only modified parts of the model, as it is done by org.eclipse.xtext.util.concurrent.IWriteAccess.modify(IUnitOfWork<Boolean, XtextResource>)
Re: How to modify a model which is not opened in an editor ? [message #1732945 is a reply to message #1732943] Mon, 23 May 2016 05:35 Go to previous messageGo to next message
Eclipse UserFriend
sry no idea on this
Re: How to modify a model which is not opened in an editor ? [message #1732950 is a reply to message #1732945] Mon, 23 May 2016 06:09 Go to previous messageGo to next message
Eclipse UserFriend
Have a look at ReconcilingUnitOfWork. It contains the code to re-serialize the changed parts only.
Re: How to modify a model which is not opened in an editor ? [message #1732952 is a reply to message #1732950] Mon, 23 May 2016 07:00 Go to previous message
Eclipse UserFriend
Sadly, ReconcilingUnitOfWork heavily relies on the underlying IXtextDocument (in particular it applies the computed text edits using a RewriteSessionEditProcessor which takes the document in parameter), and I don't know how to get an IXtextDocument associated to my resource without opening it in an editor (which is not possible for my commands modifying many files).
Previous Topic: xtext grammar ignore everything after a keyword
Next Topic:formatter fragment in project from an existing ecore model
Goto Forum:
  


Current Time: Wed Jul 16 17:41:05 EDT 2025

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

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

Back to the top