removed LCD class
[des2015.git] / dsl / xtend / src / robots / missions / validation / TaskDSLValidator.xtend
index 67fdc6e..e9f20fb 100644 (file)
@@ -3,23 +3,59 @@
  */
 package robots.missions.validation
 
-//import org.eclipse.xtext.validation.Check
+import java.util.LinkedList
+import java.util.List
+import org.eclipse.xtext.validation.Check
+import robots.missions.taskDSL.Action
+import robots.missions.taskDSL.Behaviour
+import robots.missions.taskDSL.Mission
+import robots.missions.taskDSL.Robot
 
+//import org.eclipse.xtext.validation.Check
 /**
  * This class contains custom validation rules. 
- *
+ * 
  * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation
  */
 class TaskDSLValidator extends AbstractTaskDSLValidator {
+       @Check
+       def checkRobot(Robot r){
+               if(r.acc == 0){
+                       warning("Acceleration set to zero, this could lead to non moving robot", null);
+               }
+               if(r.spd == 0){
+                       warning("Acceleration set to zero, this could lead to non moving robot", null);
+               }
+       }
+       
+       @Check
+       def checkBehavioursl(Mission m) {
+               var List<String> empty = new LinkedList<String>();
+               var List<String> all = new LinkedList<String>();
+               var List<String> warned = new LinkedList<String>();
+               for(Behaviour b : m.behaviours){
+                       if(b.tc == null){
+                               empty.add(b.name);
+                       }
+                       if(all.contains(b.name) && !warned.contains(b.name)){
+                               warning("Behaviour '" + b.name + "' multiple times in the behaviourlist.", null);
+                               warned.add(b.name);
+                       }
+                       all.add(b.name);
+               }
+               if(empty.size() > 1){
+                               warning("Multiple behaviours without takeControl predicate. You might want to remove some of: " + empty.toString(), null);
+               }
+       }
 
-//  public static val INVALID_NAME = 'invalidName'
-//
-//     @Check
-//     def checkGreetingStartsWithCapital(Greeting greeting) {
-//             if (!Character.isUpperCase(greeting.name.charAt(0))) {
-//                     warning('Name should start with a capital', 
-//                                     MyDslPackage.Literals.GREETING__NAME,
-//                                     INVALID_NAME)
-//             }
-//     }
+       @Check
+       def checkActions(Action a) {
+               if(a.turnType != null && a.turnType.turnDir == null){
+                       if(a.turnType.start == a.turnType.end){
+                               error("Start and end cannot be the same", null);
+                       } else if(a.turnType.start > a.turnType.end){
+                               error("Start should be smaller then end", null);
+                       }
+               }
+       }
 }