added validation and document update
[des2015.git] / dsl / xtend / src / robots / missions / validation / TaskDSLValidator.xtend
1 /*
2 * generated by Xtext
3 */
4 package robots.missions.validation
5
6 import java.util.LinkedList
7 import java.util.List
8 import org.eclipse.xtext.validation.Check
9 import robots.missions.taskDSL.Action
10 import robots.missions.taskDSL.Behaviour
11 import robots.missions.taskDSL.Mission
12 import robots.missions.taskDSL.Robot
13
14 //import org.eclipse.xtext.validation.Check
15 /**
16 * This class contains custom validation rules.
17 *
18 * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation
19 */
20 class TaskDSLValidator extends AbstractTaskDSLValidator {
21 @Check
22 def checkRobot(Robot r){
23 if(r.acc == 0){
24 warning("Acceleration set to zero, this could lead to non moving robot", null);
25 }
26 if(r.spd == 0){
27 warning("Acceleration set to zero, this could lead to non moving robot", null);
28 }
29 }
30
31 @Check
32 def checkBehavioursl(Mission m) {
33 var List<String> empty = new LinkedList<String>();
34 var List<String> all = new LinkedList<String>();
35 var List<String> warned = new LinkedList<String>();
36 for(Behaviour b : m.behaviours){
37 if(b.tc == null){
38 empty.add(b.name);
39 }
40 if(all.contains(b.name) && !warned.contains(b.name)){
41 warning("Behaviour '" + b.name + "' multiple times in the behaviourlist.", null);
42 warned.add(b.name);
43 }
44 all.add(b.name);
45 }
46 if(empty.size() > 1){
47 warning("Multiple behaviours without takeControl predicate. You might want to remove some of: " + empty.toString(), null);
48 }
49 }
50
51 @Check
52 def checkActions(Action a) {
53 if(a.turnType != null && a.turnType.turnDir == null){
54 if(a.turnType.start == a.turnType.end){
55 error("Start and end cannot be the same", null);
56 } else if(a.turnType.start > a.turnType.end){
57 error("Start should be smaller then end", null);
58 }
59 }
60 }
61 }