Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Xtext/DeveloperFAQ"

(New page: == [UI programming] How do I get access to the model and the parse tree?== In the editor the model and parse tree is loaded and managed by an implementation of IXtextDocument which extend...)
 
([UI programming] How do I get access to the model and the parse tree?)
Line 14: Line 14:
 
</code>
 
</code>
  
'''It is very important that you never ever hand out anything which references to an EObject contained in the passed resource!'''
+
'''It is very important that state from the passed resource is never ever returned!'''

Revision as of 05:22, 19 January 2009

[UI programming] How do I get access to the model and the parse tree?

In the editor the model and parse tree is loaded and managed by an implementation of IXtextDocument which extends IDocument. It is important, that you refer to the parsed information in transactions only. Therefore the IXtextDocument defines two methods: readOnly(UnitOfWork<T>) and readWrite(UnitOfWork<T>). Usually one only wants to read the parsed information in order to compute completion proposals, build outline view, etc. To do so you have to use the API like so:

 return document.readOnly(new UnitOfWork<ICompletionProposal[]>(){
   public ICompletionProposal[] exec(XtextResource resource) throws Exception {
     // compute proposals
     return proposals;
   }
 });

It is very important that state from the passed resource is never ever returned!

Back to the top