Reinaldo Junior

Um outro tech-blog

The Droid DSL

The first part of my GSoC project is creating a DSL (Domain Specific Language) targeting the development of Android applications. The main objective is the building of a DSL which can be used as the basis to the development of the Amalgamation Tutorials (the project’s final objective).

The DSL’s abstract syntax [1] (an Ecore metamodel) was created from the definition of a concrete syntax  (a Xtext grammar [2]). To this part, I used Xtext. Before that, I and my mentor had discussed about what granularity level should be used to choose what concepts should be expressed in the DSL. A too fine granularity level could lead to a very detailed DSL but would take too much time to complete, while a too coarse one could lead to an very constrained DSL (and maybe useless).


Considering this, I chose the following concepts as main concepts to the DSL:
  • Application - The main concept. We’re talking about Android Applications.
  • Activity - Represents an application screen and the user interface displayed.
  • Layout - Represents a collection of UI elements
  • Widget - Represents the various UI elements
  • Resource - Represents values which can be assigned to widgets properties. They have a type and can be serialized to a resource file (XML) 
The following example ilustrates the Hello World sample application (provided by Android) written using the Droid DSL (there are more Hello World examples available [3])



In order to have some direction in the creation of the tutorials, I started to create a code-generator using a Model-to-Text transformation. The transformation [4] can generate the AndroidManifest.xml file that describes the application, the Activity Java class, the Layout XML file and the String resource XML file.
To make this I used the Acceleo.

If you want to play with this DSL you just need to install the generated plugins in your Eclipse and create a new file with the .droid extension. For more information check the project repository at GitHub.

References:

  1. Harel, D., & Rumpe, B. (2000). Modeling Languages: Syntax, Semantics and All That Stuff Part I: The Basic Stuff. Citeseer. doi: 10.1.1.10.1512.
  2. To more info, see: Droid.xtext
  3. Some of the Hello Views tutorials are available: Relative Layout and Linear Layout.
  4. Available under this path