This is a light-weight tutorial for developing additions for SCCharts in KIELER. It will use Eclipse, EMF, and Xtend and therefore, finishing the corresponding tutorials could prove useful. However, they are not a strict requirement for this tutorial.
There's a few things to do before we dive into the tutorial itself. For example, to do Eclipse programming, you will have to get your hands on an Eclipse installation first. Read through the following sections to get ready for the tutorial tasks.
As you're going to develop for KIELER SCCharts we recommend to use the semantic Oomph setup as described in Getting Eclipse (Oomph Setup). However, you could also install all componentes by yourself. Please consult the other tutorials if you want to do that. You would need to install the Modeling Tools and the Xtext SDK.
Additionally, install the EcoreViz from the Ecore Model Visualization category from the OpenKieler update site: http://rtsys.informatik.uni-kiel.de/~kieler/updatesite/nightly-openkieler/. For this, choose Install New Software... in the Help tab.
We recommend that you have completed the following tutorials before diving into this one (or at least sweep over them). However, this is not a strict requirement.
When developing within the KIELER semantics team, you will most likely be confronted with Xtext and Lightweight Diagrams (KLighD). The following tutorials may be helpful but not required for this tutorial.
You can find additional documentation to the aforementioned topics in the corresponding tutorials. If you get stuck with a particular topic, please consult that tutorial. For SCCharts, you should read the SCCharts confluence page in our wiki: SCCharts
As usual, documentation often gets obsolete or wrong if not maintained regularly, so please, if you find missing, misleading, or outdated information, please let us know.
Additionally, the following list will give a short overview over the most important publications:
Navigate to the models folder of the plugin de.cau.cs.kieler.sccharts
. Here, open the sccharts.ecore
and right-click on the sccharts.ecore
file and select Visualize Ecore Model. Since you also installed EcoreViz from the OpenKieler Suite, you should now see a graphical representation of the SCCharts metamodel. Every SCChart will be a model of this metamodel.
IMAGE
Try to understand most parts of the metamodel. You don't have to understand every detail but you should get the idea.
We need a project for testing. Do the following:
To create a model programmatically you cannot directly use the Java classes generated for the model. Instead, the main package contains interfaces for all of your model object classes. The impl
package contains the actual implementation and the util
package contains some helper classes. Do not instantiate objects directly by manually calling new
. EMF generates a Factory to create new objects. The factory itself uses the singleton pattern to get access to it:
SCChartsFactory sccFactory = SCChartsFactory.eINSTANCE; State state = sccFactory .createState(); Transition transition = sccFactory .createTransition(); |
Important: The SCCharts grammar is build on top of several other grammars. Therefore, not all language objects can be found in the SCCharts factory. For example, all expression elements are part of the KExpressions grammar and hence, have their own factory. If you need other factories, don't forget to add the corresponding plugin to your plugin dependency list.
KExpressionsFactory kFactory = KExpressionsFactory.eINSTANCE; BooleanValue boolValue = kFactory.createBooleanValue(); |
For all simple attributes, there are getter and setter methods:
state.setId("Root"); boolValue.setValue(true); |
Simple references (multiplicity of 1) also have getters and setters:
transition.setTrigger(boolValue); |
List references (multiplicity of > 1) have only a list getter, which is used to manipulate the list:
state.outgoingTransitions.add(transition); |
EMF uses the Eclipse Resource concept to save models to files and load models from files. It can use different Resource Factories that determine how exactly models are serialized. We will use the XMIResourceFactoryImpl to save our models to XML files:
org.eclipse.emf.ecore.xmi
plug-in.Use something like the following code to save the model from above:
// Create a resource set. ResourceSet resourceSet = new ResourceSetImpl(); // Register the default resource factory -- only needed for stand-alone! // this tells EMF to use XML to save the model resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put( Resource.Factory.Registry.DEFAULT_EXTENSION, new SCTResourceFactoryImpl()); // Get the URI of the model file. URI fileURI = URI.createFileURI(new File("myABO.sct").getAbsolutePath()); // Create a resource for this file. Resource resource = resourceSet.createResource(fileURI); // Add the model objects to the contents. resource.getContents().add(myModel); // Save the contents of the resource to the file system. try { resource.save(Collections.EMPTY_MAP); // the map can pass special saving options to the operation } catch (IOException e) { /* error handling */ } |
With these information out of the way, on we go to some model creation:
main()
method.main()
method by right-clicking its class and selecting Run as -> Java Application. Note that this runs your main()
method as a simple Java program, not a complete Eclipse application. EMF models can be used in any simple Java context, not just in Eclipse applications.Transformations from one model to another may be performed within the same metamodel or from metamodel to a different metamodel. Both methods are used in KIELER and in principle they do not really differ in implementation. Nevertheless, if working within the same metamodel you should keep in mind that you're potentially changing the actual model instead of changing another instance (after copying). Both is possible. Just make sure that you know what you're doing.
Now, you're going to transform the normalized form of HandleA from ABO to an SCG. The Sequentially Constructive Graph is a control-flow graph which can be seen as another representation of the same program. The SCG of the normalized version of ABO's HandleA is depicted on the right.
|
The next figure depicts the direct mapping from normalized SCCharts to their corresponding SCG.
Inspect the metamodel of the SCGs in plugin de.cau.cs.kieler.scg. SCGs are used for analyses and optimization and include a lot of additional elements. However, for this tutorial it should be sufficient to look at the SCGraph class, its nodes attribute, the important node classes and the controlflow class. Important nodes for this SCG are entry, exit, assignment, conditional,
Write a transformation that transforms your normalized version of ABO's HandleA into its corresponding SCG.
Writing a Model Transformation
This time we want you to integrate your transformation into your SCCharts Editor instance. Therefore,...
<project>.transformations
to your project.org.eclipse.xtext.xbase.lib,
you can hover over the error with your mouse and have Eclipse add all libraries required by Xtend to your project.Define an entry method for the transformation that takes an SCChart program instance as an argument and returns an SCG Program
. You can use the following (incomplete) method as a starting point:
/** * Transforms a given SCCharts program into an SCG. * */ def SCGraph transform(State rootState) { // Create the SCG val scg = SCGraphFactory::eINSTANCE.createSCGraph() // TODO: Your transformation code // Return the transformed program scg } |
There's a few points to note here:
val
declares a constant, while var
declares a variable. Try to make do with constants where possible.def private
since they are implementation details and shouldn't be called by other classes.def create
methods might offer a better alternative...Congratulations! You finished the SCCharts Development Tutorial. Ask your supervisor for further instructions!