DTU 
 

 

02265: Advanced Topics in Software Engineering (f15)

Assignment 5 (due wk 11)
 
 

In this assignment, you get some experience in implementing (actually slightly changing) a model-to-code transformation using Java Emitter Templates (JET), and the ways of working with and "debugging" JET templates. To this end, you will change a code generator of the ECNO project: the one which generates the behavior class from an ECNO net (ECNO_PN2J.jet). You will find this (and some other ECNO code generators) in the project dk.dtu.imm.se.ecno.model.generator. The task is to generate some additional code, which prints output to a console, whenever the condition of a transition is evaluated to false (when the ECNO Engine is computing possible interactions).

 

If you want, you can also install the "Java Emitter Templates (JET) SDK" from the Eclipse M2T update site: http://download.eclipse.org/modeling/m2t/updates/releases/ (do select all features from the category "M2T JET SDK 1.1.1" except for the "Jave Emitter Template (JET) All-In-One-Feature" and the "JET extensions for UML2 model traversal" feature). Using the JET SDK is not strictly necessary, but it makes the development of JET templates (and checking their correctness) a bit easier.

 

  1. You need to have installed the ECNO Tool as discussed in the Eclipse Installation instructions.

     

    In order to change the code generator later, you need to import the project dk.dtu.imm.se.ecno.model.generator as source project into your workspace (remember: open the Plug-Ins view, select the project, and chose "Import As" -> "Source Project").

     

  2. Have a look at the class ECNO_PN2JGenerator in package dk.dtu.imm.se.ecno.model.generator, which initiates the JET transformation and generates the Java code from an ECNO net — the actual transformation for each ECNO net being done in the generate() method.

     

    You will find the used skeletons and templates in the folder templates.

     

  3. As mentioned above, the you should extend the code generator so that it outputs a message to the console, whenever the ECNO Engine evaluates a condition of some transition of the ECNO to false, when the engine tries to compute valid interactions.

     

    Before you actually start changing the JET files, you should change one of the generated classes manually, so that the above behaviour is achieved. I suggest to use the workers example (from assignment 3) for this purpose; in this example, the job is the only local behaviour that has a condition. So in this example, go to class Job in package dk.dtu.imm.se.ecno.examples.workers.automata and change the evaluateCondition() method so that it outputs something like
      Condition j.newName.length() > 5 of transition t1 of net Job evaluated to false
    in case the condition evaluates to false (case 0 of the switch statement).

     

    Run an instance of this example in order to check wether the proper output shows at the console.

     

  4. Now look into the template ECNO_PN2J.jet and identify the spot where you need to generate the code for this addition automatically. Adjust the JET-templates so that the additional code would be generated automatically.

     

    You will probably not get this right in the first place. So, you need to test and adjust the JET template. To this end, you need to start the runtime workbench of your Eclipse; but you need to make sure that the project dk.dtu.imm.se.ecno.example.workers.worklistgui is NOT deployed to the runtime workbench. You can do that by selecting "Run Configurations" and deselecting (unchecking) this project from the PlugIns tab in this "Run configurations" dialog.

     

    To experiment with the dk.dtu.imm.se.ecno.example.workers.worklistgui in the runtime workbench, export it from the development workbench before you start the runtime workbench; and then import it to the Eclipse runtime workbench once you have started it.

     

    In the runtime workbench, generate the ECNO code by opening the file workers.ecnogen and right-clicking and selecting ECNO -> Generatre ECNO Packgage Code. If this results in an error right away, you probably forgot to uncheck the project dk.dtu.imm.se.ecno.example.workers.worklistgui in your "run configuration" before you started your runtime workbench.

     

    If it did not result in an error, have a look whether the code for class Job was generated properly. It is very unlikely that this works right away. If the file Job is completely empty, there is probably some syntax error in the JET templates. The easiest way to find out is by inspecting the project .JETEmitters. Since this project starts with a dot, it is normally not shown in the Eclipse project explorer. But you can change it by customizing the view of the project explorer. If the project explorer shows syntax errors in the project .JETEmitters, the JET templates have some syntax errors, which can be derived from the java errors shown in the .JETEmitters project.

     

    If there are no errors in the .JETEmitters, but errors in the generated code, you need to correct the JET templates so that the generated code is correct.

     

    You need to go back and forth adjusting the JET templates in the development workbench and test them in the runtime workbench by starting the ECNO generator again. But, you do not need to shut down and restart the runtime workbench after changing the JET templates. You can just start the ECNO generator again in the runtime workbench, after saving the changed templates in the development workbench (the templates are interpreted dynamically).

     

  5. Ultimately test, whether the final version of your adjusted JET templates work properly. It will be a good idea also to change the ECNO net for job to see whether the generation also works for different ECNO nets.

 

Ekkart Kindler (), Mar 3, 2015