developing a new epsilon language through annotations: testlang

19
MoDELS 2016 Advanced Model Management with Epsilon Advanced Model Management with Epsilon MoDELS 2016 Developing a new Epsilon Language through Annotations: TestLang Antonio Garcia-Dominguez @antoniogado 1

Upload: antonio-garcia-dominguez

Post on 15-Apr-2017

123 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Developing a new Epsilon Language through Annotations: TestLang

MoDELS 2016 Advanced Model Management with EpsilonAdvanced Model Management with EpsilonMoDELS 2016

Developing a new Epsilon Language through Annotations:

TestLangAntonio Garcia-Dominguez

@antoniogado

1

Page 2: Developing a new Epsilon Language through Annotations: TestLang

MoDELS 2016 Advanced Model Management with Epsilon

When should I use annotations?

• One of the Epsilon languages does almost everything that you need, but…

• … you need to add a thin layer of orchestration logic on top of it.

• Some examples:– Unit testing (EOL + orchestration)– Model generation (EOL + ...)– Model mutation (EOL/ETL + ...)– Categorized model validation (EVL + ...)– Model-driven game engine...

2

Page 3: Developing a new Epsilon Language through Annotations: TestLang

MoDELS 2016 Advanced Model Management with Epsilon

Example TestLang script (v1)var rnd = new Native('java.util.Random');

@test

operation allInstancesWorks() {

if (Class.all.size != 6) { “FAILED aiw”.println(); }

}

@test

$times 10 * 10

operation randomTest() {

var b = 2 + rnd.nextInt(9); var e = rnd.nextInt(10);

if (slowPow(b, e) != fastPow(b, e)) { “FAILED rt”.println(); }

} 3

Page 4: Developing a new Epsilon Language through Annotations: TestLang

MoDELS 2016 Advanced Model Management with Epsilon

Overview

• TestLang is divided into:– org.eclipse.epsilon.examples.testlang.engine

implements the language (Eclipse-agnostic)– org.eclipse.epsilon.examples.testlang.dt

provides Eclipse dev tools

• Sources here:– https://git.eclipse.org/c/epsilon/org.eclipse.e

psilon.git/tree/examples

4

Page 5: Developing a new Epsilon Language through Annotations: TestLang

MoDELS 2016 Advanced Model Management with Epsilon

TESTLANG EXECUTION ENGINEImplementing a simple unit testing language on top of EOL

5

Page 6: Developing a new Epsilon Language through Annotations: TestLang

MoDELS 2016 Advanced Model Management with Epsilon

TestLangModule: execution engine

● Inherits from EolModule, overrides methods○ execute(): interprets @test and $times

● 68 lines of Java code6

Page 7: Developing a new Epsilon Language through Annotations: TestLang

MoDELS 2016 Advanced Model Management with Epsilon

AnnotatableModuleElement

• Superclass of anything that can be annotated– EOL operations– ETL rules– EVL contexts and constraints...

• Two types of annotations supported:– Simple: “@test a” - constant value– Executable: “$test self.x * 2” - uses expression– Repeated annotations are allowed

• Provides methods for handling annotations

7

Page 8: Developing a new Epsilon Language through Annotations: TestLang

MoDELS 2016 Advanced Model Management with Epsilon

Example TestLang script (v2)var rnd = new Native('java.util.Random');

@test

operation allInstancesWorks() { areEqual(6, Class.all.size); }

@test

$times 10 * 10

operation randomTest() {

var base = 2 + rnd.nextInt(9);

var exp = rnd.nextInt(10);

areEqual(slowPow(base, exp), fastPow(base, exp));

}8

Page 9: Developing a new Epsilon Language through Annotations: TestLang

MoDELS 2016 Advanced Model Management with Epsilon

TestLangModule: add areEqual

● By overriding prepareContext(), we can add task-specific operations/variables

● Operations provided by OperationContributor9

Page 10: Developing a new Epsilon Language through Annotations: TestLang

MoDELS 2016 Advanced Model Management with Epsilon

Operation contributors

• When processing x.f(args):– contributesTo(x) must return true– f(args) must be a method of the contributor

• Contextless operations (e.g. “areEqual”) receive a special value in contributesTo:– EolNoType.NoInstance

10

Page 11: Developing a new Epsilon Language through Annotations: TestLang

MoDELS 2016 Advanced Model Management with Epsilon

TESTLANG ECLIPSE-BASED DEVELOPER TOOLS

Integration of TestLang into Eclipse

11

Page 12: Developing a new Epsilon Language through Annotations: TestLang

MoDELS 2016 Advanced Model Management with Epsilon 12

Page 13: Developing a new Epsilon Language through Annotations: TestLang

MoDELS 2016 Advanced Model Management with Epsilon

TestLang developer tools

• Same approach as the engine: inherit from common.dt / eol.dt and refine as desired– 65 lines of Java code

• plugin.xml (49 lines):– Integrates all our subclasses– Associates .eolt with the “New TestLang” wizard– Reuses EOL editor/debugger for .eolt files– Provides a custom icon for .eolt launch configs

• In short: mostly plumbing!

13

Page 14: Developing a new Epsilon Language through Annotations: TestLang

MoDELS 2016 Advanced Model Management with Epsilon

TestLang editor: same as EOL

14

Page 15: Developing a new Epsilon Language through Annotations: TestLang

MoDELS 2016 Advanced Model Management with Epsilon

TestLang launch facilities

15

Page 16: Developing a new Epsilon Language through Annotations: TestLang

MoDELS 2016 Advanced Model Management with Epsilon

Summary

• Showed how to implement a unit testing language on top of EOL:– @test tags an operation as a test case– $times allows for repeating the same test

• Reuses all EOL tooling:– Editor and debugger “for free”– Can work with EMF, CSV, BibTeX, XML, ...

• < 200 lines of code: 133 Java, 49 XML

16

Page 17: Developing a new Epsilon Language through Annotations: TestLang

MoDELS 2016 Advanced Model Management with EpsilonAdvanced Model Management with EpsilonMoDELS 2016

Questions?

@antoniogado

17

Page 18: Developing a new Epsilon Language through Annotations: TestLang

MoDELS 2016 Advanced Model Management with Epsilon

Other examples

@operator

$condition self.isKindOf(Addition)

operation add2sub() {

// … return Subtraction

}

@operator

$condition self.isKindOf(BooleanLiteral)

operation flipLiteral() {

// … return negated BooleanLiteral

}

For a model mutation language:

18

Page 19: Developing a new Epsilon Language through Annotations: TestLang

MoDELS 2016 Advanced Model Management with Epsilon

Other examples

@enemy

@after blinky

@sprite red_ghost.png

operation inky(player, enemies) {

// … compute which way to turn next …

// … compute speed …

}

In a model-driven game engine, operations could provide behavior for AI actors:

The language can provide built-in operations for common/expensive tasks (e.g. pathfinding algorithms).

19