Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Issue saving Xtext resource from Eclipse plug-ins
Issue saving Xtext resource from Eclipse plug-ins [message #784734] Fri, 27 January 2012 23:16 Go to next message
Marcello Vitaletti is currently offline Marcello VitalettiFriend
Messages: 7
Registered: July 2009
Junior Member
I have created a DSL from an independent Ecore model + very little tweaking of the automatically generated grammar. I am using Xtext (2.2.1) and the generated DSL editor works nicely within INDIGO 3.7.1.

I have also written code for load/save of model instances. This piece also works perfectly when run as a standalone Java application. However, when I call the save function from within an Eclipse plug-in I get some strange behavior: the first time I save the EMF model instance as an Xtext resource everything is fine. After that, every successive invocation of save() still produces the desired result (the EMF model instance is correctly serialized on the output file) but each time the running Eclipse gets the following error:

!ENTRY org.eclipse.xtext.builder.impl.XtextBuilder 4 40000 2012-01-27 23:51:24.695
!MESSAGE Passed org.eclipse.xtext.resource.IResourceDescriptions not of type org.eclipse.xtext.resource.impl.ResourceSetBasedResourceDescriptions
!STACK 0
java.lang.IllegalStateException: Passed org.eclipse.xtext.resource.IResourceDescriptions not of type org.eclipse.xtext.resource.impl.ResourceSetBasedResourceDescriptions


I saw a recent posting with the above error message but not quite the same context. Perhaps is it wrong from within Eclipse to use the generated standalone-setup as follows?
private static Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
...
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
Resource resource = resourceSet.createResource(URI.createFileURI(dslFile.getAbsolutePath()));
resource.getContents().add(<root-object-of-EMF-model-instance>);
try {
	resource.save(null);
} catch (IOException e) {}



But why then I only see the error on the 2nd time? Of course I can share a minimalistic set of plug-in projects for reproducing the problem if that is needed.

Thanks a lot,

Marcello
Re: Issue saving Xtext resource from Eclipse plug-ins [message #784942 is a reply to message #784734] Sat, 28 January 2012 07:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
Hi,

It is a bad bad bad idea to call a StandaloneSetup from eclipse (hey it is called STANDALONE).
it will destroy your registries in eclipse.

and it is a bead idea to "steal" the <root-object-of-EMF-model-instance>
from your editor (if you do so i cannot see this from the little snippet you posted)

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sat, 28 January 2012 07:37]

Report message to a moderator

Re: Issue saving Xtext resource from Eclipse plug-ins [message #784965 is a reply to message #784942] Sat, 28 January 2012 08:01 Go to previous messageGo to next message
Marcello Vitaletti is currently offline Marcello VitalettiFriend
Messages: 7
Registered: July 2009
Junior Member
Thanks Christian.
In fact I am not "stealing" the root object from the editor: I am actually processing the import from a different format (or DSL if you wish) (using an Eclipse File Import Wizard). I am parsing the original input file in real time with custom code and building an instance of the same EMF ecore model which was used in defining my DSL. At that stage of the import process I need to save the in-memory model instance as a file in the workspace, using the Xtext resource "machinery" for having it serialized in my own DSL syntax. As I said, this works perfectly in several stand-alone tests...
And in Eclipse, the DSL editor has no problems opening DSL files created in this way.

From your input the remaining key question seems to be: "What is the proper way to initialize an Xtext resource set for an Xtext DSL within Eclipse"? I found several posts more or less related to this question but no definite example that I could build into working code...

Thanks a lot, I really appreciate your help!


Re: Issue saving Xtext resource from Eclipse plug-ins [message #784968 is a reply to message #784965] Sat, 28 January 2012 08:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
Hi,

e.g. using a Guice Injected Provider for a ResourceSet

@Inject
Provider<XtextResourceSet> rsp;


...

XtextResourceSet rs = rsp.get();


of course you need a guice injected chain from your plugin.xml (where you use yourdslexecutableextensionfactory e.g. to create your handler or whatever)
since i have no idea from/how you are exactly calling your code it is hard to say what you exactly have to do.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Issue saving Xtext resource from Eclipse plug-ins [message #785195 is a reply to message #784968] Sat, 28 January 2012 16:39 Go to previous message
Marcello Vitaletti is currently offline Marcello VitalettiFriend
Messages: 7
Registered: July 2009
Junior Member
Christian,

what I am doing (ser/deser of Xtext model instances) should be a common use case for Xtext users and one which I hoped could be implemented by a standard piece of code at any point of an Eclipse application...

From your (precious) hints I see that I need to study more stuff (guice) that I had hoped to keep aside. I am sure I will need more help along the way. If so, for the sake of clarity I will open a more specific topic (Initializing EMF/Xtext resource sets from within Eclipse to load/save AST model instances)

Thanks again for your suggestions. Marcello
Previous Topic:Need brutal review / tips
Next Topic:Abstract Syntax Tree from Xtext (first post, please be gentle)
Goto Forum:
  


Current Time: Fri Apr 26 19:30:47 GMT 2024

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

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

Back to the top