Search code examples
javaeclipsextextemfecore

Listen to EObject changes in XText editor from another Eclipse view


I want to create an Eclipse view of the document that is in the current XtextEditor. To create the view I want to traverse the EObject's created by xtext from the document contents. I can get the current editor but I can't work out how to get the EObject's?

I assume that the EObject tree of the DSL is available as its what xtext uses internally and I'm also assuming that it's what is used to populate the eclipse outline view.

I thought that I would be able to get the XtextResource from the editor, but when I get the resource I just get a org.eclipse.core.internal.resources.File

Anyone know how to get a reference to the current ECore model that the editor is using?


Solution

  • you can use

    XtextEditor.getDocument().readOnly(IUnitOfWork)
    

    please note: you may not return the resource or contents in IUnitOfWork

    another possibility is to simly load the resource separately into a resourceset