Hide last authors
ssm 49.1 1 This is a light-weight tutorial for developing transformations/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.
ssm 1.1 2
cds 51.1 3 {{warning title="Outdated!"}}
4 The KiCo part "Model-to-Model Transformations with KiCo" is outdated. We will update this tutorials in the near future.
5 {{/warning}}
ssm 12.1 6
7
cds 51.1 8
9
ssm 12.1 10 {{toc/}}
11
ssm 1.1 12 = Preliminaries =
13
14 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.
15
16 == Required Software ==
17
ssm 25.1 18 As you're going to develop for KIELER SCCharts, we recommend to use the Oomph setup as described in [[doc:KIELER.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.
ssm 1.1 19
Alexander Schulz-Rosengarten 71.1 20
ssm 11.1 21
ssm 7.1 22 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/>>url:http://rtsys.informatik.uni-kiel.de/~~kieler/updatesite/nightly-openkieler/||rel="nofollow" shape="rect"]]. For this, choose //Install New Software...// in the //Help// tab.
ssm 8.1 23
24 Due to the ongoing migration you have to install a workaround for EcoreViz to function. You have to install the KLighD diagram view directly from [[http:~~/~~/rtsys.informatik.uni-kiel.de/~~~~kieler/updatesite/release_pragmatics_2016-02/>>url:http://rtsys.informatik.uni-kiel.de/~~kieler/updatesite/release_pragmatics_2016-02/||shape="rect"]]. Select the features
25
26 * KIELER Lightweight Diagrams - Developer Resources and
27 * KIELER Lightweight Diagrams Generic Diagram View.
28
29 (This step should be obsolete in the near future.)
ssm 1.1 30
ssm 11.1 31
ssm 7.1 32 [[image:attach:InstallEcoreViz.png]]
ssm 12.1 33
ssm 11.1 34
Niklas Rentz 72.1 35
ssm 8.1 36 [[image:attach:InstallKLighDFeatures.png]]
ssm 7.1 37
ssm 1.1 38 == Recommended Tutorials ==
39
40 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.
41
Alexander Schulz-Rosengarten 68.1 42 1. [[doc:KIELER.Development.Tutorials.Eclipse.Eclipse Plug-ins and Extension Points.WebHome]]
Alexander Schulz-Rosengarten 67.1 43 1. [[doc:KIELER.Development.Tutorials.Eclipse.Eclipse Modeling Framework (EMF).WebHome]]
ssm 1.1 44 11. This tutorial needs the turingmachine.ecore and the controller you've implemented in the EMF tutorial. If you did not complete the EMF tutorial, you may download a working turing machine here... (in the future).
45 1. (((
46 (% class="with-breadcrumbs" %)
47 [[Xtend 2 - Model Transformations>>url:http://rtsys.informatik.uni-kiel.de/confluence/display/TUT/Xtend+2+-+Model+Transformations||shape="rect"]]
48 )))
49
50 == Helpful Tutorials ==
51
52 When developing within the KIELER semantics team, you will most likely be confronted with Xtext and [[doc:KIELER.Lightweight Diagrams (KLighD)]]. The following tutorials may be helpful but not required for this tutorial.
53
Alexander Schulz-Rosengarten 70.1 54 1. [[doc:KIELER.Development.Tutorials.Xtext and Xtend.Xtext 2 - Creating a Grammar from Scratch.WebHome]]
Alexander Schulz-Rosengarten 66.1 55 1. [[doc:KIELER.Development.Tutorials.Diagrams and Layout.Lightweight Diagrams (KLighD).WebHome]]
ssm 1.1 56
57 == Finding Documentation ==
58
ssm 50.1 59 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: [[doc:KIELER.SCCharts (pre 1\.0)]]
ssm 1.1 60
61 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.
62
63 Additionally, the following list will give a short overview over the most important publications:
64
Richard Kreissig 73.1 65 * (% style="color:#000000" %)**Main paper:**(%%)
66 (% style="color:#000000" %)Reinhard von Hanxleden and Björn Duderstadt and Christian Motika and Steven Smyth and Michael Mendler and Joaquín Aguado and Stephen Mercer and Owen O’Brien. SCCharts: Sequentially Constructive Statecharts for Safety-Critical Applications. In (% class="cmti-10" %)Proc. ACM SIGPLAN Conference on Programming Language Design(%%) (% class="cmti-10" %)and Implementation (PLDI’14)(%%), Edinburgh, UK, June 2014. ACM. [[pdf>>url:http://rtsys.informatik.uni-kiel.de/~~biblio/downloads/papers/pldi14.pdf||shape="rect"]](% style="color:#000000" %), (%%)[[talk>>url:http://rtsys.informatik.uni-kiel.de/~~biblio/downloads/talks/pldi14-talk.pdf||shape="rect"]](% style="color:#000000" %), (%%)[[bib>>url:http://rtsys.informatik.uni-kiel.de/~~biblio/cgi-bin/bibcgi.cgi?key=vonHanxledenDM+14||shape="rect"]]
ssm 1.1 67 * **SLIC Compilation:**
Richard Kreissig 73.1 68 (% style="color:#000000" %)Christian Motika and Steven Smyth and Reinhard von Hanxleden. Compiling SCCharts—A Case-Study on Interactive Model-Based Compilation. In (% class="cmti-10" %)Proceedings of(%%) (% class="cmti-10" %)the 6th International Symposium on Leveraging Applications of Formal(%%) (% class="cmti-10" %)Methods, Verification and Validation (ISoLA 2014)(%%), volume 8802 of (% class="cmti-10" %)LNCS(%%), page 443–462, Corfu, Greece, October 2014. The [[original publication>>url:http://dx.doi.org/10.1007/978-3-662-45234-9||shape="rect"]](% style="color:#000000" %) is available at (%%)[[http:~~/~~/link.springer.com>>url:http://link.springer.com/||shape="rect"]](% style="color:#000000" %). (%%)[[pdf>>url:http://rtsys.informatik.uni-kiel.de/~~biblio/downloads/papers/isola14.pdf||shape="rect"]](% style="color:#000000" %), (%%)[[bib>>url:http://rtsys.informatik.uni-kiel.de/~~biblio/cgi-bin/bibcgi.cgi?key=MotikaSvH14||shape="rect"]]
ssm 1.1 69 * **Theoretical Foundations:**
Richard Kreissig 73.1 70 (% style="color:#000000" %)Reinhard von Hanxleden and Michael Mendler and Joaquín Aguado and Björn Duderstadt and Insa Fuhrmann and Christian Motika and Stephen Mercer and Owen O’Brien and Partha Roop. Sequentially Constructive Concurrency—A Conservative Extension of the Synchronous Model of Computation. (% class="cmti-10" %)ACM Transactions on Embedded Computing(%%) (% class="cmti-10" %)Systems, Special Issue on Applications of Concurrency to System Design(%%), 13(4s):144:1–144:26, July 2014. [[pdf>>url:http://rtsys.informatik.uni-kiel.de/~~biblio/downloads/papers/tecs14.pdf||shape="rect"]](% style="color:#000000" %), (%%)[[bib>>url:http://rtsys.informatik.uni-kiel.de/~~biblio/cgi-bin/bibcgi.cgi?key=vonHanxledenMA+14||shape="rect"]]
ssm 1.1 71 * **Overview and High-Level Transformations in Detail:**
Richard Kreissig 73.1 72 (% style="color:#000000" %)Reinhard von Hanxleden and Björn Duderstadt and Christian Motika and Steven Smyth and Michael Mendler and Joaquín Aguado and Stephen Mercer and Owen O’Brien. SCCharts: Sequentially Constructive Statecharts for Safety-Critical Applications. Technical Report 1311, Christian-Albrechts-Universität zu Kiel, Department of Computer Science, December 2013. ISSN 2192-6247.  (%%)[[pdf>>url:http://rtsys.informatik.uni-kiel.de/~~biblio/downloads/papers/report-1311.pdf||shape="rect"]](% style="color:#000000" %), (%%)[[bib>>url:http://rtsys.informatik.uni-kiel.de/~~biblio/cgi-bin/bibcgi.cgi?key=vonHanxledenDM+13b||shape="rect"]]
ssm 13.1 73
ssm 1.1 74 = The SCCharts Metamodel =
75
ssm 9.1 76 Navigate to the {{code language="none"}}models{{/code}} folder of the plugin {{code language="none"}}de.cau.cs.kieler.sccharts{{/code}}. Here, open the {{code language="none"}}sccharts.ecore{{/code}} and right-click on the {{code language="none"}}sccharts.ecore{{/code}} 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.
ssm 1.1 77
ssm 14.1 78 To see all class information check //Attributes/Literals// in the Diagram Options on the right.
79
ssm 15.1 80 EcoreViz gives you an overview over the selected Ecore diagram. However, Ecore model definitions may depend on other Ecore definitions that are not displayed in the diagram. You can open new diagrams for these Ecore files as described before or use the Ecore tree editor to inspect all classes.
81
ssm 1.1 82 Try to understand most parts of the metamodel. You don't have to understand every detail but you should get the idea.
83
84 ==== Model Task ====
85
ssm 48.1 86 * (((
Richard Kreissig 73.1 87 (% style="line-height:1.42857" %)Answer the following questions
ssm 4.1 88
ssm 25.1 89 1. How do you describe a superstate in the model?
Richard Kreissig 73.1 90 1. Outline the relationship between states, regions, transitions, and valued objects.
ssm 25.1 91 1. Name the class of the root element of an SCChart.
92 1. What is a valued object?
93 1. How do you get the type of an interface variable?
94 1. What other metamodels are needed for the SCCharts metamodel and write down which one is needed for what?
ssm 48.1 95 )))
96 * Write down (on paper, text editor, etc) how the following SCChart models look like
97 *1. Open the wiki page that explains the [[doc:KIELER.Textual SCCharts Language SCT]].
98 *1. Search the //SCChart, Initial State, State, Transition and Immediate Transition //example and ...
99 *11. write down (on paper or text editor, etc) how the model of that SCChart looks like.
100 *11. The user now marks C as final. What has to be changed in the model? What semantic problem do you see?
101 *1. Now, navigate to the //Super State: Strong Abort Transition //example. Write down (on paper) how the model of that SCCharts looks like.
102 *1. And finally a more sophisticated model: Write down the model of ABO (from [[doc:KIELER.Examples]]).
ssm 25.1 103
Richard Kreissig 74.1 104 {{info title="KLighD Screenshots"}}
ssm 17.1 105 By the way: You can //right-click// on the Diagram View surface and select //Save as image...// to create a screenshot!
ssm 9.1 106 {{/info}}
107
108 [[image:attach:sccharts_metamodel.png]]
109
ssm 15.1 110 [[image:attach:sccharts_metamodel_treeEditor.png]]
ssm 9.1 111
112 [[image:attach:KLighDSaveAsImage.png]]
113
Niklas Rentz 72.1 114 = Creating SCCharts Models Programmatically =
ssm 4.1 115
116 == Creating a Test Project ==
117
118 We need a project for testing. Do the following:
119
ssm 48.1 120 * If you used the standard KIELER Oomph installation setup, create a new Working Set named Tutorial in the Package Explorer. Then...
121 * Create a new empty //Plug-In Project//.
122 * Add the project that contains the sccharts metamodel as a dependency of your new project through the //Plugin Manifest Editor//.
123 * Create a simple Java class that implements a main method. Hint: In a new Java class, simply type main and hit Ctrl+Space. Eclipse content assist will create the method for you.
ssm 4.1 124
125 == Creating a Model ==
126
ssm 18.1 127 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 {{code language="none"}}impl{{/code}} package contains the actual implementation and the {{code language="none"}}util{{/code}} package contains some helper classes. Do not instantiate objects directly by manually calling {{code language="none"}}new{{/code}}. EMF generates a Factory to create new objects. The factory itself uses the singleton pattern to get access to it:
ssm 4.1 128
129 {{code language="java"}}
130 SCChartsFactory sccFactory = SCChartsFactory.eINSTANCE;
ssm 19.1 131 State state = sccFactory.createState();
132 Transition transition = sccFactory.createTransition();
ssm 4.1 133 {{/code}}
134
135 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.
136
137 {{code language="java"}}
138 KExpressionsFactory kFactory = KExpressionsFactory.eINSTANCE;
ssm 18.1 139 BoolValue boolValue = kFactory.createBoolValue();
ssm 4.1 140 {{/code}}
141
142 For all simple attributes, there are getter and setter methods:
143
144 {{code language="java"}}
ssm 19.1 145 state.setId("Init");
ssm 4.1 146 boolValue.setValue(true);
147 {{/code}}
148
149 Simple references (multiplicity of 1) also have getters and setters:
150
151 {{code language="java"}}
152 transition.setTrigger(boolValue);
153 {{/code}}
154
155 List references (multiplicity of > 1) have only a list getter, which is used to manipulate the list:
156
157 {{code language="java"}}
ssm 18.1 158 state.getOutgoingTransitions().add(transition);
ssm 4.1 159 {{/code}}
160
ssm 18.1 161 {{info title="Plugin Dependencies"}}
162 You may have noticed that is was not necessary to add a dependency for the kexpressions classes. The SCCharts plugin reexports the dependencies of the other EMF metamodels. Look at the plugin.xml in the SCCharts plugin in the dependency tab for more information.
163 {{/info}}
164
ssm 4.1 165 == Saving a Model ==
166
167 EMF uses the [[Eclipse Resource concept>>url:http://help.eclipse.org/juno/topic/org.eclipse.platform.doc.isv/guide/resInt.htm?cp=2_0_10||rel="nofollow" shape="rect" class="external-link"]] 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>>url:http://download.eclipse.org/modeling/emf/emf/javadoc/2.8.0/org/eclipse/emf/ecore/xmi/impl/XMIResourceFactoryImpl.html||rel="nofollow" shape="rect" class="external-link"]] to save our models to XML files:
168
ssm 48.1 169 * (((
ssm 19.1 170 Add a dependency to the {{code language="none"}}com.google.inject, org.eclipse.core.resources, {{/code}}and{{code language="none"}} de.cau.cs.kieler.sccharts.text{{/code}} plug-ins.
171
172 {{info title="Additional Dependencies"}}
173 Don't worry. You will be experienced enough to add mandatory dependencies quickly in the future. However, for now just add the dependencies to proceed with the tutorial.
174 {{/info}}
175 )))
ssm 48.1 176 * (((
ssm 4.1 177 Use something like the following code to save the model from above:
178
179 {{code language="java"}}
180 // Create a resource set.
181 ResourceSet resourceSet = new ResourceSetImpl();
182
ssm 19.1 183 // Register the resource factory -- only needed for stand-alone!
184 SctStandaloneSetup.doSetup();
185
186  
ssm 4.1 187 // Get the URI of the model file.
188 URI fileURI = URI.createFileURI(new File("myABO.sct").getAbsolutePath());
189
190 // Create a resource for this file.
191 Resource resource = resourceSet.createResource(fileURI);
192
ssm 50.1 193 // Add the model objects to the contents. Usually, this is the root node of the model.
ssm 4.1 194 resource.getContents().add(myModel);
195
196 // Save the contents of the resource to the file system.
197 try
198 {
199 resource.save(Collections.EMPTY_MAP); // the map can pass special saving options to the operation
200 } catch (IOException e) {
201 /* error handling */
202 }
203 {{/code}}
ssm 20.1 204
205 {{info title="File Extensions"}}
206 File extensions are important! They define the parser/serializer that EMF uses. Always use the file extension that is defined for a particular model.
207 {{/info}}
ssm 4.1 208 )))
209
210 ==== Model Creation Task ====
211
ssm 19.1 212 You are now equipped with the fundamentals you need to create models programmatically. Let's try it:
ssm 4.1 213
Richard Kreissig 73.1 214 * (% style="line-height:1.42857" %)The code fragments listed above do not suffice to create a grammatically correct model. Try to generate a model that corresponds with the serialized model listed on the right side.
215 *1. (% style="line-height:1.42857" %)Run the {{code language="none"}}main(){{/code}} method by right-clicking its class and selecting //Run as// -> //Java Application//. Note that this runs your {{code language="none"}}main(){{/code}} 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.
ssm 48.1 216 *1. Execute the main method.
217 *1. (((
Richard Kreissig 73.1 218 (% style="line-height:1.42857" %)Inspect your SCT file. (Press F5 to refresh your file view.)
ssm 25.1 219
Richard Kreissig 73.1 220 {{info title="Kext Warning"}}
ssm 20.1 221 It is possible that kext generates a Null Pointer Exception when you save your model this way. This is a known issue. We're working on it. Just ignore it for now.
Richard Kreissig 73.1 222 {{/info}}
ssm 20.1 223 )))
ssm 48.1 224 * Now, create a new Java class and proceed as before to generate a model of ABO in the {{code language="none"}}main(){{/code}} method.
Richard Kreissig 73.1 225 * (% style="line-height:1.42857" %)Start your SCChart Editor Eclipse instance and load your SCT file. KLighD should now be able to visualize your ABO correctly.
ssm 48.1 226 *1. For this, open tab //Run// and select// Run Configurations...//
227 *1. Create a new //Eclipse Application// and name it appropriately.
228 *1. As product select {{code language="none"}}de.cau.cs.kieler.core.product.product{{/code}}.
229 *1. Click //Run// (or //Debug// if you opened// Debug Configuration...//)
230 *1. Create a new project and add you generated model.
ssm 19.1 231
Richard Kreissig 74.1 232 {{code language="java" title="Root.sct"}}
ssm 19.1 233 scchart Root {
234 initial state Init
235 --> Init with true;
236 }
237 {{/code}}
ssm 20.1 238
239 [[image:attach:RunConfiguration.png]]
ssm 4.1 240
ssm 22.1 241 = Model-to-Model Transformations with KiCo =
ssm 20.1 242
ssm 24.1 243 You can use the [[Kieler Compiler>>url:http://rtsys.informatik.uni-kiel.de/confluence/display/KIELER/Kieler+Compiler||shape="rect"]] (KiCo) to handle all the model input/output tasks and concentrate on the actual transformation. If you executed the **Model Creation Task correctly**, you should now have a complete running SCT Editor instance that looks like the one on the right. You should see the //KIELER Compiler Selection// n the lower right part of the working space. Here you can select specific transformations that will be applied to the actual model. Simply select a transformation to test it.
ssm 20.1 244
245 == Creating a new Transformation ==
246
ssm 24.1 247 Now, you're going to write your own transformation with **Xtend** *drumroll*, a programming language that looks very similar to Java, but which adds some very convenient features. Xtend code compiles to Java and and was developed using Xtext. In fact, once you gain experience working with Xtend you will probably appreciate the power of Xtext even more. Xtend is particularly useful to browse & modify EMF models. You get the point... we like it. :)
ssm 20.1 248
ssm 25.1 249 [[image:attach:KielerSCTEditor.png]]
ssm 20.1 250
ssm 22.1 251 ==== Transformation Creation Task ====
ssm 20.1 252
ssm 48.1 253 * Create your first transformation...
254 *1. Create a new project within your tutorial working set as before.
255 *1. Add plugin dependencies to {{code language="none"}}de.cau.cs.kieler.kico{{/code}} and {{code language="none"}}de.cau.cs.kieler.sccharts{{/code}}.
256 *1. Create a new //Xtend class// in you package and name it "DoubleStates" and use {{code language="none"}}AbstractProductionTransformation{{/code}} as superclass.
257 *1. Here, you can automatically add the missing Xtend files by using the quickfix //Add Xtend lib to class path. //Alternatively you can simply add {{code language="none"}}com.google.guava{{/code}}, {{code language="none"}}org.eclipse.xtext.xbase.lib{{/code}}, {{code language="none"}}org.eclipse.xtend.lib{{/code}}, and {{code language="none"}}org.eclipse.xtend.lib.macro{{/code}} to you plugin dependencies.
258 *1. Click on //Add unimplemented methods//.
259 *1. (((
ssm 20.1 260 Now, you should have a class similar to the following one.
261
262 {{code language="java"}}
263 package tutorial.transformation
264
265 import de.cau.cs.kieler.kico.transformation.AbstractProductionTransformation
266
267 class DoubleStates extends AbstractProductionTransformation {
268
269 override getProducedFeatureId() {
270 throw new UnsupportedOperationException("TODO: auto-generated method stub")
271 }
272
273 override getId() {
274 throw new UnsupportedOperationException("TODO: auto-generated method stub")
275 }
276
277 }
278 {{/code}}
ssm 22.1 279
280 {{info title="Xtend Infos"}}
281 * Lines in Xtend code don't have to and with a semicolon.
282 * We have been explicit about the method's return type, but we could have easily omitted it, letting Xtend infer the return type.
283 * The keyword {{code language="none"}}val{{/code}} declares a constant, while {{code language="none"}}var{{/code}} declares a variable. Try to make do with constants where possible.
284 * The methods you call should be declared as {{code language="none"}}def private{{/code}} since they are implementation details and shouldn't be called by other classes.
285 * You may be tempted to add a few global variables that hold things like a global input variable or a pointer to the current state. While you could to that, {{code language="none"}}def create {{/code}}methods might offer a better alternative...
286 {{/info}}
ssm 20.1 287 )))
ssm 48.1 288 * (((
ssm 25.1 289 As you can see, it is mandatory to add an id for the transformation and another id of the feature that this transformation produces. Name your transformation **tutorial.doubleStates **and the id of feature you want to produce is **sccharts.doubleStates**.
290
ssm 20.1 291 {{info title="Programming Guidelines"}}
292 You should really think about some constants here. You can also look at the sccharts transformation and features constants in the sccharts plugin.
293 {{/info}}
ssm 48.1 294 )))
ssm 25.1 295
ssm 48.1 296 * KiCo must know about the new feature and also about your new transformation. 
297 *1. Add a new Xtend class with Feature as superclass. Add all unimplemented methods. Also set** sccharts.doubleStates** as Id.
298 *1. Go to the Extension tab inside your plugin configuration. 
299 *11. Add a new Extension Point de.cau.cs.kieler.kico.feature. Create a new featureClass and point it to your new feature class.
300 *11. Also add a new Extension Point de.cau.cs.kieler.kico.transformation. Create a new productionTransformationClass and point it to your transformation class.
301 *11. Finally, you have to link your transformation to the SCT Editor. Add the Extension point de.cau.cs.kieler.kico.ui.transformation. Create an editor link and fill in the following values:
302 *111. editor: {{code language="none"}}de.cau.cs.kieler.sccharts.text.sct.Sct{{/code}}
303 *111. features: sccharts.doubleStates
304 *111. label: Tutorial Compilation
305 *111. priority: 101
306 *111. preferred: (leave it blank)
Richard Kreissig 74.1 307 *1. {{info title="Plugin Tasks"}}In general it is bad to mix non-ui plugins/tasks with ui plugin/tasks because (in the context of KiCo) even if you're not working with an active UI your transformations should work (e.g. a command line compiler). To keep this tutorial simple, you can add this dependency to your plugin nevertheless. However, you shouldn't do this in real products. Always keep the UI separated.{{/info}}If you start your KIELER instance now, you should get a new compilation chain which has only one transformation: yours, which doesn't do anything.
ssm 48.1 308 * If you want to rename your feature in the Compiler Selection (without changing its Id), override the {{code language="none"}}getName{{/code}} method and return a new name. Rename your feature appropriately.
ssm 25.1 309
310 [[image:attach:KielerSCTEditorOwnTransformation.png]]
311
ssm 48.1 312 * Now, fill your transformation with life:
313 *1. Inside your transformation class, add a new method with the following signature: {{code language="none"}}def State transform(State rootState, KielerCompilerContext context){{/code}}. This transformation will be executed if the feature is selected in the Compiler Selection.
314 *1. (((
ssm 22.1 315 Add thew following body to the function and try to understand the Xtend code. Import unknown class via code assist.
ssm 20.1 316
ssm 21.1 317 {{code language="java" title="transform"}}
318 def State transform(State rootState, KielerCompilerContext context) {
319 val newState = SCChartsFactory.eINSTANCE.createState => [
320 id = "ololo"
321 label = "ololo"
322 ]
323
324 rootState.regions.filter(ControlflowRegion).head.states += newState
325
326 rootState
327 }
328 {{/code}}
329 )))
ssm 48.1 330 *1. When selecting your transformation, the SCChart gets transformed and looks like the version on the right.
331 * Extend the transformation so that the transition is split up in two and connected via a transient state meaning that the original transformation should point to the new state and a new immediate transformation then points to the original target state. Try it out.
332 * (((
ssm 25.1 333 Xtend supports extensions that can be used to extend the function set of you classes (i.e. models). Add {{code language="none"}}com.google.inject{{/code}} to the dependencies of your plugin. Now, add the following code fragment to the beginning of your class.
334
ssm 22.1 335 {{code language="java" title="Code injection"}}
336 @Inject
337 extension SCChartsExtension
338 {{/code}}
339
ssm 25.1 340 There are several Extensions classes within the KIELER project that extend the functionality of various classes. Basically, there are one or more for each metamodel (e.g. SCCharts, SCG, KExpressions, etc). You don't want to invent the wheel again. Use these methods. For example: there is a method that gives you all contained states of a state in a list: {{code language="none"}}getAllContainedStatesList{{/code}}. You can use it on your {{code language="none"}}rootState{{/code}}: {{code language="none"}}rootState.allContainedStatesList{{/code}}. There are also several convenient methods for creating model elements so that you don't have to use the factories directly.
ssm 22.1 341
Richard Kreissig 75.1 342 {{info title="Extensions Naming Scheme"}}
ssm 22.1 343 Extensions are also just classes. You can add your own to improve the structure of your own projects. In KIELER all extensions end with "Extensions"; except SCChartsExtension for legacy reasons. This will be renamed in after the next snapshot to SCChartsExtensions. So, if you're going to add new extensions to the project, please name them accordingly.
Richard Kreissig 75.1 344 {{/info}}
ssm 48.1 345 )))
ssm 22.1 346
ssm 25.1 347 [[image:attach:KielerSCTEditorOwnTransformationOlolo.png]]
348
Alexander Schulz-Rosengarten 71.1 349
350
ssm 48.1 351 * Extend your transformation so that it is applied on all states (except the root state). Try your new transformation with ABO. The result should look like the example on the right.
ssm 25.1 352
ssm 22.1 353 == The existing Compilation Chain ==
354
355 Congratulations. You added and executed your own KiCo transformation. Nevertheless, often you want to extend the existing compilation chain. To do this, you proceed as before but instead of creating your own compilation chain, you must modify the existing chains (e.g. the netlist compilation in de.cau.cs.kieler.sccharts.ui). To add a specific transformation at a specific point in the chain, you must tell KiCo what features are required for the transformation. For that you must override the method getRequiredFeatureIds and return a set with all required features.
356
357 Also, if you're developing for the master chain, you should obey the package structure. Look at the sccharts plugins. All features, transformation, extensions, the metamodel, ui elements, etc are separated from each other. You should always do the same!
358
359 //We will add more content to this subsection in the future...//
360
ssm 19.1 361
ssm 25.1 362 [[image:attach:ABODoubleStates.png]]
ssm 20.1 363
ssm 22.1 364
365
366 = Model-to-Model Transformations between Metamodels =
ssm 4.1 367
ssm 22.1 368 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). When transforming to another metamodel, you're always generating a new model. So there is no in-place transformation. Both is possible. Just make sure that you know what you're doing.
ssm 4.1 369
370 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.
371
cds 51.1 372 (% class="wrapped" %)
ssm 4.1 373 |(((
cds 51.1 374 (% class="content-wrapper" %)
375 (((
ssm 4.1 376 {{code}}
377 scchart ABO_norm_HandleA {
378 input output bool A;
379 input output bool B;
380 output bool O1;
381 output bool O2;
382 region HandleA:
383 initial state WaitA
384 --> _S immediate with A
385 --> _Pause immediate;
386 final state DoneA;
387 state _S
388 --> _S2 immediate with / B = true;
389 state _S2
390 --> DoneA immediate with / O1 = true;
391 state _Pause
392 --> _Depth;
393 state _Depth
394 --> _S immediate with A
395 --> _Pause immediate;
396 }
397 {{/code}}
cds 51.1 398 )))
ssm 4.1 399 )))|(((
cds 51.1 400 (% class="content-wrapper" %)
401 (((
ssm 4.1 402 [[image:attach:abo_norm_HandleA.png]]
cds 51.1 403 )))
ssm 4.1 404 )))|(% colspan="1" %)(% colspan="1" %)
405 (((
cds 51.1 406 (% class="content-wrapper" %)
407 (((
ssm 4.1 408 [[image:attach:abo_scg_HandleA.png]]
409 )))
cds 51.1 410 )))
ssm 4.1 411
412 The next figure depicts the direct mapping from normalized SCCharts to their corresponding SCG.
413
ssm 22.1 414 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,
415
ssm 4.1 416 [[image:attach:sccharts-scg.png]]
417
ssm 22.1 418 ==== Transformation Creation Task 2 ====
ssm 4.1 419
420 Write a transformation that transforms your normalized version of ABO's HandleA into its corresponding SCG.
421
ssm 48.1 422 * Proceed as before. Create a new plugin (or copy your last one) Make sure, you also add de.cau.cs.kieler.scg to your dependencies.
423 * Write a transformation that is able to transform {{code language="none"}}ABO_norm_HandleA{{/code}} into its corresponding SCG.
424 * **Verify your generated SCG**. If you added your transformation correctly, the SCG should be displayed automatically as soon as selected. If your SCG looks like the SCG depicted earlier, then everything is fine.
425 * Check your SCG semantically. Is there anything you could improve/optimize? 
426 *1. Write a second transformation (just as before) and add it to the transformation chain right after the transformation you already added.
427 *1. Optimize the given SCG and compare the result with the previous one.
428 *1. Make sure that the two SCGs are still semantically identical.
ssm 4.1 429
430 Congratulations! You finished the SCCharts Development Tutorial. Ask your supervisor for further instructions!