Thursday, March 29, 2012

Building your own Java with the Whole Platform

At the Code Generation 2012 conference me and Enrico attended the hands-on session Building your own Java with MPS. Sadly we haven't had the opportunity to follow the second part of the tutorial because in the afternoon we had to present our session in parallel.

In the evening I managed to complete their assignment using MPS then I developed the following solution using the Whole Platform.


Exercise 2: Extending Java with Range Iteration

The solution can be defined and tested live on a running Whole Platform Language Workbench (Eclipse) without generating any code.

Open the given java example using the "Java Editor (Whole)" and save it with a different name and persistence (.xwl).


Define the metamodel of the MPSDemo1 DSL containing just the RangeIterator entity. Then add the Foreign Types Relations to be able to use the RangeIterator as a Java statement and to be able to use Java expressions and statements inside of it.

The metamodel is self-contained: you can use it alone or together with the Java language. Of course to be able to write an heterogeneous model both languages have to be deployed.

Deploy the MPSDemo1 DSL (Interpret button in the toolbar) and place a RangeIterator instance on the java Sample using the content assist menu. Then fill its features with java code as requested.


If you want to obtain also a concrete textual notation for the RangeIterator you have also to define a Grammar.



Deploy the grammar and select the new notation from the context menu of the RangeIterator instance.


Define and deploy the reduceToJava function.

In order to save the reduced version of the extended java example into a java source file define and deploy an Artifacts Generator.

Now you can go back to the extended java example and apply the generator.


No comments:

Post a Comment