Reflective tree editor for Xtext-based languages

Xtext is a great technology. I really mean it. After 15-30 minutes (depending on your previous domain knowledge) you can get a really fancy textual editor, that parses your text into an EMF model. Xbase is even better: you can simply include Java-like expressions into your language, that can be easily translated into pure Java code.

However, while using Xtext I found some minor “paper-cuts”. One of the most problematic of them was the fact that I cannot open my textual models using the Sample Reflective Ecore  Model editor, as I get an exception: java.net.MalformedURLException: unknown protocol: java.

A similar exception occurred if I tried to open the files programatically (but without the help of the generated Xtext editor). When I asked in the Eclipse forums how to open Xtext model files programatically, I was answered (btw. very quickly – kudos for that 🙂 ) that a specific ResourceSet implementation is needed that refers to model files and classes available in a Java project.

This gave me the idea to create an Xtext extension that allows opening an EMF tree editor, the Xtext Reflective Tree Editor. The plug-in consists of two parts:

  1. An extended version of the org.eclipse.emf.ecore.presentation.EcoreEditor class, that opens its ResourceSet using the Xtext API (more specifically, uses an injected ResourceSet);
  2. And an Xtext generator fragment, that can be used to generate a new editor extension to the ui project (with the corresponding dependency added to the reflective editor plug-in).

Usage

To use the plug-in, just follow the following simple steps:

  1. Add hu.cubussapiens.xtext.reflectiveeditor as a dependency to your language project.
  2. Extend your editor generation workflow:
    1. Import the generator package: import hu.cubussapiens.xtext.reflectiveeditor.generator.*
    2. Add the new generator fragment at the end of the generator (file.extensions is the list of file extensions defined in the default workflow):
      fragment = ReflectiveXtextEditorFragment {
      fileExtensions = file.extensions
      }
    3. Regenerate your language.
  3. Unless the plugin.xml files are updated automatically, you have to copy the newly generated editor extension from the end of the plugin.xml_gen file of the ui plug-in to the plugin.xml file. The simplest way to do this is to select both files, and open the compare editor from the popup menu (Compare with/Each other…), the copy the changes manually.
  4. Finally, open the runtime workbench, and open your textual model files from the popup menu using Open with/«LanguageName» Reflective Editor. The result should be similar to the screenshot below.
The Xtext Reflective Editor

In my case, the editor shows both the domain model generated from the file directly (the Pattern Model element), the inferred JVM model classes (the various JVM Generic Type instances), and also the referred Java classes as external resources (the resources beginning with the java:/ URIs).

Download

If you are interested in the plug-in in action, download it from our update site: http://eclipse.cubussapiens.hu, or take a look at the repository on Github: https://github.com/ujhelyiz/xtext-reflective

Version 0.5.3 is already available, and hopefully works well for all languages.

Applications of high-performance model queries @ OMG/Eclipse workshop

At the last EclipseCon Europe, my collegue, István Ráth presented our incremental model query approach in the Modeling Symposium. Since then, we are working hard to evaluate further uses of the technology while creating a better tooling support for the specification of those queries.

This year, during the OMG/Eclipse workshop a day before EclipseCon 2012 István will present our approach together with our new results:

14:35 – 15:00

High performance queries and their novel applications

István Ráth- Research Associate, BME

High-performance model queries are still a major challenge for the industry standard Eclipse Modeling Framework (EMF), they are intensively used in various model validation, model transformation or code generation scenarios. Existing EMF-based query technologies (like Eclipse OCL, EMF Model Query 1-2, or native Java programs) can have significant scalability issues for complex queries of models over 50-100000 model elements. Moreover, it is often tedious and time consuming to efficiently implement EMF-based queries manually on a case-by-case basis.

Recent initiatives, such as the EMF-IncQuery framework (http://viatra.inf.mit.bme.hu/incquery) have proposed innovative algorithms to mitigate this issue. EMF-IncQuery uses a graph query language, and provides incremental query evaluation by caching the results of the model queries and incrementally maintaining the cache when the underlying EMF model changes. Furthermore, the EMF-IncQuery framework can be easily integrated into existing EMF-based applications in a non-intrusive way.

In the first part of the talk, we overview the results of a thorough benchmark comparison
intended to aid software engineers in picking the best tool for a given purpose. The measurements involve several versions of Eclipse OCL, manually optimized Java code, dedicated academic query and well-formedness checking tools and EMF-IncQuery and highlight the most important practical considerations of queries in model-driven tool design.

In the second part of the talk, we briefly overview novel and innovative uses of high performance queries such design-space exploration, whereby traditional modeling is augmented with AI techniques to aid the (semi-automatic) optimization of model-based software designs.

If you are interested in modeling techniques, I recommend attending to the talk. As a teaser, I show now an existing application of such AI-based techniques: an automated quick fix generation for domain-specific modeling languages. We already presented this technique, albeit based on the VIATRA2 transformation framework in VL/HCC 2011. The article, together with a video demonstration is available from http://dx.doi.org/10.1109/VLHCC.2011.6070373

For interest, the video demonstration is also uploaded to Youtube for easier watching. (UPDATE: For feed readers the video url is the following: http://youtu.be/kPc4x01K7-s).

Reusing PDE in modeling context

If you’re developing with EMF it is a common task to separate the model into multiple files along with enabling the user to create crosslinks between them. This works out-of box if the files are located inside the same project. However, in some cases for larger models it is simply not enough. It can be useful to be able to define reusable (and versioned) packets of models and enable the user to define a configuration which determines the imported model packages. Sounds familiar? The same functionality exists in PDE. Maybe it can be reused for non-java purposes.

Continue reading “Reusing PDE in modeling context”

EMF-IncQuery @ EclipseCon Europe ’11

The research of my group often build on various Eclipse technologies. We are developers of the VIATRA2 model transformation framework. Recently we also created EMF-IncQuery, an incremental query technology over EMF models, that we believe really useful in various areas, such as model validation during editing or model synchronization scenarios.

This year, a collegue of mine, István Ráth will attend at EclipseCon Europe, and during the Modeling Symposium present the basic use cases of the tool. In the following I attach a short abstract of the talk to give a basic idea:

EMF-IncQuery: Incremental evaluation of model queries over large EMF model

A Talk at the EclipseCon Europe 2011 Modeling Symposium
Presenter: István Ráth

High-performance model queries are still a major challenge for the industry standard Eclipse Modeling Framework (EMF), as they are intensively used in various model validation, model transformation or code generation scenarios.

Existing EMF-based query technologies (like OCL, EMF Query or native Java programs) have significant scalability issues for models over 50000 model elements. Moreover, it is often tedious and time consuming to efficiently implement EMF-based queries manually on a case-by-case basis.

This talk introduces EMF-IncQuery, a declarative and scalable EMF model query framework. EMF-IncQuery uses a graph query language, and provides incremental query evaluation by caching the results of the model queries and incrementally maintaining the cache when the underlying EMF model changes. Furthermore, the EMF-IncQuery framework can be easily integrated into existing EMF-based applications in a non-intrusive way.

During the talk, we quickly overview how easy it is to define and integrate highly scalable model queries into existing EMF-based applications, in the form of a very short live demonstration using the MDT Papyrus modeling tool. The scalability of the engine will also be demonstrated, with on-the-fly constraint revalidation that takes less than 100 milliseconds over large AUTOSAR models with over 1 million elements.

 

More info: http://viatra.inf.mit.bme.hu/incquery

Unfortunately, I cannot go to the conference, but I hope, the 10th birthday of Eclipse will be celebrated well. Have fun, and if you are interested, listen at our talk.

Source code visualisation for my projects

Today I read the announcement of SourceCloud, a new Zest/Cloudio-based visualization for source code. As I like cool visualizations, I tried it out on the open projects I am participating in.At first I created the cloud for the source code of the Debug Visualisation project. Globally it consists of about half Eclipse debugger/UI and Java keywords – as this is quite a small project (about 4 kLOC), this is somewhat expected with 200 words.

SourceCloud of the Debug Visualisation Project

However, it is interesting, that the strings ‘end_of_line‘ and ‘sp_cleanup‘ found their way in. Luckily, only a few one-character names and numbers are present, meaning, we managed to created longer variable names…

The cloud of the VIATRA2 model transformation framework is more interesting: it is a much larger codebase, developed for several year by around a dozen people. Because of the size I generated the cloud using 300 words, but almost no Java keywords found their way into the graph.

SourceCloud of the VIATRA2 framework

However, the mandatory comment parts did, e.g. nbsp or the names of some creators. A lot of EMF-specific keywords are also present. They are present because we have quite a large EMF metamodel that provides several hundred generated Java files.

At last, but not least I also checked the cloud of the EMF-IncQuery project. This is smaller, then the VIATRA2 project, but larger then the Debug Visualisation. Additionally, it has a shorter history, but with several key committers.

SourceCloud of the EMF-IncQuery project

My personal favorite is this diagram, as it shows a lot of nice things: e.g. four digit numbers in large quantities (magic numbers FTW) or the absolute champion string: ‘HUKfyM7ahfg‘. All of them are present in the Ecore Diagram of the defined metamodel (the meaningless string 152 times as a postfix of an identifier 🙂 ). At least, I learned something about the internal model representation of GMF.

And how do your projects look like?