-
Notifications
You must be signed in to change notification settings - Fork 0
Examples
The console example is basically the same as the logger presented before, but with some wrapper code to work in the Eclipse console view instead of the standard output.
To start this example, execute the following steps:
- Open the Console view (available in the General category)
- Click on the Open console button in the view, and select 'Xtext-EVM Index Console'
- After the build has finished, the console will display the logged resource and event changes
A more complex example is used to update a JFace Viewer in case of the Xtext Index changed. This example uses two more aspects of EVM:
- An event filter is defined that filters notifications where the modified Object Description is not of a selected EClass (see line 40-41).
- To make sure the user interface is updated correctly in the user interface thread, the rules use
Display#syncExec
to switch threads (see line 58 and line 62).
To start this example, execute the following steps:
- Open the Display Inferred Classes view (available in the Xtext-EVM integration category).
- Have a project with xtend files in the workspace. The most simple way to achieve this is to generate the xtend-examples project using File/New/Example... and select the Xtend Introductory Examples option.
- After the build finishes, the Display Inferred Classes view should be filled with references to all known inferred java types.
The following screenshot describes how this view looks like:
It is important to note that the view contains very limited domain specific information: it only features information that is directly available in the Xtext index (qualified name, type and location); but it does not require opening the files themselves, thus provide quick updates.
The final, most complex example describes the globally visible state of a model, but relies on information not available in the Xtext Index. In general, the example works by loading all models that export an EObject with the type TClass (as defined in the Example Language included) into a ResourceSet; and then making sure these resources are updated when the underlying model changes.
It is important to note, that the ResourceSet of the example is not connected directly to any editor at all, but opens a second instance to display; however, after a model file is saved, the result is updated correctly.
There are two specific EVM rules implemented: an object rule that is responsible to ensure a model file exporting a TClass is loaded; and a resource rule to load/unload/reload the resources that were changed.
There are two new ideas presented in this example:
- The rules are ordered by priority: all object rules are evaluated before the resource rules are considered. This allows the object rules to to prepare all resources into the ResourceSet.
- IncQuery Viewers is used on the managed ResourceSet, that uses an EMF-based EVM instance to display the contents effectively.
The following screenshot shows this example in action:
To start this example, execute the following steps:
- Open the TClass Call Graph view (available in the Xtext-EVM integration category)
- Have a project with models of the example language (included in the repository)
- Notice that the call graph view updates after the builder has finished execution
- Home
- [Incremental View over Xtext Models - Overview](Incremental View over Xtext Models)
- Event driven Programming over the Xtext Index
- Getting Started
- Examples