Xtext Reflective Editor updated for Kepler

Today a new Eclipse version codenamed Kepler was released, with a lot of nice new features, including conflict handling during update, an update user interface for the Marketplace client or various EGit updates (my favorite is the Commit and Push button in the Commit dialog).

About the less visible stuff, in the modeling projects we use, e.g. EMF, Graphiti or Xtext also got some internal updates, resulting in the need to update our projects. As of now, I updated the Xtext Reflective Editor, as a change in EMF 2.9 made it unusable in Kepler.

I often use this tool to debug the Xtext-based parsers that use Xbase and model inferrers, as it displays the generated model using the EMF reflective editors. Version 0.5.5 is a recommended minor update – it works on both newer EMF/Xtext versions, but maintains compatibility with older EMF versions. It is still downloadable from our update site http://eclipse.cubussapiens.hu.

Thanks for all contributors the new, nice features of Kepler (and of course fixes as well). This can become a new platform for new projects for me – the reflective editor update is only the first of them.

Author: Zoltán Ujhelyi

I am an Eclipse Technology Expert at IncQuery Labs Ltd. and a regular contributor of open-source projects, most importantly the VIATRA project at eclipse.org. Furthermore, I am in the process of finishing my PhD in computer science at the Budapest University of Technology and Economics focusing on analysis techniques for model queries and transformations.

20 thoughts on “Xtext Reflective Editor updated for Kepler”

  1. Hi Hi, I have created a xtext grammar from an existing ecore model. I am able to instantiate my grammar and write the model dsl for the gramar. The problem comes when I do the following “Open With -> Sample Reflective Ecore Model”. So I downloaded your plug-ins with the hope that it would work. Unfortunately, I am still not able to get the ecore model. The error that I am getting is as follows :

    org.eclipse.emf.ecore.xmi.XMIException: org.xml.sax.SAXParseExceptionpublicId: platform:/resource/mnc.test/src/mnc.mncspec; systemId: platform:/resource/mnc.test/src/mnc.mncspec; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog. (platform:/resource/mnc.test/src/mnc.mncspec, 1, 1)
    at org.eclipse.emf.ecore.xmi.impl.XMLHandler.toXMIException(XMLHandler.java:682)
    at org.eclipse.emf.ecore.xmi.impl.XMLHandler.fatalError(XMLHandler.java:705)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source)
    at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:175)
    at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:253)
    at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518)
    at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1297)
    at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
    at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
    at org.eclipse.xtext.resource.XtextResourceSet.getResource(XtextResourceSet.java:201)
    at org.eclipse.xtext.resource.SynchronizedXtextResourceSet.getResource(SynchronizedXtextResourceSet.java:24)
    at hu.cubussapiens.xtext.reflectiveeditor.editor.ReflectiveXtextEditor.createModelGen(ReflectiveXtextEditor.java:91)
    at org.eclipse.emf.ecore.presentation.EcoreEditor.createModel(EcoreEditor.java:1257)
    at hu.cubussapiens.xtext.reflectiveeditor.editor.ReflectiveXtextEditor.createModel(ReflectiveXtextEditor.java:67)
    at org.eclipse.emf.ecore.presentation.EcoreEditor.createPages(EcoreEditor.java:1326)
    at org.eclipse.ui.part.MultiPageEditorPart.createPartControl(MultiPageEditorPart.java:358)
    at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(CompatibilityPart.java:142)
    at org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor.createPartControl(CompatibilityEditor.java:96)
    at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:323)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
    at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:877)
    at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:857)
    at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:119)
    at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:333)
    at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:254)
    at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
    at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(Reflect.

    So this is the error stack. Thanks in Advance..

  2. @Zoltan, Thanks for your immediate response. Well, I am trying to create an example and open an issue.

  3. Hi there, I am able to fix the problem above. It was a mistake, maybe on my own part. It was beacuse, the file extension variable in my Workflowgenerator was something else and the editor of my xtext grammar was something different. So the XtextResourceSet.getResource() function threw the above exceptions. After changing the file-extension in workflow, it is working smoothly.
    Thanks.. 🙂

  4. Hi,

    thanks for reporting back. I was looking into your issue, but at first everything seemed fine. Setting the file extension correctly is indeed needed. I will close then your ticket as well.

    Thanks again for contacting me and good luck.

  5. Hi Zoltan

    Thanks for your responses. But, I would like to address another issue that I am currently facing which is not in correspondence with this post. So, I would really like some help on that problem, if you are interested. If you are fine, I would post it here itself, otherwise mail, provided you share your mail ID. 🙂

    Note :- It is regarding synchronization between the reflective editor and xtext model.


  6. Hi,

    I think, the best forum to ask questions related to the editor is the comments of this blog. As the project has only a few users, I have not bothered to set up any forum/mailing list, etc.

    So just shoot your question, and I try my best to answer it.


  7. Hi,
    Ok. That’s great. So,What I am trying is to build is multiple partial editors on top of my Xtext grammar. Now for example, when I open the reflective ecore editor I want to be able to make change in the emf-based ecore editor and reflect it back to the xtext editor. I also plan to integrate GMF at certain point of time, to give users a graphical view of my textual model. But there are serious issues to attend to here like synchronization, partial view of my model, integration of frameworks to name a few.
    It will be great if you can suggest some ways to solve the first issue, which is changes in reflective editor are reflected in the xtext editor.
    Hope you understand my problem. 🙂


  8. Hi,

    you have a knack for hard questions. 😀 I understand the issue, but even the Xtext developers do not recommend to rely on the internal changes of the text editor to maintain a concurrent graphical editor.

    This is caused by a very different editing model between textual editors and tree or graphical editors: when you edit your text in the textual editor, the text needs to be re-parsed, and the EMF model replaced – this means a lot of unplanned changes in model. In case of tree- and graphical editors support the direct changing of the model (e.g. updating a label feature, adding a single new element, etc.), resulting in clear notifications.

    When relying on the changes of the textual model directly, the tree/graphical editors need to replace a lot of things in parallel. In case of the graphical editors this also results in relayouting the diagram, that is also problematic.

    The recommended way to integrate Xtext editors with different kinds of editors is relying on the file level, as described in the Eclipse Help for GMF (http://help.eclipse.org/luna/topic/org.eclipse.xtext.doc/contents/210-emf-integration.html?cp=70_1_8_3#gmf_integration).

    I hope, this was helpful.


  9. Hi.

    Hmm. Thought so, its difficult. But hopefully, the developers think of some way of getting them to sync in future. Anyways, thanks for the clarification.
    So this brings me to my next query 😛 Which is how to make changes in the xtext editor itself depending upon certain condition. For example, when we instantiate a feature in the xtext editor, I want another instance of a particular model class getting created automatically or by a custom handler. Actually I want to implement an EOpposite reference of EMF, which is not possible in XTEXT. 😉 I have other queries too, if you are interested 🙂


  10. Ok, I have been through this link. But here it says about generating an EMF model from Xtext, which I am not doing at all. I don’t think the technique would work in my case. 🙁 My EMF metamodel is independent and it already contains the EOpposite reference but when I am creating the model in Xtext the EOpposite reference does not get instantiated automatically as it would have in default EMF model editor. I know Xtext does not provide any mechanism for my problem, so I was thinking if I could manually instantiate the required EOpposite reference based on a particular condition or rather by a context menu(Right+click) and reflect it back on the editor. I hope you understand what I am trying to say. 🙂 Do you think it’s feasible?


  11. Well, I am also planning to add a feature like selective view on the Xtext Editor. So when I am creating the model in Xtext it will be like a huge document. So if I wanted to view a particular section of the document or say “only the statemachine of the whole System , where System contains a lot of other attributes, features and references” , how would I be able to achieve that? I guess Eclipse itself would provide some APIs for the editor but I don’t know of any yet. Any suggestions will be helpful. 😉


  12. About EOpposites, I don’t really know why does it not work. As far as I can recall, it should work out-of-the-box, without any necessary gluecode for already existing metamodels. Sadly, I don’t think a simple command in the pop-up menu will work, as it would try to serialize the references on save that would cause all kinds of issues.

    About creating views your editor, it is also a complex idea – especially if you want to have any kind of editing functionality. Based on the SelectionService you can get a handle of your model, or by relying on the current editor you can reuse the XtextDocument as well (the latter should work better in case of Xtext), but basically you have to do some complex infrastructure tasks.

    Sorry about being so generic, but I hope I have given you hints where to look.


  13. Hmm. Thanks. Actually, I think my requirements are a little abstract. I am also in a fix how to fix these issues. And if I am able to put all these together my next task would be too simulate my xtext file. For example, the debugger mode operation for java language. So based upon some logic I would need to run my xtext model file just as we do any other language, after all, what we are creating is a Domain-Specific Language which should run like any other languages. Basically I would like to show the flow of control(Step-in and Step-out type of Debug functions) in my xtext file. Do you have any ideas about achieving it? Thanks in advance, and I would really be sorry if I am getting you irritated with such questions. You let me know.!! 🙂


  14. Hi Zoltan
    I was using your plug-in for the reflective ecore. But I found that there is a missing functionality in your plug-in. As I was seeing through various Xtext videos on Vimeo, I came across the use of editor, “Sample reflective ecore editor” which allows to modify the EMF model synchronously, as I had previously wanted. But its not happening with your plug-in. And the option Open With -> Sample reflective ecore editor is giving me the following error.

    org.eclipse.emf.ecore.xmi.XMIException: org.xml.sax.SAXParseExceptionpublicId: platform:/resource/mnc.test/src/mnc.mncspec; systemId: platform:/resource/mnc.test/src/mnc.mncspec; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog. (platform:/resource/mnc.test/src/mnc.mncspec, 1, 1)

  15. Moreover, I just had a very weird experience. When I use your plug-in to open and close the ecore editor, if after that I use the option of Open With -> Sample reflective ecore editor, I am getting the desired editor, with synchronous changes. :O How is that possible.? Do you have any idea?


  16. Hi Puneet,

    I don’t really know why does the synchronized editing work in case of the normal reflective editor, and why does not in my editor. It might have something to do with some changes in the editor I was not following. It is worth a look.

    On the other hand, I have a theory why has the reflective editor begin to work after my editor ran: in order to load everything as expected, I had to do some registration steps that the normal ecore editor does not do. After these registrations are done, the normal reflective editor might be able to open the model. However, I am not sure whether there are limitations (e.g. does it matter if you open an xtext file from another project between the closing and opening of the editor).

    I have opened https://github.com/ujhelyiz/xtext-reflective/issues/4 in order not to forget what is possible. Sorry, but I don’t know whether I will have time to check this in a short time or not.


  17. Hi

    You are right with the theory of registrations, but how will I detect which part of code is affecting these registrations and what exactly are these registrations. Because this is happening every time. After I open your view the default editors also start working perfectly. 🙁


  18. Hi,

    my editor basically uses a specific ResourceSet, and makes sure that the language plug-in itself is loaded by reusing its dependency injection configuration module.

    Sadly, the entire thing is a bit more complex than this comment box allows describing. Maybe this is an idea for a future blog post. 🙂


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.