The Epsilon Pattern Language

Post on 23-Jan-2018

104 views 2 download

Transcript of The Epsilon Pattern Language

The Epsilon Pattern Language

Dimitris Kolovos, Richard Paige

May 22, 2017

Department of Computer Science

University of York

9th Workshop on Modelling in Software Engineering (MiSE)

ICSE 2017, Buneos Aires, Argentina

Pattern Matching

• In general: finding sub-structures of interest within morecomplex structures

• e.g. character sequences that look like email addresses

• In modelling: finding sets of model elements that have certain

properties and/or are connected in interesting ways

1

Example: Attributes to Pull Up

• Find pairs of attributes that can be moved up to a common

supertype

2

Declarative Pattern Matching

• Describe patterns declaratively

• Let the pattern matching engine figure out the optimal

execution plan

1

1from Arend et. al. – Henshin: Advanced Concepts and Tools for In-Place

EMF Model Transformations, ACM/IEEE MoDELS 2010

3

Declarative Pattern Matching Languages

Strengths

• Lots of room for behind-the-scene optimisation

• Can be executed incrementally (speed/memory trade-off)

Weaknesses

• Complex patterns can be challenging/verbose to express

graphically

• Falling back to complex expressions can reduce the scope for

optimisation/incrementality

• Current execution planners are not great

4

Practical Considerations

• Bound to a particular modelling technology / modelrepresentation format

• Non-negligible conversion cost

• No support for patterns that involve elements from different(heterogeneous) models

• e.g. UML activities and Simulink blocks

• No out-of-the-box support for “exporting” the results of

pattern matching to downstream activities (e.g. M2M, M2T)

5

Epsilon Pattern Language

• Hybrid OCL-based pattern matching language

• Modelling-technology independent

• Support for patterns that involve elements from multiple

heterogeneous models

• Support for “exporting” detected pattern instances to M2T,

M2M transformations etc.

6

Epsilon Organisation

eclipse.org/epsilon

7

Example: Attributes to Pull Up

• Find pairs of attributes that can be moved up to a common

supertype

8

Finding Attributes to Pull Up using EPL

pattern AttributesToPullUp

c : EClass ,

a1, a2 : EAttribute {

match :

a1.name = a2.name

and a1.eType = a2.eType

and a1 <> a2

and a1.eContainingClass.eAllSuperTypes.includes(c)

and a2.eContainingClass.eAllSuperTypes.includes(c)

}

9

A More Performant Version

pre {

var attributes = EAttribute.all.mapBy(a|a.name);

}

pattern AttributesToPullUp

c : EClass ,

a1 : EAttribute ,

a2 : EAttribute

from : attributes.get(a1.name). excluding(a1) {

match :

a1.eType = a2.eType

and a1.eContainingClass.eAllSuperTypes.includes(c)

and a2.eContainingClass.eAllSuperTypes.includes(c)

}

10

Adding a Second Model

• To specify attributes which should be ignored during pattern

detection

• The second model is an Excel spreadsheet with one worksheet

called “Ignore”

M

class attribute

. . . . . .

Employee name

. . . . . .

C

11

Pattern Matching on Two Models

pre { var attributes = M!EAttribute.all.mapBy(a|a.name); }

pattern AttributesToPullUp

c : M!EClass ,

a1 : M!EAttribute ,

a2 : M!EAttribute

from : attributes.get(a1.name). excluding(a1)

guard : not a1.isIgnored() and not a2.isIgnored() {

match :

a1.eType = a2.eType

and a1.eContainingClass.eAllSuperTypes.includes(c)

and a2.eContainingClass.eAllSuperTypes.includes(c)

}

operation M!EAttribute isIgnored() {

return C!Ignore.all.exists(i|i.attribute = self.name

and i.class = self.eContainingClass.name);

}12

Consuming Pattern Instances

• Pattern instances are wrapped as an EMC-compatiblein-memory “model”

• Patterns become types (e.g. AttributesToPullUp)

• Roles become fields (e.g. c, a1, a2)

• Other Epsilon programs can query and navigate them

• To transform, validate them etc.

• . . . even to detect patterns of patterns

13

Pattern Matching in a Workflow

<project default="main"> <target name="main">

<epsilon.emf.loadModel name="M" modelfile="model.ecore"

metamodeluri="http://www.eclipse.org/emf/2002/Ecore"/>

<epsilon.loadModel name="C" type="ExcelModel">

<parameter name="SPREADSHEET FILE" file="config.xlsx"/>

</epsilon.loadModel>

<epsilon.epl src="patterns.epl" exportas="P">

<model ref="M"/> <model ref="C"/>

</epsilon.epl>

<epsilon.eol>

for (atp in P!AttributesToPullUp.all) { atp.c.name.println(); }

<model ref="M"/><model ref="C"/><model ref="P"/>

</epsilon.eol>

</target > </project >14

Future Work

• Experimental evaluation against GrGen.NET, Henshin,

VIATRA/EMF-IncQuery, AGG etc.

• Static analysis

• Parallel and incremental pattern matching

15

Summary

• Hybrid OCL-based pattern matching language

• Modelling-technology independent

• Support for “exporting” detected patterns to downstream

model management programs

eclipse.org/epsilon

16