SlideShare a Scribd company logo
1 of 18
Scala DSL for Mobile Application
Specification
Specification Language
“A specification language … used during systems analysis, requirement
analysis and system design to describe a system at a much higher level
than a programming language…” -Wikipedia
Spec Languages examples: CASL, VDM, Z, Alloy, UML, etc.
Native Code Generating
Cross-platform translation
Specification
DSL
AST
Android Native
Project
iOS Native
Project
Requirements
Component
Model
Data
structures
Native Code Generating (contd.)
• Requirements – functional and non-functional, use-cases, user-stories,
feature-lists, business rules, etc.
• Component Model – splitting the application area into a set of components
with precise interfaces and behavior:
Widgets
ContentProvider, Entities
Services, BroadcastReceivers
NotificationService
GPS, GMap
Camera, Audio, Sensors
• Data structures – data entities and bindings between entities and
components.
• Specification DSL is a Ubiquitous language of the problem domain.
Domain Specific Language (DSL)
Overview
“Domain modeling (or domain analysis) involves the identification of all
the major components of the domain and how they collaborate.”
– DSLs in Action, D.Ghosh
The problem domain is the processes, entities and business rules that
are part of the analysis.
The solution domain is the implementation of problem domain in
terms of components with precisely defined behavior.
Scala as a host language of a DSL
Scala is a good choice to be a host language of the specification DSL
since it supports a lot of approaches makes it DSL friendly:
• Operators overriding
• Implicit conversions
• Infix notation to avoid parenthesis
• High-order functions, currying
• Meta-programming (macroses)
• Statically typed
Meta Model: Containers and
Components
An application specified in terms of components and connections
between components. Each component could contain inner
components (container).
A connection indicates either data flow or events-handling
relation between components.
GuiContainer is an example of a group of widgets that translates
to UI functionality. A connector between two Gui Containers
means that there is for instance a navigation event from one to
another.
Meta Model: Data Binding and Events
Handling
The DSL supports several kinds of Data Binding relations
between components:
Events-handling allows to add behavior to components, several
groups of events supported (navigation, persistence, messaging,
etc.):
gui1.listView1.onClick >~ gui2.doActivate
gui1.pane1.onUpdate >~ dbPrv.doUpdate
gui1 <~ dbPrv
Read-only binding Write-only binding Bidirectional binding
target <= source source >= target comp1 <=> comp2
Sample App
val mainActivity = GuiContainer(
EditText(‘address), EditText(‘longitude), EditText(‘latitude)
)
val db = DbProvider {
val coordinates = Entity {
val address = Item
val longitude = Item
val latitude = Item
}
}
mainActivity <~> db
mainActivity <=> db.coordinates
Sample App-2
Component Open API
Simplified API that each component conforms to:
trait Component {
val owner: Component
def inners: Set[Component]
def events: Set[Event]
def handlers: Set[Handler]
def bound: Option[Component]
def +=(comp: Component): this.type
def <~(comp: Component): this.type
def ~>(comp: Component): this.type
def <~>(comp: Component): this.type
def <=(comp: Component): this.type
def >=(comp: Component): this.type
def <=>(comp: Component): this.type
def generate(code: Code): Unit
}
Component Open API (contd.)
It’s a component’s responsibility to initialize owner field of each
inner component. events and handlers returns respective lists of
instances and bound reflects a data binding relation added.
+=-operator appends inner components, <~, >~, <~> manage
even-handling capabilities and <=, >=, <=> control data bindings.
Overridden method generate provides native code generating –
business-logic specifics, features implementation using dynamic
template engine.
Component-based Open API (contd.)
Embedding of business logic and customization of the component’s behavior should be applied per each particular component type:
generate(app: Code): Unit = this match {
case root: App =>
root.generate(app)
root.inners.foreach(_.generate(app))
~app
case gui: GuiContainer =>
val activity = Public::Class(gui.id, AndroidAppActivity)
gui.generate(activity)
gui.inners.foreach(_.generate(activity))
case dbPrv: ContentProvider =>
val provider = Public::Class(dbPrv.id, AndroidContentContentProvider)
dbPrv.generate(provider)
dbPrv.inners.foreach(_.generate(provider))
}
Java CodeGen DSL
Code Generation DSL (Codegen DSL or just Codegen) is a meta-programming framework that allows generating
of Java-classes based on dynamic composition of fragments of code into methods and classes.
Fragments of code are templates contain expressions within ${} that calculated while using Scala string
interpolation process. Code fragment trait has a ~-operator that evaluates a template. E.g. fragment
~$"""
super.onCreate(savedInstanceState);
setContentView(R.layout.${activity.sName});
"""
will generate Java-code (activity.sName is “activity1”):
super.onCreate(savedInstanceState);
setContentView(R.layout.activity1);
Java CodeGen DSL (contd.)
Available at https://github.com/alex-evseenko/codegen
Supports API to dynamically add templates and then generate code:
val activity = Public::Class(app.guiPackage, 'MyActivity, AndroidAppActivity)
val onCreate =
Override::Public::Method('onCreate, 'savedInstanceState->AndroidOsBundle, JavaVoid)(
$"""
super.onCreate(savedInstanceState);
setContentView(R.layout.${activity.sName});
""")
activity += onCreate
~activity
Web-platform
To expose the DSL functionality to end-users simple web-app is
available at http://adaldev.com
It consists from Apps Repository, Builder and Target project page to
create an app, translate it to native Android project and then build
binary module.
Advantages and Disadvantages
Clearly defined borders of components
Extendable and customizable components
Automation Integral Testing
Produce readable native code
Cross-platform and multi-versioning
Meta-programming is difficult to integrate with IDE
Supporting of business logic
Reverse engineering from native code to meta-model is difficult
Questions

More Related Content

Similar to Specification Scala DSL for Mobile Application

Современная архитектура Android-приложений - Archetype / Степан Гончаров (90 ...
Современная архитектура Android-приложений - Archetype / Степан Гончаров (90 ...Современная архитектура Android-приложений - Archetype / Степан Гончаров (90 ...
Современная архитектура Android-приложений - Archetype / Степан Гончаров (90 ...Ontico
 
Crafted Design - LJC World Tour Mash Up 2014
Crafted Design - LJC World Tour Mash Up 2014Crafted Design - LJC World Tour Mash Up 2014
Crafted Design - LJC World Tour Mash Up 2014Sandro Mancuso
 
Crafted Design - Sandro Mancuso
Crafted Design - Sandro MancusoCrafted Design - Sandro Mancuso
Crafted Design - Sandro MancusoJAXLondon2014
 
Intro To Android App Development
Intro To Android App DevelopmentIntro To Android App Development
Intro To Android App DevelopmentMike Kvintus
 
Technology and Android.pptx
Technology and Android.pptxTechnology and Android.pptx
Technology and Android.pptxmuthulakshmi cse
 
Overview of atg framework
Overview of atg frameworkOverview of atg framework
Overview of atg frameworkYousuf Roushan
 
Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014Sandro Mancuso
 
Android Development
Android DevelopmentAndroid Development
Android Developmentmclougm4
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introductionaswapnal
 
Azure Functions.pptx
Azure Functions.pptxAzure Functions.pptx
Azure Functions.pptxYachikaKamra
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011YoungSu Son
 
Android- Introduction for Beginners
Android- Introduction for BeginnersAndroid- Introduction for Beginners
Android- Introduction for BeginnersTripti Tiwari
 
Lecture 05. UI programming for Mobile Apps
Lecture 05. UI programming for Mobile AppsLecture 05. UI programming for Mobile Apps
Lecture 05. UI programming for Mobile AppsMaksym Davydov
 
MyMobileWeb Certification Part II
MyMobileWeb Certification Part IIMyMobileWeb Certification Part II
MyMobileWeb Certification Part IIcrdlc
 

Similar to Specification Scala DSL for Mobile Application (20)

Современная архитектура Android-приложений - Archetype / Степан Гончаров (90 ...
Современная архитектура Android-приложений - Archetype / Степан Гончаров (90 ...Современная архитектура Android-приложений - Archetype / Степан Гончаров (90 ...
Современная архитектура Android-приложений - Archetype / Степан Гончаров (90 ...
 
PPT Companion to Android
PPT Companion to AndroidPPT Companion to Android
PPT Companion to Android
 
Crafted Design - LJC World Tour Mash Up 2014
Crafted Design - LJC World Tour Mash Up 2014Crafted Design - LJC World Tour Mash Up 2014
Crafted Design - LJC World Tour Mash Up 2014
 
Crafted Design - Sandro Mancuso
Crafted Design - Sandro MancusoCrafted Design - Sandro Mancuso
Crafted Design - Sandro Mancuso
 
Intro To Android App Development
Intro To Android App DevelopmentIntro To Android App Development
Intro To Android App Development
 
Technology and Android.pptx
Technology and Android.pptxTechnology and Android.pptx
Technology and Android.pptx
 
Android Anatomy
Android  AnatomyAndroid  Anatomy
Android Anatomy
 
Overview of atg framework
Overview of atg frameworkOverview of atg framework
Overview of atg framework
 
Android Deep Dive
Android Deep DiveAndroid Deep Dive
Android Deep Dive
 
Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014Crafted Design - ITAKE 2014
Crafted Design - ITAKE 2014
 
Android Technology
Android TechnologyAndroid Technology
Android Technology
 
Android Development
Android DevelopmentAndroid Development
Android Development
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introduction
 
Azure Functions.pptx
Azure Functions.pptxAzure Functions.pptx
Azure Functions.pptx
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
 
Android- Introduction for Beginners
Android- Introduction for BeginnersAndroid- Introduction for Beginners
Android- Introduction for Beginners
 
Angular2 and You
Angular2 and YouAngular2 and You
Angular2 and You
 
Android primer
Android primerAndroid primer
Android primer
 
Lecture 05. UI programming for Mobile Apps
Lecture 05. UI programming for Mobile AppsLecture 05. UI programming for Mobile Apps
Lecture 05. UI programming for Mobile Apps
 
MyMobileWeb Certification Part II
MyMobileWeb Certification Part IIMyMobileWeb Certification Part II
MyMobileWeb Certification Part II
 

Recently uploaded

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 

Recently uploaded (20)

Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 

Specification Scala DSL for Mobile Application

  • 1. Scala DSL for Mobile Application Specification
  • 2. Specification Language “A specification language … used during systems analysis, requirement analysis and system design to describe a system at a much higher level than a programming language…” -Wikipedia Spec Languages examples: CASL, VDM, Z, Alloy, UML, etc.
  • 3. Native Code Generating Cross-platform translation Specification DSL AST Android Native Project iOS Native Project Requirements Component Model Data structures
  • 4. Native Code Generating (contd.) • Requirements – functional and non-functional, use-cases, user-stories, feature-lists, business rules, etc. • Component Model – splitting the application area into a set of components with precise interfaces and behavior: Widgets ContentProvider, Entities Services, BroadcastReceivers NotificationService GPS, GMap Camera, Audio, Sensors • Data structures – data entities and bindings between entities and components. • Specification DSL is a Ubiquitous language of the problem domain.
  • 5. Domain Specific Language (DSL) Overview “Domain modeling (or domain analysis) involves the identification of all the major components of the domain and how they collaborate.” – DSLs in Action, D.Ghosh The problem domain is the processes, entities and business rules that are part of the analysis. The solution domain is the implementation of problem domain in terms of components with precisely defined behavior.
  • 6. Scala as a host language of a DSL Scala is a good choice to be a host language of the specification DSL since it supports a lot of approaches makes it DSL friendly: • Operators overriding • Implicit conversions • Infix notation to avoid parenthesis • High-order functions, currying • Meta-programming (macroses) • Statically typed
  • 7. Meta Model: Containers and Components An application specified in terms of components and connections between components. Each component could contain inner components (container). A connection indicates either data flow or events-handling relation between components. GuiContainer is an example of a group of widgets that translates to UI functionality. A connector between two Gui Containers means that there is for instance a navigation event from one to another.
  • 8. Meta Model: Data Binding and Events Handling The DSL supports several kinds of Data Binding relations between components: Events-handling allows to add behavior to components, several groups of events supported (navigation, persistence, messaging, etc.): gui1.listView1.onClick >~ gui2.doActivate gui1.pane1.onUpdate >~ dbPrv.doUpdate gui1 <~ dbPrv Read-only binding Write-only binding Bidirectional binding target <= source source >= target comp1 <=> comp2
  • 9. Sample App val mainActivity = GuiContainer( EditText(‘address), EditText(‘longitude), EditText(‘latitude) ) val db = DbProvider { val coordinates = Entity { val address = Item val longitude = Item val latitude = Item } } mainActivity <~> db mainActivity <=> db.coordinates
  • 11. Component Open API Simplified API that each component conforms to: trait Component { val owner: Component def inners: Set[Component] def events: Set[Event] def handlers: Set[Handler] def bound: Option[Component] def +=(comp: Component): this.type def <~(comp: Component): this.type def ~>(comp: Component): this.type def <~>(comp: Component): this.type def <=(comp: Component): this.type def >=(comp: Component): this.type def <=>(comp: Component): this.type def generate(code: Code): Unit }
  • 12. Component Open API (contd.) It’s a component’s responsibility to initialize owner field of each inner component. events and handlers returns respective lists of instances and bound reflects a data binding relation added. +=-operator appends inner components, <~, >~, <~> manage even-handling capabilities and <=, >=, <=> control data bindings. Overridden method generate provides native code generating – business-logic specifics, features implementation using dynamic template engine.
  • 13. Component-based Open API (contd.) Embedding of business logic and customization of the component’s behavior should be applied per each particular component type: generate(app: Code): Unit = this match { case root: App => root.generate(app) root.inners.foreach(_.generate(app)) ~app case gui: GuiContainer => val activity = Public::Class(gui.id, AndroidAppActivity) gui.generate(activity) gui.inners.foreach(_.generate(activity)) case dbPrv: ContentProvider => val provider = Public::Class(dbPrv.id, AndroidContentContentProvider) dbPrv.generate(provider) dbPrv.inners.foreach(_.generate(provider)) }
  • 14. Java CodeGen DSL Code Generation DSL (Codegen DSL or just Codegen) is a meta-programming framework that allows generating of Java-classes based on dynamic composition of fragments of code into methods and classes. Fragments of code are templates contain expressions within ${} that calculated while using Scala string interpolation process. Code fragment trait has a ~-operator that evaluates a template. E.g. fragment ~$""" super.onCreate(savedInstanceState); setContentView(R.layout.${activity.sName}); """ will generate Java-code (activity.sName is “activity1”): super.onCreate(savedInstanceState); setContentView(R.layout.activity1);
  • 15. Java CodeGen DSL (contd.) Available at https://github.com/alex-evseenko/codegen Supports API to dynamically add templates and then generate code: val activity = Public::Class(app.guiPackage, 'MyActivity, AndroidAppActivity) val onCreate = Override::Public::Method('onCreate, 'savedInstanceState->AndroidOsBundle, JavaVoid)( $""" super.onCreate(savedInstanceState); setContentView(R.layout.${activity.sName}); """) activity += onCreate ~activity
  • 16. Web-platform To expose the DSL functionality to end-users simple web-app is available at http://adaldev.com It consists from Apps Repository, Builder and Target project page to create an app, translate it to native Android project and then build binary module.
  • 17. Advantages and Disadvantages Clearly defined borders of components Extendable and customizable components Automation Integral Testing Produce readable native code Cross-platform and multi-versioning Meta-programming is difficult to integrate with IDE Supporting of business logic Reverse engineering from native code to meta-model is difficult