Date post: | 16-Jul-2015 |
Category: |
Software |
Upload: | valerio-cosentino |
View: | 36 times |
Download: | 1 times |
Valerio CosentinoMassimo Tisi
Javier Luis Canovas Izquierdo
SOFSEM, 2015, Pec pod Sněžkou, Czech Republic
A Model-Driven Approach to Generate External DSLs from Object-Oriented
APIs
1© AtlanMod - [email protected]
Outline
Introduction
Model Driven Engineering
From API to DSL
Conclusion and Future work
2© AtlanMod - [email protected]
Introduction
Code abstraction and reuse allow the use of existing software knowledge (i.e., code libraries) to build new software by reducing:– Time– Resources– Redundancy
Code libraries can be accessed via:– APIs using mechanisms (function call, class
inheritance, etc.) provided by the General-purpose Programming Language (GPL)
– DSLs (Domain Specific Languages)
3© AtlanMod - [email protected]
Introduction
Are DSLs better than APIs?[1]– Pros:
DSLs can be more expressive, maintainable, concise and readable
Static validation, syntax highlighting, etc. Interpretation/compilation optimized for the DSL code execution
– Cons: DSLs requires a higher development cost
[1] Kelly, S., Tolvanen, J.P.: Domain-Specific Modeling: Enabling Full Code Generation. Wiley IEEE Computer (2008)
5© AtlanMod - [email protected]
Introduction
How to reduce the development cost when building a DSL?–Model Driven Engineering (MDE)
Automatic generation of DSL components:– compiler, validator, development environment
6© AtlanMod - [email protected]
Model Driven Engineering
What is MDE?– Models: first class entities in MDE (abstract
representation of the knowledge for a given domain)– Model transformations: operaration for model handling
Injectors/extractors to move between technical spaces [2]
[2] Kurtev, I., Bezivin, J., Aksit, M.: Technological Spaces : an Initial Appraisal. In: DOA. (2002) 1–6
7© AtlanMod - [email protected]
API classes to API metamodel
Mapping[3]– API class definitions metamodel elements– Java classes metaclasses
Attributes metaclass attributes Methods operations
Customization:– Some APIs can generate very large
metamodels Selection of a subset of API elements
– Tunable API metamodel Manual modifications
[3] Canovas Izquierdo, J.L., Jouault, F., Cabot, J., Garcıa Molina, J.: API2MoL: Automating the building of bridges between APIs and Model-Driven Engineering. Inform. Software Tech. 54(0) (2012) 257–273
11© AtlanMod - [email protected]
API metamodel to DSL metamodel
Domain-specific concepts extracted from the API metamodel
Domain-independent API structure– Templates
13© AtlanMod - [email protected]
Templates
Plain Old Data (POD)– For simple APIs to create and maintain a
data structure– API classes composed by getters, setters
and constructors
14© AtlanMod - [email protected]
Templates
Fluent– For APIs that rely on chaining method calls– The return values of the method calls
(keywords) are used to structure the DSL
15© AtlanMod - [email protected]
Templates
SimpleJava– For APIs that do not fit in the previous
categories– Java sub-set(statements, declarations, etc.)
16© AtlanMod - [email protected]
DSL metamodel to DSL tooling
Bridge between the Model TS and the Grammar TS– Mapping of metamodel elements into the grammar
rules– Development environment
The generation process is parameterized by:– The DSL metamodel (concepts, attributes,
references, cardinalities, etc.)– The template chosen (the grammar structure, the
development environment and compiler)– Particularized for Xtext[4]
[4] Eysholdt, M., Behrens, H.: Xtext: implement your language faster than the quick and dirty way. In: SPLASH. (2010) 307–309
18© AtlanMod - [email protected]
Compiler generation
Since the semantics of the DSL template is known, a DSL instance can be transformed into its equivalent in Java– SimpleJava
DSL concepts have a one-to-one correspondence with Java constructs
DSL model to Java model (MoDisco[5]) Java model to Java readable file (Acceleo[6])
[5] http://www.eclipse.org/gmt/modisco/technologies/J2SE5/|6] http://www.eclipse.org/acceleo
20© AtlanMod - [email protected]
Conclusion and Future work
MDE approach to connect API, Model and Grammar technical spaces
Template mechanism to generate the resulting DSL Proof of concept
Future work:– Identify more templates to cover other types of
DSLs (API characterization)– Study how our method could cope with more
complex APIs (event-driven, concurrent, etc.)– Explore how distinct APIs used in the same GPL can
be combined at DSL-level (interleaving DSLs)
21© AtlanMod - [email protected]