1@ 2#include "TrafficLight-sharedFunctions.cws" 3 4function generateJavaClass(strategy : node) { 5 @class @strategy.name@ extends TrafficLightStrategy { 6 public @strategy.name@() {} 7 8 public bool start() { 9 return @strategy.start@; 10 } 11 12 public int executeRules() { 13 int iTriggeredRules = 0; 14 if (bActive_) { 15@ 16 incrementIndentLevel(); 17 foreach i in strategy.rules { 18 @ if (executeRule@i.key()@()) ++iTriggeredRules; 19@ 20 } 21 @ } 22 return iTriggeredRules; 23} 24 25@ 26 27 foreach i in strategy.rules { 28 @private bool executeRule@i.key()@() { 29 if (@convertAntecedent2Cpp(i.condition)@ == false) { 30 return false; 31 } 32@ 33 foreach j in i.actions { 34 writeAction<j>(j, "Java"); 35 } 36 @ return true; 37} 38 39@ 40 } 41 decrementIndentLevel(); 42 @} 43 44@ 45} 46 47if getMarkupKey() == "strategies" { 48 // the current markup key is worth "strategies": 49 // generate the implementation of each strategy 50 // class, coming from ".tlc" files 51 foreach strategy in this.strategies { 52 generateJavaClass(strategy); 53 } 54} else if startString(getMarkupKey(), "DSL: ") { 55 // the current markup key embeds strategies written 56 // directly into the Java file 57 if subString(getMarkupKey(), 5) != "TrafficLight" { 58 error("only one DSL recognized for the moment: 'TrafficLight'!"); 59 } 60 61 // parsing of the strategies attached to the markup: the function 62 // 'getMarkupValue()' returns data embedded in the markup 63 local theParseTree; 64 parseStringAsBNF("TrafficLight.cwp", theParseTree, getMarkupValue()); 65 66 @*/ 67@ 68 foreach strategy in theParseTree.strategies { 69 generateJavaClass(strategy); 70 } 71 @/* 72@ 73}