Browse Source

Enhanced the validation rules that only the defect elements are highlighted (YAKHMI-256)

markus.muehlbrandt@itemis.de 13 years ago
parent
commit
8af85eaeb9

+ 1 - 19
Examples/org.yakindu.sct.generator.java.trafficlight/src/org/yakindu/sct/examples/java/trafficlight/CrossingDemo.java

@@ -102,7 +102,6 @@ public class CrossingDemo {
 				display.sleep();
 			}
 		}
-		System.out.println("Shell disposed...");
 		thread.interrupt();
 	}
 
@@ -142,7 +141,7 @@ public class CrossingDemo {
 				public void handleEvent(
 						final org.eclipse.swt.widgets.Event event) {
 
-					// Shorter call for code commentet out below
+					// Shorter call for code commented out below
 					try {
 						Class<?> interfaceClass = statemachine
 								.getInterfaceDefault().getClass();
@@ -164,22 +163,5 @@ public class CrossingDemo {
 				}
 			});
 		}
-		// button[1].addListener(SWT.Selection, new Listener() {
-		// public void handleEvent(final org.eclipse.swt.widgets.Event event) {
-		// statechart.getInterfaceDefault().raiseKeypress1();
-		// }
-		// });
-		//
-		// button[2].addListener(SWT.Selection, new Listener() {
-		// public void handleEvent(final org.eclipse.swt.widgets.Event event) {
-		// statechart.getInterfaceDefault().raiseKeypress2();
-		// }
-		// });
-		//
-		// button[3].addListener(SWT.Selection, new Listener() {
-		// public void handleEvent(final org.eclipse.swt.widgets.Event event) {
-		// statechart.getInterfaceDefault().raiseKeypress3();
-		// }
-		// });
 	}
 }

+ 32 - 39
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/validation/STextJavaValidator.java

@@ -17,8 +17,7 @@ import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.resource.Resource;
 import org.eclipse.xtext.validation.Check;
 import org.eclipse.xtext.validation.CheckType;
-import org.yakindu.sct.model.sgraph.Declaration;
-import org.yakindu.sct.model.sgraph.Event;
+import org.eclipse.xtext.validation.ValidationMessageAcceptor;
 import org.yakindu.sct.model.sgraph.SGraphPackage;
 import org.yakindu.sct.model.stext.stext.AlwaysEvent;
 import org.yakindu.sct.model.stext.stext.Direction;
@@ -35,6 +34,7 @@ import org.yakindu.sct.model.stext.stext.ReactionTrigger;
 import org.yakindu.sct.model.stext.stext.SimpleScope;
 import org.yakindu.sct.model.stext.stext.StatechartDefinition;
 import org.yakindu.sct.model.stext.stext.StextPackage;
+import org.yakindu.sct.model.stext.stext.VariableDefinition;
 
 import de.itemis.xtext.utils.gmf.resource.InjectMembersResource;
 
@@ -60,13 +60,6 @@ public class STextJavaValidator extends AbstractSTextJavaValidator {
 				error("entry, exit, oncycle and always events are allowed as local reactions only.",
 						StextPackage.Literals.REACTION_TRIGGER__TRIGGERS);
 			}
-			// Context Transitions
-			// if (reactionTrigger.eContainer() instanceof TransitionReaction) {
-			// if (eventSpec instanceof RegularEventSpec) {
-			// error("Regular event specs are not allowed for transitions.",
-			// StextPackage.Literals.REACTION_TRIGGER__TRIGGERS);
-			// }
-			// }
 
 			// Context StatechartDefiniton
 			if (isStatechartDefinitionChild(reactionTrigger)) {
@@ -82,44 +75,44 @@ public class STextJavaValidator extends AbstractSTextJavaValidator {
 	}
 
 	@Check(CheckType.FAST)
-	public void checkSimpleScope(SimpleScope simpleScope) {
-		// Context State
-		if (simpleScope.getVariables().size() > 0) {
-			error("Variables can not be defined in states.",
-					SGraphPackage.Literals.SCOPE__VARIABLES);
-		}
-		
-		for (Declaration declaration: simpleScope.getDeclarations()) {
-			if (declaration instanceof Operation) {
-				error("Operations can not be defined in states.",
-						SGraphPackage.Literals.SCOPE__DECLARATIONS);
-			}
+	public void checkVariable(VariableDefinition variable) {
+		if (variable.eContainer() instanceof SimpleScope) {
+			error("Variables can not be defined in states.", variable,
+					SGraphPackage.Literals.NAMED_ELEMENT__NAME,
+					ValidationMessageAcceptor.INSIGNIFICANT_INDEX);
 		}
 	}
 
 	@Check(CheckType.FAST)
-	public void checkInterfaceScope(InterfaceScope interfaceScope) {
-		for (Declaration declaration : interfaceScope.getDeclarations()) {
-			if (declaration instanceof LocalReaction) {
-				error("Local reactions are not allowed in interface scope.",
-						SGraphPackage.Literals.SCOPE__DECLARATIONS);
-			}
+	public void checkEventDefinition(EventDefinition event) {
+		if (event.eContainer() instanceof InterfaceScope
+				&& event.getDirection() == Direction.LOCAL) {
+			error("Local declarations are not allowed in interface scope.",
+					StextPackage.Literals.EVENT_DEFINITION__DIRECTION);
 		}
-		for (Event event : interfaceScope.getEvents()) {
-			if (event instanceof EventDefinition && ((EventDefinition)event).getDirection() == Direction.LOCAL) {
-				error("Local declarations are not allowed in interface scope.",
-						SGraphPackage.Literals.SCOPE__EVENTS);
-			}
+		if (event.eContainer() instanceof InternalScope
+				&& event.getDirection() != Direction.LOCAL) {
+			error("In/Out declarations are not allowed in internal scope.",
+					StextPackage.Literals.EVENT_DEFINITION__DIRECTION);
 		}
 	}
-
+	
 	@Check(CheckType.FAST)
-	public void checkInternalScope(InternalScope internalScope) {
-		for (Event event : internalScope.getEvents()) {
-			if (event instanceof EventDefinition && ((EventDefinition)event).getDirection() != Direction.LOCAL) {
-				error("In/Out declarations are not allowed in internal scope.",
-						SGraphPackage.Literals.SCOPE__EVENTS);
-			}
+	public void checkOperation(Operation operation) {
+		if (operation.eContainer() instanceof SimpleScope) {
+			error("Operations can not be defined in states.", operation,
+					StextPackage.Literals.OPERATION__PARAM_TYPES,
+					ValidationMessageAcceptor.INSIGNIFICANT_INDEX);
+		}
+	}
+	
+	@Check(CheckType.FAST)
+	public void checkLocalReaction(LocalReaction localReaction) {
+		if (localReaction.eContainer() instanceof InterfaceScope) {
+			error("Local reactions are not allowed in interface scope.",
+					localReaction,
+					StextPackage.Literals.LOCAL_REACTION__PROPERTIES,
+					ValidationMessageAcceptor.INSIGNIFICANT_INDEX);
 		}
 	}