Git Product home page Git Product logo

simpleocl-1's Introduction

SimpleOCL

SimpleOCL is an embeddable OCL implementation for inclusion in transformation languages for the EMF Transformation Virtual Machine (EMFTVM). SimpleOCL is built on top of the Eclipse Modeling Framework (EMF) and EMFText.

Below you can find an example of SimpleOCL code:

module test;

metamodel UML : 'http://www.eclipse.org/uml2/3.0.0/UML';

import OCL;

static def : allClasses : Sequence(UML!Class) =
	OclAny::allInstances()->union(
	UML!Class.allInstances());

def : allModuleNames : Set(String) =
	self.modules.getKeys()->map(k | k.toString());

context UML!Class def : umlQualifiedName(sep : String) : String =
	(let parent : OclAny = self.refImmediateComposite() in
	if parent.oclIsUndefined() then
		self.name
	else
		parent.umlQualifiedName() + sep + self.name
	endif)
	+
	let slottest : String = 'test' in slottest;

context Collection(OclAny) def : map(f : Lambda(OclAny):OclAny) : Collection(OclAny) =
	self->collect(e | f(e));


context Collection(OclAny) def : join(f : Lambda(OclAny, OclAny) : OclAny) : OclAny =
	self->iterate(e; acc : OclAny = OclUndefined |
		if acc.oclIsUndefined() then
			e
		else 
			f(acc, e)
		endif
	);

context OclAny def : name() : String =
	'<unnamed>';

context String def : name() : String =
	if self.isEmpty() then
		super.name()
	else
		self
	endif;
	
context OclAny def : name : String =
	self.name();

context String def : name : String =
	super.name;

static def : map : Map(OclAny, OclAny) =
	Map{
		(1, 'one'),
		(2, 'two'),
		(3, 'three')
	};

static def : tuple : Tuple(a : String, b : String) =
	Tuple{
		a = 'one',
		b = 'two'
	};
	
static def : tupleType : TupleType(a : String, b : String) =
	Tuple{
		a = 'one',
		b = 'two'
	};
	
context Env static def : main() : Set(String) =
	(36 + 3.5).toString().debug('arithmetic test') +
	env.allModuleNames->join(x, y | x + ', ' + y).debug('module names') +
	Env::map.debug('map').toString() +
	Env::tuple.debug('tuple').toString();

This code defines a couple of attributes and operations. Note that we've added the Lambda type, so you can define your own iterator expressions, e.g.:

list->map(x | x*2)

More examples can be found in iterators.simpleocl.

To facilitate better integration with Java code, we've also added support for static attributes/operations. These are invoked using the :: operator instead of the . operator. Finally, all attributes/operations without a defined context fall in the Env context, which stands for the environment. The environment has a single runtime instance, which can be accessed using the env keyword.

SimpleOCL does not support OCL's pre, post, and inv declarations. It is intended as a navigation language to be embedded in model transformation languages, and therefore only supports def declarations. That said, EMFTVM's integration with Java allows you to do much more.

Installation

To download and install the SimpleOCL Eclipse plugin, install it from the following Eclipse update site:

Drag to your running Eclipse workspace to install SimpleOCL or https://raw.githubusercontent.com/dwagelaar/simpleocl/master/org.eclipselabs.simpleocl.updatesite/

Running SimpleOCL/EMFTVM modules

Note that SimpleOCL modules don't do anything normally, unless you define a static main operation:

static def : main() : OclAny = ...

EMFTVM includes a separate launch configuration dialog that looks very much like ATL's launch configuration dialog. It can be found via "Run -> Run Configurations...".

EMFTVM launch configuration dialog

Links

simpleocl-1's People

Contributors

dwagelaar avatar

Watchers

James Cloos avatar amine BEN avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.