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

Xtext/DeveloperFAQ

< Xtext
Revision as of 05:22, 19 January 2009 by Sven.efftinge.itemis.de (Talk | contribs) ([UI programming] How do I get access to the model and the parse tree?)

[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