Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 11:43 Go to next message
Flo Plateau is currently offline Flo PlateauFriend
Messages: 16
Registered: December 2013
Junior Member
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 12:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
is this in the context of a quickfix or independent from?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
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 08:37 Go to previous messageGo to next message
Flo Plateau is currently offline Flo PlateauFriend
Messages: 16
Registered: December 2013
Junior Member
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 08:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
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 09:28 Go to previous messageGo to next message
Flo Plateau is currently offline Flo PlateauFriend
Messages: 16
Registered: December 2013
Junior Member
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 09:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
sry no idea on this

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
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 10:09 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Have a look at ReconcilingUnitOfWork. It contains the code to re-serialize the changed parts only.

---
Get professional support from the Xtext committers at www.typefox.io
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 11:00 Go to previous message
Flo Plateau is currently offline Flo PlateauFriend
Messages: 16
Registered: December 2013
Junior Member
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: Thu Apr 18 07:29:07 GMT 2024

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

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

Back to the top