Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XtextDocument Resource empty after getContents()
XtextDocument Resource empty after getContents() [message #1403573] Thu, 24 July 2014 13:10 Go to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hi,
I've implemented a serialization-mechanism for saving dsl-files via an eclipse action, on an XtextEditor.
It works fine for the first serialization-action, but when I edit the file and want to serialize it again the XtextResource is empty.

Here some code for a better understanding:

if (EditorUtils.getActiveXtextEditor() != null) {
IXtextDocument xtextDocument = EditorUtils.getActiveXtextEditor().getDocument();
XtextResource resource = xtextDocument.readOnly(new IUnitOfWork<XtextResource, XtextResource>() {

				public XtextResource exec(XtextResource state) throws Exception {
					return state;
				}
			});

EObject model = resource.getContents().get(0);
performSerialization(model);
}


Do I have to save the resource or the editor after accessing the elements of the XtextResource?

~Alex
Re: XtextDocument Resource empty after getContents() [message #1403579 is a reply to message #1403573] Thu, 24 July 2014 13:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
You should never give out any eobject from the readlony method.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XtextDocument Resource empty after getContents() [message #1403588 is a reply to message #1403579] Thu, 24 July 2014 14:03 Go to previous messageGo to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
So you mean I should run the serialization from within the exec operation?
I read this post and thought it was a good idea to access the semantic model in this way:

http://koehnlein.blogspot.de/2010/06/semantic-model-access-in-xtext.html

Is there any better way to get some access to the semantic model from within a XtextEditor? I mean, I could also
search the .dsl file and run the serialization on this resource direct.


Re: XtextDocument Resource empty after getContents() [message #1403637 is a reply to message #1403588] Thu, 24 July 2014 18:02 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi,

that exactly does "serialize" mean


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Xtext maven and Xcore model
Next Topic:Staged translation?
Goto Forum:
  


Current Time: Tue Apr 23 07:55:39 GMT 2024

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

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

Back to the top