a model-driven approach to generate external dsls from object-oriented apis

21
Valerio Cosentino Massimo 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]

Upload: valerio-cosentino

Post on 16-Jul-2015

35 views

Category:

Software


1 download

TRANSCRIPT

Page 1: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

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]

Page 2: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

Outline

Introduction

Model Driven Engineering

From API to DSL

Conclusion and Future work

2© AtlanMod - [email protected]

Page 3: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

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]

Page 4: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

Introduction

API vs DSL:

4© AtlanMod - [email protected]

Page 5: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

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]

Page 6: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

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]

Page 7: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

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]

Page 8: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

From API to DSL

8© AtlanMod - [email protected]

Page 9: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

From API to DSL

9© AtlanMod - [email protected]

Page 10: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

From API to DSL

10© AtlanMod - [email protected]

Page 11: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

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]

Page 12: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

From API to DSL

12© AtlanMod - [email protected]

Page 13: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

API metamodel to DSL metamodel

Domain-specific concepts extracted from the API metamodel

Domain-independent API structure– Templates

13© AtlanMod - [email protected]

Page 14: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

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]

Page 15: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

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]

Page 16: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

Templates

SimpleJava– For APIs that do not fit in the previous

categories– Java sub-set(statements, declarations, etc.)

16© AtlanMod - [email protected]

Page 17: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

From API to DSL

17© AtlanMod - [email protected]

Page 18: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

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]

Page 19: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

From API to DSL

19© AtlanMod - [email protected]

Page 20: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

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]

Page 21: A Model-Driven Approach to Generate External DSLs from Object-Oriented APIs

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]