Android code generation(1)

Summary

This tutorial covers the instalation of Acceleo and the creation of a Code Generator to model Android Applications.

Instalation and Requisites

  1. Eclipse IDE for Java Developeers, version 3.6.2 (Helios SR2 release).
    Available at: http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/heliossr2
  2. Acceleo (version 3.1.0)
    Install "Acceleo SDK" from the "Acceleo 3.1 update site" (http://download.eclipse.org/modeling/m2t/acceleo/updates/releases/3.1)
  3. Android Development Tools (ADT) plugin
    Instructions available at: http://developer.android.com/sdk/installing.html.
  4. Android 2.3.3 Platform (SDK and AVD)
    If you can follow the "Hello, World" tutorial you have set it up correctly.

Metamodel plugin installation

Before creating the Acceleo project you must export and install the plug-in containing your DSL metamodel. Therefore, export and install the Xtext plugin (org.xtext.example.droid) generated in the previous tutorial.

Note: If you have extracted the EMF plugin your Xtext plugin (org.emf.example.droid) you should install it too. The tutorial forementioned contains detailed instructions on performing both operations.

Acceleo

Acceleo is a pragmatic implementation of the Object Management Group (OMG) MOF Model to Text Language (MTL) standard. So, with Acceleo you can generate code from a model through a Model to Text transformation.

In this tutorial we will cover a Model to Text transformation, generating code to an Android application from a model written in the Droid DSL (covered in the "Building the Droid DSL editor with Xtext" tutorial).

Creating a sample Android Project

0fc8d6bdc1acf60f33b8132327ca364185e86136

We are going to create a sample Android Project. This project will be our guide in the generator creation process, and will be our test to the generator.

  1. Open menu File > New > Project...
  2. Choose Android > Android Project
  3. Fill the Project Options as follows:
    1. Project name and Package Name: org.android.example.droid
    2. Build target: Android 2.3.3
    3. Application Name: Hello Droid
    4. Create Activity: org.android.example.droid.MainActivity
    5. Min SDK Version: 10

/images/01.png

Creating a Droid file

In order to test the generator, we need to have some source file written in our DSL language.

  1. Right-click the org.android.example.droid
  2. Choose New > Folder
  3. Create a folder named model
  4. Right-click the created model folder
  5. Choose New > File
  6. Create a file named hello.droid
  7. Paste the following code in the file contents:
//From: http://developer.android.com/resources/tutorials/hello-world.html

application "Hello, Droid" => org.android.example.droid

hello = "Hello Droid!"

screen Main {
    show main
}

layout main {
    # textView text_view string(hello) {
        layout: {
            width: fill_parent;
            height: fill_parent;
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值