Преглед изворни кода

Issue 71: added check: reference before defined

Andreas Mülder пре 10 година
родитељ
комит
004a270fa0

+ 154 - 214
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/validation/STextJavaValidator.java

@@ -15,6 +15,7 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.eclipse.emf.common.util.EList;
 import org.eclipse.emf.common.util.TreeIterator;
@@ -28,6 +29,7 @@ import org.eclipse.xtext.Constants;
 import org.eclipse.xtext.EcoreUtil2;
 import org.eclipse.xtext.Keyword;
 import org.eclipse.xtext.naming.IQualifiedNameProvider;
+import org.eclipse.xtext.naming.QualifiedName;
 import org.eclipse.xtext.nodemodel.ICompositeNode;
 import org.eclipse.xtext.nodemodel.INode;
 import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
@@ -56,6 +58,7 @@ import org.yakindu.base.types.Parameter;
 import org.yakindu.base.types.Property;
 import org.yakindu.base.types.TypesPackage;
 import org.yakindu.sct.model.sgraph.Choice;
+import org.yakindu.sct.model.sgraph.Declaration;
 import org.yakindu.sct.model.sgraph.Entry;
 import org.yakindu.sct.model.sgraph.Exit;
 import org.yakindu.sct.model.sgraph.ReactionProperty;
@@ -96,6 +99,7 @@ import org.yakindu.sct.model.stext.types.ISTextTypeInferrer;
 import com.google.common.base.Predicate;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
 import com.google.inject.Inject;
 import com.google.inject.name.Named;
 
@@ -108,10 +112,8 @@ import de.itemis.xtext.utils.jface.viewers.ContextElementAdapter;
  * @auhor muelder
  * 
  */
-@ComposedChecks(validators = { SGraphJavaValidator.class,
-		SCTResourceValidator.class, ExpressionsJavaValidator.class })
-public class STextJavaValidator extends AbstractSTextJavaValidator implements
-		STextValidationMessages {
+@ComposedChecks(validators = { SGraphJavaValidator.class, SCTResourceValidator.class, ExpressionsJavaValidator.class })
+public class STextJavaValidator extends AbstractSTextJavaValidator implements STextValidationMessages {
 
 	@Inject
 	private ISTextTypeInferrer typeInferrer;
@@ -131,14 +133,12 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 
 	@Check(CheckType.FAST)
 	public void transitionsWithNoTrigger(Transition trans) {
-		if (trans.getSource() instanceof Entry
-				|| trans.getSource() instanceof Choice
+		if (trans.getSource() instanceof Entry || trans.getSource() instanceof Choice
 				|| trans.getSource() instanceof Synchronization) {
 			return;
 		}
 		if (trans.getSource() instanceof org.yakindu.sct.model.sgraph.State) {
-			org.yakindu.sct.model.sgraph.State state = (org.yakindu.sct.model.sgraph.State) trans
-					.getSource();
+			org.yakindu.sct.model.sgraph.State state = (org.yakindu.sct.model.sgraph.State) trans.getSource();
 			if (state.isComposite()) {
 				for (Region r : state.getRegions()) {
 					for (Vertex v : r.getVertices()) {
@@ -150,8 +150,7 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 			}
 		}
 
-		if (!STextValidationModelUtils.getExitPointSpecs(trans.getProperties())
-				.isEmpty()) {
+		if (!STextValidationModelUtils.getExitPointSpecs(trans.getProperties()).isEmpty()) {
 			return;
 		}
 
@@ -164,21 +163,17 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 	public void checkUnusedEntry(final Entry entry) {
 		if (entry.getParentRegion().getComposite() instanceof org.yakindu.sct.model.sgraph.State
 				&& entry.getIncomingTransitions().isEmpty()) {
-			org.yakindu.sct.model.sgraph.State state = (org.yakindu.sct.model.sgraph.State) entry
-					.getParentRegion().getComposite();
+			org.yakindu.sct.model.sgraph.State state = (org.yakindu.sct.model.sgraph.State) entry.getParentRegion()
+					.getComposite();
 			if (!STextValidationModelUtils.isDefault(entry)) {
 				boolean hasIncomingTransition = false;
-				Iterator<Transition> transitionIt = state
-						.getIncomingTransitions().iterator();
+				Iterator<Transition> transitionIt = state.getIncomingTransitions().iterator();
 				while (transitionIt.hasNext() && !hasIncomingTransition) {
-					Iterator<ReactionProperty> propertyIt = transitionIt.next()
-							.getProperties().iterator();
+					Iterator<ReactionProperty> propertyIt = transitionIt.next().getProperties().iterator();
 					while (propertyIt.hasNext() && !hasIncomingTransition) {
 						ReactionProperty property = propertyIt.next();
 						if (property instanceof EntryPointSpec) {
-							hasIncomingTransition = entry.getName()
-									.equals(((EntryPointSpec) property)
-											.getEntrypoint());
+							hasIncomingTransition = entry.getName().equals(((EntryPointSpec) property).getEntrypoint());
 						}
 					}
 				}
@@ -194,23 +189,17 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 		Expression varRef = expression.getVarRef();
 		if (varRef instanceof FeatureCall) {
 			EObject referencedObject = ((FeatureCall) varRef).getFeature();
-			if (!(referencedObject instanceof Variable)
-					&& !(referencedObject instanceof Property)) {
-				error(LEFT_HAND_ASSIGNMENT,
-						ExpressionsPackage.Literals.ASSIGNMENT_EXPRESSION__VAR_REF);
+			if (!(referencedObject instanceof Variable) && !(referencedObject instanceof Property)) {
+				error(LEFT_HAND_ASSIGNMENT, ExpressionsPackage.Literals.ASSIGNMENT_EXPRESSION__VAR_REF);
 			}
 		} else if (varRef instanceof ElementReferenceExpression) {
-			EObject referencedObject = ((ElementReferenceExpression) varRef)
-					.getReference();
-			if (!(referencedObject instanceof Variable)
-					&& !(referencedObject instanceof Property)) {
-				error(LEFT_HAND_ASSIGNMENT,
-						ExpressionsPackage.Literals.ASSIGNMENT_EXPRESSION__VAR_REF);
+			EObject referencedObject = ((ElementReferenceExpression) varRef).getReference();
+			if (!(referencedObject instanceof Variable) && !(referencedObject instanceof Property)) {
+				error(LEFT_HAND_ASSIGNMENT, ExpressionsPackage.Literals.ASSIGNMENT_EXPRESSION__VAR_REF);
 			}
 
 		} else {
-			error(LEFT_HAND_ASSIGNMENT,
-					ExpressionsPackage.Literals.ASSIGNMENT_EXPRESSION__VAR_REF);
+			error(LEFT_HAND_ASSIGNMENT, ExpressionsPackage.Literals.ASSIGNMENT_EXPRESSION__VAR_REF);
 		}
 	}
 
@@ -221,12 +210,10 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 		if (varRef instanceof FeatureCall)
 			referencedObject = ((FeatureCall) varRef).getFeature();
 		else if (varRef instanceof ElementReferenceExpression)
-			referencedObject = ((ElementReferenceExpression) varRef)
-					.getReference();
+			referencedObject = ((ElementReferenceExpression) varRef).getReference();
 		if (referencedObject instanceof VariableDefinition) {
 			if (!((VariableDefinition) referencedObject).isWriteable()) {
-				error(ASSIGNMENT_TO_VALUE,
-						ExpressionsPackage.Literals.ASSIGNMENT_EXPRESSION__VAR_REF);
+				error(ASSIGNMENT_TO_VALUE, ExpressionsPackage.Literals.ASSIGNMENT_EXPRESSION__VAR_REF);
 			}
 		}
 	}
@@ -249,45 +236,72 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 			if (expression instanceof FeatureCall)
 				referencedObject = ((FeatureCall) expression).getFeature();
 			else if (expression instanceof ElementReferenceExpression)
-				referencedObject = ((ElementReferenceExpression) expression)
-						.getReference();
+				referencedObject = ((ElementReferenceExpression) expression).getReference();
 			if (referencedObject instanceof VariableDefinition) {
 				if (((VariableDefinition) referencedObject).isWriteable()) {
-					error(REFERENCE_TO_VARIABLE,
-							StextPackage.Literals.VARIABLE_DEFINITION__INITIAL_VALUE);
+					error(REFERENCE_TO_VARIABLE, StextPackage.Literals.VARIABLE_DEFINITION__INITIAL_VALUE);
 				}
 			}
 		}
 	}
 
+	@Check(CheckType.FAST)
+	public void checkValueReferenedBeforeDefined(Scope scope) {
+		EList<Declaration> declarations = scope.getDeclarations();
+		Set<QualifiedName> defined = Sets.newHashSet();
+		for (Declaration declaration : declarations) {
+			if (declaration instanceof VariableDefinition) {
+				VariableDefinition definition = (VariableDefinition) declaration;
+				if (definition.isWriteable())
+					return;
+				Expression initialValue = definition.getInitialValue();
+				List<Expression> toCheck = Lists.newArrayList(initialValue);
+				TreeIterator<EObject> eAllContents = initialValue.eAllContents();
+				while (eAllContents.hasNext()) {
+					EObject next = eAllContents.next();
+					if (next instanceof Expression)
+						toCheck.add((Expression) next);
+				}
+				for (Expression expression : toCheck) {
+					EObject referencedObject = null;
+					if (expression instanceof FeatureCall)
+						referencedObject = ((FeatureCall) expression).getFeature();
+					else if (expression instanceof ElementReferenceExpression)
+						referencedObject = ((ElementReferenceExpression) expression).getReference();
+					if (referencedObject instanceof VariableDefinition) {
+						if (!defined.contains(nameProvider.getFullyQualifiedName(referencedObject)))
+							error(REFERENCE_CONSTANT_BEFORE_DEFINED, definition,
+									StextPackage.Literals.VARIABLE_DEFINITION__INITIAL_VALUE);
+					}
+				}
+				defined.add(nameProvider.getFullyQualifiedName(definition));
+			}
+		}
+	}
+
 	@Check(CheckType.FAST)
 	public void checkUnusedExit(final Exit exit) {
 		if (exit.getParentRegion().getComposite() instanceof org.yakindu.sct.model.sgraph.State
 				&& exit.getOutgoingTransitions().isEmpty()) {
-			org.yakindu.sct.model.sgraph.State state = (org.yakindu.sct.model.sgraph.State) exit
-					.getParentRegion().getComposite();
+			org.yakindu.sct.model.sgraph.State state = (org.yakindu.sct.model.sgraph.State) exit.getParentRegion()
+					.getComposite();
 
 			if (!STextValidationModelUtils.isDefault(exit)) {
 				boolean hasOutgoingTransition = false;
-				Iterator<Transition> transitionIt = state
-						.getOutgoingTransitions().iterator();
+				Iterator<Transition> transitionIt = state.getOutgoingTransitions().iterator();
 				while (transitionIt.hasNext() && !hasOutgoingTransition) {
 					Transition transition = transitionIt.next();
-					hasOutgoingTransition = STextValidationModelUtils
-							.isDefaultExitTransition(transition) ? true
-							: STextValidationModelUtils.isNamedExitTransition(
-									transition, exit.getName());
+					hasOutgoingTransition = STextValidationModelUtils.isDefaultExitTransition(transition) ? true
+							: STextValidationModelUtils.isNamedExitTransition(transition, exit.getName());
 				}
 				if (!hasOutgoingTransition) {
 					error(EXIT_UNUSED, exit, null, -1);
 				}
 			} else {
 				boolean hasOutgoingTransition = false;
-				Iterator<Transition> transitionIt = state
-						.getOutgoingTransitions().iterator();
+				Iterator<Transition> transitionIt = state.getOutgoingTransitions().iterator();
 				while (transitionIt.hasNext() && !hasOutgoingTransition) {
-					hasOutgoingTransition = STextValidationModelUtils
-							.isDefaultExitTransition(transitionIt.next());
+					hasOutgoingTransition = STextValidationModelUtils.isDefaultExitTransition(transitionIt.next());
 				}
 				if (!hasOutgoingTransition) {
 					error(EXIT_DEFAULT_UNUSED, exit, null, -1);
@@ -304,8 +318,7 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 					org.yakindu.sct.model.sgraph.State state = (org.yakindu.sct.model.sgraph.State) transition
 							.getTarget();
 					if (!state.isComposite()) {
-						warning(TRANSITION_ENTRY_SPEC_NOT_COMPOSITE,
-								transition, null, -1);
+						warning(TRANSITION_ENTRY_SPEC_NOT_COMPOSITE, transition, null, -1);
 					}
 				}
 			} else if (property instanceof ExitPointSpec) {
@@ -314,19 +327,14 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 					org.yakindu.sct.model.sgraph.State state = (org.yakindu.sct.model.sgraph.State) transition
 							.getSource();
 					if (!state.isComposite()) {
-						warning(TRANSITION_EXIT_SPEC_NOT_COMPOSITE, transition,
-								null, -1);
+						warning(TRANSITION_EXIT_SPEC_NOT_COMPOSITE, transition, null, -1);
 					} else {
 						// Validate an exit point is continued on one transition
 						// only.
 						for (Transition t : state.getOutgoingTransitions()) {
 							if (transition != t
-									&& STextValidationModelUtils
-											.isNamedExitTransition(t,
-													exitPointSpec
-															.getExitpoint())) {
-								warning(TRANSITION_EXIT_SPEC_ON_MULTIPLE_SIBLINGS,
-										transition, null, -1);
+									&& STextValidationModelUtils.isNamedExitTransition(t, exitPointSpec.getExitpoint())) {
+								warning(TRANSITION_EXIT_SPEC_ON_MULTIPLE_SIBLINGS, transition, null, -1);
 							}
 						}
 
@@ -334,22 +342,18 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 						// region
 
 						boolean hasExit = false;
-						Iterator<Region> regionIter = state.getRegions()
-								.iterator();
+						Iterator<Region> regionIter = state.getRegions().iterator();
 						while (regionIter.hasNext() && !hasExit) {
 
-							Iterator<Exit> exitIter = STextValidationModelUtils
-									.getExits(regionIter.next().eContents())
+							Iterator<Exit> exitIter = STextValidationModelUtils.getExits(regionIter.next().eContents())
 									.iterator();
 							while (exitIter.hasNext() && !hasExit) {
 								Exit exit = exitIter.next();
-								hasExit = exitPointSpec.getExitpoint().equals(
-										exit.getName());
+								hasExit = exitPointSpec.getExitpoint().equals(exit.getName());
 							}
 						}
 						if (!hasExit) {
-							error(TRANSITION_NOT_EXISTING_NAMED_EXIT_POINT,
-									transition, null, -1);
+							error(TRANSITION_NOT_EXISTING_NAMED_EXIT_POINT, transition, null, -1);
 						}
 
 					}
@@ -359,26 +363,21 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 	}
 
 	@Check(CheckType.FAST)
-	public void checkUnboundEntryPoints(
-			final org.yakindu.sct.model.sgraph.State state) {
+	public void checkUnboundEntryPoints(final org.yakindu.sct.model.sgraph.State state) {
 		if (state.isComposite()) {
-			final List<Transition>[] transitions = STextValidationModelUtils
-					.getEntrySpecSortedTransitions(state
-							.getIncomingTransitions());
+			final List<Transition>[] transitions = STextValidationModelUtils.getEntrySpecSortedTransitions(state
+					.getIncomingTransitions());
 			Map<Region, List<Entry>> regions = null;
 
 			// first list contains Transitions without entry spec
 			if (!transitions[0].isEmpty()) {
-				regions = STextValidationModelUtils
-						.getRegionsWithoutDefaultEntry(state.getRegions());
+				regions = STextValidationModelUtils.getRegionsWithoutDefaultEntry(state.getRegions());
 				if (!regions.isEmpty()) {
 					for (Transition transition : transitions[0]) {
-						error(TRANSITION_UNBOUND_DEFAULT_ENTRY_POINT,
-								transition, null, -1);
+						error(TRANSITION_UNBOUND_DEFAULT_ENTRY_POINT, transition, null, -1);
 					}
 					for (Region region : regions.keySet()) {
-						error(REGION_UNBOUND_DEFAULT_ENTRY_POINT, region, null,
-								-1);
+						error(REGION_UNBOUND_DEFAULT_ENTRY_POINT, region, null, -1);
 					}
 				}
 			}
@@ -386,8 +385,7 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 			// second list contains Transitions with entry spec
 			if (!transitions[1].isEmpty()) {
 				if (regions == null) {
-					regions = STextValidationModelUtils
-							.getRegionsWithoutDefaultEntry(state.getRegions());
+					regions = STextValidationModelUtils.getRegionsWithoutDefaultEntry(state.getRegions());
 				}
 				for (Transition transition : transitions[1]) {
 					boolean hasTargetEntry = true;
@@ -398,21 +396,18 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 							for (Region region : regions.keySet()) {
 								boolean hasEntry = false;
 								for (Entry entry : regions.get(region)) {
-									if (entry.getName().equals(
-											spec.getEntrypoint())) {
+									if (entry.getName().equals(spec.getEntrypoint())) {
 										hasEntry = true;
 										break;
 									}
 								}
 								if (!hasEntry) {
-									error(REGION_UNBOUND_NAMED_ENTRY_POINT
-											+ specName, region, null, -1);
+									error(REGION_UNBOUND_NAMED_ENTRY_POINT + specName, region, null, -1);
 									hasTargetEntry = false;
 								}
 							}
 							if (!hasTargetEntry) {
-								error(TRANSITION_UNBOUND_NAMED_ENTRY_POINT
-										+ specName, transition, null, -1);
+								error(TRANSITION_UNBOUND_NAMED_ENTRY_POINT + specName, transition, null, -1);
 							}
 						}
 					}
@@ -425,8 +420,7 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 	public void checkVariableDefinition(final VariableDefinition definition) {
 		try {
 			InferenceResult result = typeInferrer.inferType(definition);
-			if (result.getType() != null
-					&& typeSystem.isVoidType(result.getType())) {
+			if (result.getType() != null && typeSystem.isVoidType(result.getType())) {
 				error(VARIABLE_VOID_TYPE, null);
 			} else {
 				report(result, null);
@@ -450,8 +444,7 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 	}
 
 	@Check(CheckType.FAST)
-	public void checkOperationArguments_TypedElementReferenceExpression(
-			final ElementReferenceExpression call) {
+	public void checkOperationArguments_TypedElementReferenceExpression(final ElementReferenceExpression call) {
 		if (call.getReference() instanceof Operation) {
 			Operation operation = (Operation) call.getReference();
 			EList<Parameter> parameters = operation.getParameters();
@@ -467,18 +460,16 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 
 		final String name = getVariableName(exp);
 
-		List<AssignmentExpression> contents = EcoreUtil2.eAllOfType(exp,
-				AssignmentExpression.class);
+		List<AssignmentExpression> contents = EcoreUtil2.eAllOfType(exp, AssignmentExpression.class);
 		contents.remove(exp);
 
-		Iterable<AssignmentExpression> filter = Iterables.filter(contents,
-				new Predicate<AssignmentExpression>() {
-					public boolean apply(final AssignmentExpression ex) {
-						String variableName = getVariableName(ex);
-						return variableName.equals(name);
+		Iterable<AssignmentExpression> filter = Iterables.filter(contents, new Predicate<AssignmentExpression>() {
+			public boolean apply(final AssignmentExpression ex) {
+				String variableName = getVariableName(ex);
+				return variableName.equals(name);
 
-					}
-				});
+			}
+		});
 		if (Iterables.size(filter) > 0) {
 			error(ASSIGNMENT_EXPRESSION, null);
 		}
@@ -488,11 +479,9 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 		Expression varRef = exp.getVarRef();
 		if (varRef instanceof ElementReferenceExpression
 				&& ((ElementReferenceExpression) varRef).getReference() instanceof Property) {
-			Property reference = (Property) ((ElementReferenceExpression) varRef)
-					.getReference();
+			Property reference = (Property) ((ElementReferenceExpression) varRef).getReference();
 			return reference.getName();
-		} else if (varRef instanceof FeatureCall
-				&& ((FeatureCall) varRef).getFeature() instanceof Property) {
+		} else if (varRef instanceof FeatureCall && ((FeatureCall) varRef).getFeature() instanceof Property) {
 			Property reference = (Property) ((FeatureCall) varRef).getFeature();
 			return reference.getName();
 		}
@@ -505,8 +494,7 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 			return;
 		}
 		if (call.getFeature() instanceof Scope) {
-			error("A variable, event or operation is required",
-					ExpressionsPackage.Literals.FEATURE_CALL__FEATURE,
+			error("A variable, event or operation is required", ExpressionsPackage.Literals.FEATURE_CALL__FEATURE,
 					INSIGNIFICANT_INDEX, FEATURE_CALL_TO_SCOPE);
 		}
 	}
@@ -518,18 +506,16 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 		}
 		if (call.getReference() instanceof Scope) {
 			error("A variable, event or operation is required",
-					ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE,
-					INSIGNIFICANT_INDEX, FEATURE_CALL_TO_SCOPE);
+					ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE, INSIGNIFICANT_INDEX,
+					FEATURE_CALL_TO_SCOPE);
 		}
 	}
 
 	@Check(CheckType.FAST)
 	public void checkGuard(Guard guard) {
 		try {
-			InferenceResult result = typeInferrer.inferType(guard
-					.getExpression());
-			if (result.getType() == null
-					|| !typeSystem.isBooleanType(result.getType())) {
+			InferenceResult result = typeInferrer.inferType(guard.getExpression());
+			if (result.getType() == null || !typeSystem.isBooleanType(result.getType())) {
 				error(GUARD_EXPRESSION, StextPackage.Literals.GUARD__EXPRESSION);
 			}
 			report(result, null);
@@ -543,8 +529,7 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 	public void checkTimeEventSpecValueExpression(TimeEventSpec spec) {
 		try {
 			InferenceResult result = typeInferrer.inferType(spec.getValue());
-			if (result.getType() == null
-					|| !typeSystem.isIntegerType(result.getType())) {
+			if (result.getType() == null || !typeSystem.isIntegerType(result.getType())) {
 				error(TIME_EXPRESSION, null);
 			}
 			report(result, StextPackage.Literals.TIME_EVENT_SPEC__VALUE);
@@ -560,8 +545,8 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 			if (!(reactionTrigger.eContainer() instanceof LocalReaction)
 					&& (eventSpec instanceof EntryEvent || eventSpec instanceof ExitEvent)) {
 				error("entry and exit events are allowed as local reactions only.",
-						StextPackage.Literals.REACTION_TRIGGER__TRIGGERS,
-						INSIGNIFICANT_INDEX, LOCAL_REACTIONS_NOT_ALLOWED);
+						StextPackage.Literals.REACTION_TRIGGER__TRIGGERS, INSIGNIFICANT_INDEX,
+						LOCAL_REACTIONS_NOT_ALLOWED);
 			}
 		}
 	}
@@ -588,18 +573,15 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 	public void checkReactionEffectActions(ReactionEffect effect) {
 		for (Expression exp : effect.getActions()) {
 
-			if (!(exp instanceof AssignmentExpression)
-					&& !(exp instanceof EventRaisingExpression)) {
+			if (!(exp instanceof AssignmentExpression) && !(exp instanceof EventRaisingExpression)) {
 
 				if (exp instanceof FeatureCall) {
 					checkFeatureCallEffect((FeatureCall) exp);
 				} else if (exp instanceof ElementReferenceExpression) {
 					checkElementReferenceEffect((ElementReferenceExpression) exp);
 				} else {
-					error("Action has no effect.",
-							StextPackage.Literals.REACTION_EFFECT__ACTIONS,
-							effect.getActions().indexOf(exp),
-							FEATURE_CALL_HAS_NO_EFFECT);
+					error("Action has no effect.", StextPackage.Literals.REACTION_EFFECT__ACTIONS, effect.getActions()
+							.indexOf(exp), FEATURE_CALL_HAS_NO_EFFECT);
 				}
 
 			}
@@ -610,22 +592,16 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 		if (call.getFeature() != null && call.getFeature() instanceof Feature
 				&& !(call.getFeature() instanceof Operation)) {
 			if (call.getFeature() instanceof Property) {
-				error("Access to property '"
-						+ nameProvider.getFullyQualifiedName(call.getFeature())
-						+ "' has no effect.", call,
-						ExpressionsPackage.Literals.FEATURE_CALL__FEATURE,
+				error("Access to property '" + nameProvider.getFullyQualifiedName(call.getFeature())
+						+ "' has no effect.", call, ExpressionsPackage.Literals.FEATURE_CALL__FEATURE,
 						INSIGNIFICANT_INDEX, FEATURE_CALL_HAS_NO_EFFECT);
 			} else if (call.getFeature() instanceof Event) {
-				error("Access to event '"
-						+ nameProvider.getFullyQualifiedName(call.getFeature())
-						+ "' has no effect.", call,
-						ExpressionsPackage.Literals.FEATURE_CALL__FEATURE,
-						INSIGNIFICANT_INDEX, FEATURE_CALL_HAS_NO_EFFECT);
+				error("Access to event '" + nameProvider.getFullyQualifiedName(call.getFeature()) + "' has no effect.",
+						call, ExpressionsPackage.Literals.FEATURE_CALL__FEATURE, INSIGNIFICANT_INDEX,
+						FEATURE_CALL_HAS_NO_EFFECT);
 			} else {
-				error("Access to feature '"
-						+ nameProvider.getFullyQualifiedName(call.getFeature())
-						+ "' has no effect.", call,
-						ExpressionsPackage.Literals.FEATURE_CALL__FEATURE,
+				error("Access to feature '" + nameProvider.getFullyQualifiedName(call.getFeature())
+						+ "' has no effect.", call, ExpressionsPackage.Literals.FEATURE_CALL__FEATURE,
 						INSIGNIFICANT_INDEX, FEATURE_CALL_HAS_NO_EFFECT);
 			}
 		}
@@ -634,49 +610,37 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 	protected void checkElementReferenceEffect(ElementReferenceExpression refExp) {
 		if (!(refExp.getReference() instanceof Operation)) {
 			if (refExp.getReference() instanceof Property) {
-				error("Access to property '"
-						+ nameProvider.getFullyQualifiedName(refExp
-								.getReference()) + "' has no effect.",
-						refExp,
-						ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE,
-						INSIGNIFICANT_INDEX, FEATURE_CALL_HAS_NO_EFFECT);
+				error("Access to property '" + nameProvider.getFullyQualifiedName(refExp.getReference())
+						+ "' has no effect.", refExp,
+						ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE, INSIGNIFICANT_INDEX,
+						FEATURE_CALL_HAS_NO_EFFECT);
 			} else if (refExp.getReference() instanceof Event) {
-				error("Access to event '"
-						+ nameProvider.getFullyQualifiedName(refExp
-								.getReference()) + "' has no effect.",
-						refExp,
-						ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE,
-						INSIGNIFICANT_INDEX, FEATURE_CALL_HAS_NO_EFFECT);
+				error("Access to event '" + nameProvider.getFullyQualifiedName(refExp.getReference())
+						+ "' has no effect.", refExp,
+						ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE, INSIGNIFICANT_INDEX,
+						FEATURE_CALL_HAS_NO_EFFECT);
 			} else {
-				error("Access to feature '"
-						+ nameProvider.getFullyQualifiedName(refExp
-								.getReference()) + "' has no effect.",
-						refExp,
-						ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE,
-						INSIGNIFICANT_INDEX, FEATURE_CALL_HAS_NO_EFFECT);
+				error("Access to feature '" + nameProvider.getFullyQualifiedName(refExp.getReference())
+						+ "' has no effect.", refExp,
+						ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE, INSIGNIFICANT_INDEX,
+						FEATURE_CALL_HAS_NO_EFFECT);
 			}
 		}
 	}
 
 	@Check(CheckType.FAST)
 	public void checkEventDefinition(EventDefinition event) {
-		if (event.eContainer() instanceof InterfaceScope
-				&& event.getDirection() == Direction.LOCAL) {
-			error(LOCAL_DECLARATIONS,
-					StextPackage.Literals.EVENT_DEFINITION__DIRECTION);
+		if (event.eContainer() instanceof InterfaceScope && event.getDirection() == Direction.LOCAL) {
+			error(LOCAL_DECLARATIONS, StextPackage.Literals.EVENT_DEFINITION__DIRECTION);
 		}
-		if (event.eContainer() instanceof InternalScope
-				&& event.getDirection() != Direction.LOCAL) {
-			error(IN_OUT_DECLARATIONS,
-					StextPackage.Literals.EVENT_DEFINITION__DIRECTION);
+		if (event.eContainer() instanceof InternalScope && event.getDirection() != Direction.LOCAL) {
+			error(IN_OUT_DECLARATIONS, StextPackage.Literals.EVENT_DEFINITION__DIRECTION);
 		}
 	}
 
 	@Check(CheckType.FAST)
 	public void checkExitPointSpecWithTrigger(Transition t) {
-		if (!STextValidationModelUtils.getExitPointSpecs(t.getProperties())
-				.isEmpty()
-				&& t.getTrigger() != null
+		if (!STextValidationModelUtils.getExitPointSpecs(t.getProperties()).isEmpty() && t.getTrigger() != null
 				&& t.getSource() instanceof org.yakindu.sct.model.sgraph.State) {
 			error(EXITPOINTSPEC_WITH_TRIGGER, t, null, -1);
 		}
@@ -687,17 +651,14 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 		List<InterfaceScope> defaultInterfaces = new LinkedList<InterfaceScope>();
 
 		for (Scope scope : statechart.getScopes()) {
-			if (scope instanceof InterfaceScope
-					&& ((InterfaceScope) scope).getName() == null) {
+			if (scope instanceof InterfaceScope && ((InterfaceScope) scope).getName() == null) {
 				defaultInterfaces.add((InterfaceScope) scope);
 			}
 		}
 		if (defaultInterfaces.size() > 1) {
 			for (InterfaceScope scope : defaultInterfaces) {
-				error(ONLY_ONE_INTERFACE, scope, grammarAccess
-						.getInterfaceScopeAccess().getInterfaceKeyword_1(),
-						ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
-						ONLY_ONE_INTERFACE);
+				error(ONLY_ONE_INTERFACE, scope, grammarAccess.getInterfaceScopeAccess().getInterfaceKeyword_1(),
+						ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ONLY_ONE_INTERFACE);
 			}
 		}
 	}
@@ -712,22 +673,19 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 			}
 		}
 		if (!found)
-			warning(CHOICE_ONE_OUTGOING_DEFAULT_TRANSITION,
-					SGraphPackage.Literals.VERTEX__OUTGOING_TRANSITIONS);
+			warning(CHOICE_ONE_OUTGOING_DEFAULT_TRANSITION, SGraphPackage.Literals.VERTEX__OUTGOING_TRANSITIONS);
 	}
 
 	protected boolean isDefault(Trigger trigger) {
 
 		return trigger == null
 				|| trigger instanceof DefaultTrigger
-				|| ((trigger instanceof ReactionTrigger)
-						&& ((ReactionTrigger) trigger).getTriggers().size() == 0 && ((ReactionTrigger) trigger)
+				|| ((trigger instanceof ReactionTrigger) && ((ReactionTrigger) trigger).getTriggers().size() == 0 && ((ReactionTrigger) trigger)
 						.getGuard() == null);
 	}
 
 	@Override
-	protected String getCurrentLanguage(Map<Object, Object> context,
-			EObject eObject) {
+	protected String getCurrentLanguage(Map<Object, Object> context, EObject eObject) {
 		Resource eResource = eObject.eResource();
 		if (eResource instanceof XtextResource) {
 			return super.getCurrentLanguage(context, eObject);
@@ -737,27 +695,22 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 		return "";
 	}
 
-	protected void error(String message, EObject source, Keyword keyword,
-			int index, String code) {
+	protected void error(String message, EObject source, Keyword keyword, int index, String code) {
 		final String[] issueData = null;
 		ICompositeNode rootNode = NodeModelUtils.findActualNodeFor(source);
 		if (rootNode != null) {
-			INode child = findNode(source, false, rootNode, keyword,
-					new int[] { index });
+			INode child = findNode(source, false, rootNode, keyword, new int[] { index });
 			if (child != null) {
 				int offset = child.getTotalOffset();
 				int length = child.getTotalLength();
-				getMessageAcceptor().acceptError(message, source, offset,
-						length, code, issueData);
+				getMessageAcceptor().acceptError(message, source, offset, length, code, issueData);
 				return;
 			}
 		}
-		error(message, source, (EStructuralFeature) null,
-				ValidationMessageAcceptor.INSIGNIFICANT_INDEX, code);
+		error(message, source, (EStructuralFeature) null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, code);
 	}
 
-	private INode findNode(EObject source, boolean sourceFound, INode root,
-			Keyword keyword, int[] index) {
+	private INode findNode(EObject source, boolean sourceFound, INode root, Keyword keyword, int[] index) {
 		if (sourceFound && root.getSemanticElement() != source) {
 			return null;
 		}
@@ -768,9 +721,7 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 		// .equals or == does not work because sub grammars use their own
 		// Modules with custom
 		// grammarAccess instance and .equals is not overwritten.
-		if (grammarElement instanceof Keyword
-				&& keyword.getValue().equals(
-						((Keyword) grammarElement).getValue())) {
+		if (grammarElement instanceof Keyword && keyword.getValue().equals(((Keyword) grammarElement).getValue())) {
 			if (index[0] != INSIGNIFICANT_INDEX) {
 				index[0]--;
 			}
@@ -781,8 +732,7 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 		if (root instanceof ICompositeNode) {
 			ICompositeNode node = (ICompositeNode) root;
 			for (INode child : node.getChildren()) {
-				INode result = findNode(source, sourceFound, child, keyword,
-						index);
+				INode result = findNode(source, sourceFound, child, keyword, index);
 				if (result != null) {
 					return result;
 				}
@@ -801,35 +751,26 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 	@Check(CheckType.FAST)
 	public void checkImportExists(Import importDef) {
 		String importedNamespace = importDef.getImportedNamespace();
-		if (!checkImportedNamespaceExists(importDef.getImportedNamespace(),
-				getResource(importDef))) {
-			error("The import " + importedNamespace + " cannot be resolved",
-					importDef,
-					StextPackage.Literals.IMPORT__IMPORTED_NAMESPACE,
-					IMPORT_NOT_RESOLVED);
+		if (!checkImportedNamespaceExists(importDef.getImportedNamespace(), getResource(importDef))) {
+			error("The import " + importedNamespace + " cannot be resolved", importDef,
+					StextPackage.Literals.IMPORT__IMPORTED_NAMESPACE, IMPORT_NOT_RESOLVED);
 		}
 	}
 
-	protected boolean checkImportedNamespaceExists(String importedNamespace,
-			Resource res) {
+	protected boolean checkImportedNamespaceExists(String importedNamespace, Resource res) {
 		if (importedNamespace.endsWith(".*")) {
-			importedNamespace = importedNamespace.substring(0,
-					importedNamespace.length() - 2); // remove
-														// wildcard
+			importedNamespace = importedNamespace.substring(0, importedNamespace.length() - 2); // remove
+																								// wildcard
 		}
-		IResourceDescriptions resourceDescriptions = resourceDescriptionsProvider
-				.getResourceDescriptions(res);
+		IResourceDescriptions resourceDescriptions = resourceDescriptionsProvider.getResourceDescriptions(res);
 		URI uri = res.getURI();
-		IResourceDescription resourceDescription = resourceDescriptions
-				.getResourceDescription(uri);
+		IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(uri);
 		if (resourceDescription == null) {
 			return false; // no resource description could be found, so package
 							// cannot be resolved anyway
 		}
-		for (IContainer container : containerManager.getVisibleContainers(
-				resourceDescription, resourceDescriptions)) {
-			final Iterable<IResourceDescription> currentDescriptions = container
-					.getResourceDescriptions();
+		for (IContainer container : containerManager.getVisibleContainers(resourceDescription, resourceDescriptions)) {
+			final Iterable<IResourceDescription> currentDescriptions = container.getResourceDescriptions();
 			for (IResourceDescription resDesc : currentDescriptions) {
 				Iterable<IEObjectDescription> visiblePackages = resDesc
 						.getExportedObjectsByType(TypesPackage.Literals.PACKAGE);
@@ -844,9 +785,8 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements
 	}
 
 	private Resource getResource(EObject context) {
-		final ContextElementAdapter provider = (ContextElementAdapter) EcoreUtil
-				.getExistingAdapter(context.eResource(),
-						ContextElementAdapter.class);
+		final ContextElementAdapter provider = (ContextElementAdapter) EcoreUtil.getExistingAdapter(
+				context.eResource(), ContextElementAdapter.class);
 		if (provider == null) {
 			return context.eResource();
 		} else {

+ 3 - 4
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/validation/STextValidationMessages.java

@@ -46,8 +46,7 @@ public interface STextValidationMessages {
 	public static final String ISSUE_TRANSITION_WITHOUT_TRIGGER = "Missing trigger. Transisition is never taken. Use 'oncycle' or 'always' instead";
 	public static final String IMPORT_NOT_RESOLVED = "Import cannot be resolved";
 	public static final String EXITPOINTSPEC_WITH_TRIGGER = "Transitions with an exit point spec does not have a trigger or guard.";
-	public static final String ASSIGNMENT_TO_VALUE = "Assignment to final field";
-	public static final String REFERENCE_TO_VARIABLE = "Cannot reference a variable in final field initialization";
-	public static final String REFERENCE_FIELD_BEFORE_DEFINED = "Cannot reference a field before it is defined";
-	
+	public static final String ASSIGNMENT_TO_VALUE = "Assignment constant not allowed";
+	public static final String REFERENCE_TO_VARIABLE = "Cannot reference a variable in a constant initialization";
+	public static final String REFERENCE_CONSTANT_BEFORE_DEFINED = "Cannot reference a constant from different scope or before it is defined";	
 }

+ 120 - 204
test-plugins/org.yakindu.sct.model.stext.test/src/org/yakindu/sct/model/stext/test/STextJavaValidatorTest.java

@@ -14,7 +14,7 @@ package org.yakindu.sct.model.stext.test;
 import static org.eclipse.xtext.junit4.validation.AssertableDiagnostics.errorCode;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertTrue;
 import static org.yakindu.sct.test.models.AbstractTestModelsUtil.VALIDATION_TESTMODEL_DIR;
 
 import java.lang.reflect.Method;
@@ -112,11 +112,10 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 	 */
 	@Test
 	public void checkVariableDefinition() {
-		Scope context = (Scope) parseExpression("interface if : var i : void",
-				null, InterfaceScope.class.getSimpleName());
+		Scope context = (Scope) parseExpression("interface if : var i : void", null,
+				InterfaceScope.class.getSimpleName());
 		AssertableDiagnostics validationResult = tester.validate(context);
-		validationResult
-				.assertErrorContains(STextJavaValidator.VARIABLE_VOID_TYPE);
+		validationResult.assertErrorContains(STextJavaValidator.VARIABLE_VOID_TYPE);
 	}
 
 	/**
@@ -125,29 +124,23 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 	@Test
 	public void checkAssignmentExpression() {
 
-		Scope context = (Scope) parseExpression(
-				"interface: var i : integer = 42 var j : integer =23", null,
+		Scope context = (Scope) parseExpression("interface: var i : integer = 42 var j : integer =23", null,
 				InterfaceScope.class.getSimpleName());
 
-		EObject expression = super.parseExpression("i += (i+=3) +4", context,
-				Expression.class.getSimpleName());
+		EObject expression = super.parseExpression("i += (i+=3) +4", context, Expression.class.getSimpleName());
 		AssertableDiagnostics validationResult = tester.validate(expression);
-		validationResult
-				.assertErrorContains(STextJavaValidator.ASSIGNMENT_EXPRESSION);
+		validationResult.assertErrorContains(STextJavaValidator.ASSIGNMENT_EXPRESSION);
 
-		expression = super.parseExpression("i += (j+=3) +4", context,
-				Expression.class.getSimpleName());
+		expression = super.parseExpression("i += (j+=3) +4", context, Expression.class.getSimpleName());
 		validationResult = tester.validate(expression);
 		validationResult.assertOK();
 	}
 
 	@Test
 	public void checkTimeEventSpecValueExpression() {
-		EObject expression = super.parseExpression("after true s",
-				ReactionTrigger.class.getSimpleName());
+		EObject expression = super.parseExpression("after true s", ReactionTrigger.class.getSimpleName());
 		AssertableDiagnostics validationResult = tester.validate(expression);
-		validationResult
-				.assertErrorContains(STextJavaValidator.TIME_EXPRESSION);
+		validationResult.assertErrorContains(STextJavaValidator.TIME_EXPRESSION);
 	}
 
 	@Test
@@ -159,52 +152,40 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 	public void checkLeftHandAssignment() {
 
 		Scope scope = (Scope) parseExpression(
-				"interface if : operation myOperation() : boolean event Event1 : boolean var myVar : boolean",
-				null, InterfaceScope.class.getSimpleName());
+				"interface if : operation myOperation() : boolean event Event1 : boolean var myVar : boolean", null,
+				InterfaceScope.class.getSimpleName());
 
-		EObject model = super.parseExpression("3 = 3",
-				Expression.class.getSimpleName(), scope);
+		EObject model = super.parseExpression("3 = 3", Expression.class.getSimpleName(), scope);
 		AssertableDiagnostics validationResult = tester.validate(model);
-		validationResult
-				.assertErrorContains(STextJavaValidator.LEFT_HAND_ASSIGNMENT);
+		validationResult.assertErrorContains(STextJavaValidator.LEFT_HAND_ASSIGNMENT);
 
 		// Check for referenced elements in interface
-		model = super.parseExpression("if.myOperation() = true",
-				Expression.class.getSimpleName(), scope);
+		model = super.parseExpression("if.myOperation() = true", Expression.class.getSimpleName(), scope);
 		validationResult = tester.validate(model);
-		validationResult
-				.assertErrorContains(STextJavaValidator.LEFT_HAND_ASSIGNMENT);
+		validationResult.assertErrorContains(STextJavaValidator.LEFT_HAND_ASSIGNMENT);
 
-		model = super.parseExpression("if.Event1 = true",
-				Expression.class.getSimpleName(), scope);
+		model = super.parseExpression("if.Event1 = true", Expression.class.getSimpleName(), scope);
 		validationResult = tester.validate(model);
-		validationResult
-				.assertErrorContains(STextJavaValidator.LEFT_HAND_ASSIGNMENT);
+		validationResult.assertErrorContains(STextJavaValidator.LEFT_HAND_ASSIGNMENT);
 
-		model = super.parseExpression("if.myVar = true",
-				Expression.class.getSimpleName(), scope);
+		model = super.parseExpression("if.myVar = true", Expression.class.getSimpleName(), scope);
 		validationResult = tester.validate(model);
 		validationResult.assertOK();
 
 		// check for internal referenced elements
 		scope = (Scope) parseExpression(
-				"internal : operation myOperation() : integer event Event1 : integer var myVar : integer",
-				null, InternalScope.class.getSimpleName());
+				"internal : operation myOperation() : integer event Event1 : integer var myVar : integer", null,
+				InternalScope.class.getSimpleName());
 
-		model = super.parseExpression("myOperation() = 5",
-				Expression.class.getSimpleName(), scope);
+		model = super.parseExpression("myOperation() = 5", Expression.class.getSimpleName(), scope);
 		validationResult = tester.validate(model);
-		validationResult
-				.assertErrorContains(STextJavaValidator.LEFT_HAND_ASSIGNMENT);
+		validationResult.assertErrorContains(STextJavaValidator.LEFT_HAND_ASSIGNMENT);
 
-		model = super.parseExpression("Event1 = 3",
-				Expression.class.getSimpleName(), scope);
+		model = super.parseExpression("Event1 = 3", Expression.class.getSimpleName(), scope);
 		validationResult = tester.validate(model);
-		validationResult
-				.assertErrorContains(STextJavaValidator.LEFT_HAND_ASSIGNMENT);
+		validationResult.assertErrorContains(STextJavaValidator.LEFT_HAND_ASSIGNMENT);
 
-		model = super.parseExpression("myVar = 5",
-				Expression.class.getSimpleName(), scope);
+		model = super.parseExpression("myVar = 5", Expression.class.getSimpleName(), scope);
 		validationResult = tester.validate(model);
 		validationResult.assertOK();
 
@@ -216,10 +197,9 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 	@Test
 	public void checkOperationArguments_FeatureCall() {
 		Scope scope = (Scope) parseExpression(
-				"interface if : operation myOperation(param1 : integer, param2: boolean)",
-				null, InterfaceScope.class.getSimpleName());
-		EObject model = super.parseExpression("if.myOperation(5,true)",
-				Expression.class.getSimpleName(), scope);
+				"interface if : operation myOperation(param1 : integer, param2: boolean)", null,
+				InterfaceScope.class.getSimpleName());
+		EObject model = super.parseExpression("if.myOperation(5,true)", Expression.class.getSimpleName(), scope);
 		AssertableDiagnostics validationResult = tester.validate(model);
 		validationResult.assertOK();
 	}
@@ -230,8 +210,7 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 	@Test
 	public void checkOperationArguments_TypedElementReferenceExpression() {
 		Scope context = createInternalScope("internal: operation myOperation(param1 : integer, param2: boolean)");
-		EObject model = super.parseExpression("myOperation(5,true)", context,
-				Expression.class.getSimpleName());
+		EObject model = super.parseExpression("myOperation(5,true)", context, Expression.class.getSimpleName());
 		AssertableDiagnostics validationResult = tester.validate(model);
 		validationResult.assertOK();
 	}
@@ -241,21 +220,16 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 	 */
 	@Test
 	public void checkGuard() {
-		EObject expression = super.parseExpression("[3 * 3]",
-				ReactionTrigger.class.getSimpleName());
+		EObject expression = super.parseExpression("[3 * 3]", ReactionTrigger.class.getSimpleName());
 		AssertableDiagnostics validationResult = tester.validate(expression);
-		validationResult
-				.assertErrorContains(STextJavaValidator.GUARD_EXPRESSION);
+		validationResult.assertErrorContains(STextJavaValidator.GUARD_EXPRESSION);
 
 		Scope context = createInternalScope("internal: var myInt : integer var myBool : boolean = true)");
-		expression = super.parseExpression("[myInt = 5]", context,
-				ReactionTrigger.class.getSimpleName());
+		expression = super.parseExpression("[myInt = 5]", context, ReactionTrigger.class.getSimpleName());
 		validationResult = tester.validate(expression);
-		validationResult
-				.assertErrorContains(STextJavaValidator.GUARD_EXPRESSION);
+		validationResult.assertErrorContains(STextJavaValidator.GUARD_EXPRESSION);
 
-		expression = super.parseExpression("[myInt <= 5 || !myBool ]", context,
-				ReactionTrigger.class.getSimpleName());
+		expression = super.parseExpression("[myInt <= 5 || !myBool ]", context, ReactionTrigger.class.getSimpleName());
 		validationResult = tester.validate(expression);
 		validationResult.assertOK();
 
@@ -267,21 +241,18 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 	 */
 	@Test
 	public void checkFeatureCall() {
-		Scope context = (Scope) parseExpression(
-				"interface if : in event a : integer", null,
+		Scope context = (Scope) parseExpression("interface if : in event a : integer", null,
 				InterfaceScope.class.getSimpleName());
 		EObject model = super.parseExpression("if.a / raise if.a:1", context,
 				TransitionSpecification.class.getSimpleName());
 		AssertableDiagnostics validationResult = tester.validate(model);
 		validationResult.assertOK();
 
-		model = super.parseExpression("if / raise if.a:1", context,
-				TransitionSpecification.class.getSimpleName());
+		model = super.parseExpression("if / raise if.a:1", context, TransitionSpecification.class.getSimpleName());
 		validationResult = tester.validate(model);
 		validationResult.assertError(FEATURE_CALL_TO_SCOPE);
 
-		model = super.parseExpression("if.a / raise if", context,
-				TransitionSpecification.class.getSimpleName());
+		model = super.parseExpression("if.a / raise if", context, TransitionSpecification.class.getSimpleName());
 		validationResult = tester.validate(model);
 		validationResult.assertError(FEATURE_CALL_TO_SCOPE);
 	}
@@ -293,26 +264,22 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 	@Test
 	public void checkReactionTrigger() {
 		// ENTRY, EXIT not allowed in transitions
-		Scope context = (Scope) parseExpression(
-				"internal : event a : integer var myVar : integer", null,
+		Scope context = (Scope) parseExpression("internal : event a : integer var myVar : integer", null,
 				InternalScope.class.getSimpleName());
 		EObject model = super.parseExpression("entry / myVar = 5", context,
 				TransitionSpecification.class.getSimpleName());
 		AssertableDiagnostics validationResult = tester.validate(model);
 		validationResult.assertError(LOCAL_REACTIONS_NOT_ALLOWED);
 
-		model = super.parseExpression("exit / myVar = 5", context,
-				TransitionSpecification.class.getSimpleName());
+		model = super.parseExpression("exit / myVar = 5", context, TransitionSpecification.class.getSimpleName());
 		validationResult = tester.validate(model);
 		validationResult.assertError(LOCAL_REACTIONS_NOT_ALLOWED);
 
-		model = super.parseExpression("oncycle / myVar = 5", context,
-				TransitionSpecification.class.getSimpleName());
+		model = super.parseExpression("oncycle / myVar = 5", context, TransitionSpecification.class.getSimpleName());
 		validationResult = tester.validate(model);
 		validationResult.assertOK();
 
-		model = super.parseExpression("always / myVar = 5", context,
-				TransitionSpecification.class.getSimpleName());
+		model = super.parseExpression("always / myVar = 5", context, TransitionSpecification.class.getSimpleName());
 		validationResult = tester.validate(model);
 		validationResult.assertOK();
 	}
@@ -322,45 +289,36 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 	 */
 	@Test
 	public void checkReactionEffectActions() {
-		Scope s1 = (InternalScope) parseExpression(
-				"internal : var a : integer event e operation o () : void",
-				null, InternalScope.class.getSimpleName());
-		Scope s2 = (InterfaceScope) parseExpression(
-				"interface if : var a : integer in event e operation o()",
-				null, InterfaceScope.class.getSimpleName());
-
-		EObject model = super.parseExpression("a", s1,
-				ReactionEffect.class.getSimpleName());
+		Scope s1 = (InternalScope) parseExpression("internal : var a : integer event e operation o () : void", null,
+				InternalScope.class.getSimpleName());
+		Scope s2 = (InterfaceScope) parseExpression("interface if : var a : integer in event e operation o()", null,
+				InterfaceScope.class.getSimpleName());
+
+		EObject model = super.parseExpression("a", s1, ReactionEffect.class.getSimpleName());
 		AssertableDiagnostics result = tester.validate(model);
 		result.assertError(FEATURE_CALL_HAS_NO_EFFECT);
 
-		model = super.parseExpression("1+3", s1,
-				ReactionEffect.class.getSimpleName());
+		model = super.parseExpression("1+3", s1, ReactionEffect.class.getSimpleName());
 		result = tester.validate(model);
 		result.assertError(FEATURE_CALL_HAS_NO_EFFECT);
 
-		model = super.parseExpression("valueof(e)", s1,
-				ReactionEffect.class.getSimpleName());
+		model = super.parseExpression("valueof(e)", s1, ReactionEffect.class.getSimpleName());
 		result = tester.validate(model);
 		result.assertError(FEATURE_CALL_HAS_NO_EFFECT);
 
-		model = super.parseExpression("o()", s1,
-				ReactionEffect.class.getSimpleName());
+		model = super.parseExpression("o()", s1, ReactionEffect.class.getSimpleName());
 		result = tester.validate(model);
 		result.assertOK();
 
-		model = super.parseExpression("if.a", s2,
-				ReactionEffect.class.getSimpleName());
+		model = super.parseExpression("if.a", s2, ReactionEffect.class.getSimpleName());
 		result = tester.validate(model);
 		result.assertError(FEATURE_CALL_HAS_NO_EFFECT);
 
-		model = super.parseExpression("valueof(if.e)", s2,
-				ReactionEffect.class.getSimpleName());
+		model = super.parseExpression("valueof(if.e)", s2, ReactionEffect.class.getSimpleName());
 		result = tester.validate(model);
 		result.assertError(FEATURE_CALL_HAS_NO_EFFECT);
 
-		model = super.parseExpression("if.o", s2,
-				ReactionEffect.class.getSimpleName());
+		model = super.parseExpression("if.o", s2, ReactionEffect.class.getSimpleName());
 		result = tester.validate(model);
 		result.assertOK();
 
@@ -372,20 +330,17 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 	@Test
 	public void checkEventDefinition() {
 		// No local declarations in interface scope
-		EObject model = super.parseExpression(
-				"interface MyInterface: event Event1", null,
+		EObject model = super.parseExpression("interface MyInterface: event Event1", null,
 				InterfaceScope.class.getSimpleName());
 		AssertableDiagnostics result = tester.validate(model);
 		result.assertErrorContains(LOCAL_DECLARATIONS);
 		// No in declarations in internal scope
-		model = super.parseExpression("internal: in event Event1", null,
-				InternalScope.class.getSimpleName());
+		model = super.parseExpression("internal: in event Event1", null, InternalScope.class.getSimpleName());
 		result = tester.validate(model);
 		result.assertDiagnosticsCount(1);
 		result.assertErrorContains(STextJavaValidator.IN_OUT_DECLARATIONS);
 		// No out declarations in internal scope
-		model = super.parseExpression("internal: out event Event1", null,
-				InternalScope.class.getSimpleName());
+		model = super.parseExpression("internal: out event Event1", null, InternalScope.class.getSimpleName());
 		result = tester.validate(model);
 		result.assertDiagnosticsCount(1);
 		result.assertErrorContains(IN_OUT_DECLARATIONS);
@@ -396,13 +351,11 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 	 */
 	@Test
 	public void checkInterfaceScope() {
-		EObject model = super.parseExpression(
-				"interface: in event event1 interface: in event event2", null,
+		EObject model = super.parseExpression("interface: in event event1 interface: in event event2", null,
 				StatechartSpecification.class.getSimpleName());
 		AssertableDiagnostics result = tester.validate(model);
 		result.assertDiagnosticsCount(2);
-		result.assertAll(errorCode(ONLY_ONE_INTERFACE),
-				errorCode(ONLY_ONE_INTERFACE));
+		result.assertAll(errorCode(ONLY_ONE_INTERFACE), errorCode(ONLY_ONE_INTERFACE));
 	}
 
 	/**
@@ -435,8 +388,7 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 	 */
 	@Test
 	public void testAllChecksHaveTests() throws Exception {
-		Iterable<Method> methods = Lists.newArrayList(STextJavaValidator.class
-				.getDeclaredMethods());
+		Iterable<Method> methods = Lists.newArrayList(STextJavaValidator.class.getDeclaredMethods());
 		methods = Iterables.filter(methods, new Predicate<Method>() {
 			public boolean apply(Method input) {
 				return input.getAnnotation(Check.class) != null;
@@ -444,24 +396,19 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 		});
 		for (Method checkMethod : methods) {
 			Method testMethod = getClass().getMethod(checkMethod.getName());
-			assertNotNull(
-					"Missing @Test Annotation for method "
-							+ checkMethod.getName(),
+			assertNotNull("Missing @Test Annotation for method " + checkMethod.getName(),
 					testMethod.getAnnotation(Test.class));
 		}
 	}
 
 	@Test
 	public void checkUnusedEntry() {
-		statechart = AbstractTestModelsUtil
-				.loadStatechart(VALIDATION_TESTMODEL_DIR
-						+ "UnusedEntryPoint.sct");
+		statechart = AbstractTestModelsUtil.loadStatechart(VALIDATION_TESTMODEL_DIR + "UnusedEntryPoint.sct");
 		Iterator<EObject> iter = statechart.eAllContents();
 		while (iter.hasNext()) {
 			EObject element = iter.next();
 			if (element instanceof Entry) {
-				validator.validate(element, diagnostics,
-						new HashMap<Object, Object>());
+				validator.validate(element, diagnostics, new HashMap<Object, Object>());
 			}
 		}
 
@@ -471,15 +418,12 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 
 	@Test
 	public void checkUnusedExit() {
-		statechart = AbstractTestModelsUtil
-				.loadStatechart(VALIDATION_TESTMODEL_DIR
-						+ "UnusedExitPoint.sct");
+		statechart = AbstractTestModelsUtil.loadStatechart(VALIDATION_TESTMODEL_DIR + "UnusedExitPoint.sct");
 		Iterator<EObject> iter = statechart.eAllContents();
 		while (iter.hasNext()) {
 			EObject element = iter.next();
 			if (element instanceof Exit) {
-				validator.validate(element, diagnostics,
-						new HashMap<Object, Object>());
+				validator.validate(element, diagnostics, new HashMap<Object, Object>());
 			}
 		}
 
@@ -487,15 +431,12 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 		assertError(diagnostics, EXIT_UNUSED);
 
 		resetDiagnostics();
-		statechart = AbstractTestModelsUtil
-				.loadStatechart(VALIDATION_TESTMODEL_DIR
-						+ "UnusedDefaultExitPoint.sct");
+		statechart = AbstractTestModelsUtil.loadStatechart(VALIDATION_TESTMODEL_DIR + "UnusedDefaultExitPoint.sct");
 		iter = statechart.eAllContents();
 		while (iter.hasNext()) {
 			EObject element = iter.next();
 			if (element instanceof Exit) {
-				validator.validate(element, diagnostics,
-						new HashMap<Object, Object>());
+				validator.validate(element, diagnostics, new HashMap<Object, Object>());
 			}
 		}
 
@@ -506,15 +447,13 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 	@Test
 	public void checkTransitionPropertySpec() {
 		// Test source state isn't composite
-		statechart = AbstractTestModelsUtil
-				.loadStatechart(VALIDATION_TESTMODEL_DIR
-						+ "TransitionEntrySpecNotComposite.sct");
+		statechart = AbstractTestModelsUtil.loadStatechart(VALIDATION_TESTMODEL_DIR
+				+ "TransitionEntrySpecNotComposite.sct");
 		Iterator<EObject> iter = statechart.eAllContents();
 		while (iter.hasNext()) {
 			EObject element = iter.next();
 			if (element instanceof Transition) {
-				assertTrue(validator.validate(element, diagnostics,
-						new HashMap<Object, Object>()));
+				assertTrue(validator.validate(element, diagnostics, new HashMap<Object, Object>()));
 			}
 		}
 		// Test target state isn't composite
@@ -522,16 +461,14 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 		assertWarning(diagnostics, TRANSITION_ENTRY_SPEC_NOT_COMPOSITE);
 
 		resetDiagnostics();
-		statechart = AbstractTestModelsUtil
-				.loadStatechart(VALIDATION_TESTMODEL_DIR
-						+ "TransitionExitSpecNotComposite.sct");
+		statechart = AbstractTestModelsUtil.loadStatechart(VALIDATION_TESTMODEL_DIR
+				+ "TransitionExitSpecNotComposite.sct");
 		iter = statechart.eAllContents();
 
 		while (iter.hasNext()) {
 			EObject element = iter.next();
 			if (element instanceof Transition) {
-				assertTrue(validator.validate(element, diagnostics,
-						new HashMap<Object, Object>()));
+				assertTrue(validator.validate(element, diagnostics, new HashMap<Object, Object>()));
 			}
 		}
 
@@ -540,15 +477,13 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 
 		// Test exit spec is used on multiple transition siblings.
 		resetDiagnostics();
-		statechart = AbstractTestModelsUtil
-				.loadStatechart(VALIDATION_TESTMODEL_DIR
-						+ "TransitionExitSpecOnMultipleSiblings.sct");
+		statechart = AbstractTestModelsUtil.loadStatechart(VALIDATION_TESTMODEL_DIR
+				+ "TransitionExitSpecOnMultipleSiblings.sct");
 		iter = statechart.eAllContents();
 		while (iter.hasNext()) {
 			EObject element = iter.next();
 			if (element instanceof Transition) {
-				assertTrue(validator.validate(element, diagnostics,
-						new HashMap<Object, Object>()));
+				assertTrue(validator.validate(element, diagnostics, new HashMap<Object, Object>()));
 			}
 		}
 
@@ -557,15 +492,13 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 
 		// Test transition unbound named exit point spec.
 		resetDiagnostics();
-		statechart = AbstractTestModelsUtil
-				.loadStatechart(VALIDATION_TESTMODEL_DIR
-						+ "TransitionNotExistingNamedExitPoint.sct");
+		statechart = AbstractTestModelsUtil.loadStatechart(VALIDATION_TESTMODEL_DIR
+				+ "TransitionNotExistingNamedExitPoint.sct");
 		iter = statechart.eAllContents();
 		while (iter.hasNext()) {
 			EObject element = iter.next();
 			if (element instanceof Transition) {
-				validator.validate(element, diagnostics,
-						new HashMap<Object, Object>());
+				validator.validate(element, diagnostics, new HashMap<Object, Object>());
 			}
 		}
 
@@ -575,9 +508,7 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 
 	@Test
 	public void checkUnboundEntryPoints() {
-		statechart = AbstractTestModelsUtil
-				.loadStatechart(VALIDATION_TESTMODEL_DIR
-						+ "UnboundDefaultEntryPoints.sct");
+		statechart = AbstractTestModelsUtil.loadStatechart(VALIDATION_TESTMODEL_DIR + "UnboundDefaultEntryPoints.sct");
 		Iterator<EObject> iter = statechart.eAllContents();
 
 		// create and add triggers to all transitions to prevent to trigger
@@ -589,12 +520,10 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 			EObject element = iter.next();
 			if (element instanceof Transition) {
 				((Transition) element).setTrigger(trigger);
-				validator.validate(element, diagnostics,
-						new HashMap<Object, Object>());
+				validator.validate(element, diagnostics, new HashMap<Object, Object>());
 			}
 			if (element instanceof State) {
-				validator.validate(element, diagnostics,
-						new HashMap<Object, Object>());
+				validator.validate(element, diagnostics, new HashMap<Object, Object>());
 			}
 		}
 
@@ -603,21 +532,17 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 		assertError(diagnostics, REGION_UNBOUND_DEFAULT_ENTRY_POINT);
 
 		resetDiagnostics();
-		statechart = AbstractTestModelsUtil
-				.loadStatechart(VALIDATION_TESTMODEL_DIR
-						+ "UnboundEntryPoints02.sct");
+		statechart = AbstractTestModelsUtil.loadStatechart(VALIDATION_TESTMODEL_DIR + "UnboundEntryPoints02.sct");
 		iter = statechart.eAllContents();
 
 		while (iter.hasNext()) {
 			EObject element = iter.next();
 			if (element instanceof Transition) {
 				((Transition) element).setTrigger(trigger);
-				validator.validate(element, diagnostics,
-						new HashMap<Object, Object>());
+				validator.validate(element, diagnostics, new HashMap<Object, Object>());
 			}
 			if (element instanceof State) {
-				validator.validate(element, diagnostics,
-						new HashMap<Object, Object>());
+				validator.validate(element, diagnostics, new HashMap<Object, Object>());
 			}
 		}
 		assertIssueCount(diagnostics, 4);
@@ -625,40 +550,47 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 
 	@Test
 	public void checkExitPointSpecWithTrigger() {
-		statechart = AbstractTestModelsUtil
-				.loadStatechart(VALIDATION_TESTMODEL_DIR
-						+ "NoTriggerOnTransitionWithExitPointSpec.sct");
+		statechart = AbstractTestModelsUtil.loadStatechart(VALIDATION_TESTMODEL_DIR
+				+ "NoTriggerOnTransitionWithExitPointSpec.sct");
 		Iterator<EObject> iter = statechart.eAllContents();
 		while (iter.hasNext()) {
 			EObject element = iter.next();
 			if (element instanceof Transition) {
-				validator.validate(element, diagnostics,
-						new HashMap<Object, Object>());
+				validator.validate(element, diagnostics, new HashMap<Object, Object>());
 			}
 		}
 
 		assertIssueCount(diagnostics, 2);
 		assertError(diagnostics, EXITPOINTSPEC_WITH_TRIGGER);
 	}
-	
+
 	@Test
 	public void checkAssignmentToFinalVariable() {
-		Statechart statechart = AbstractTestModelsUtil
-				.loadStatechart(VALIDATION_TESTMODEL_DIR + "AssignmentToValue.sct");
+		Statechart statechart = AbstractTestModelsUtil.loadStatechart(VALIDATION_TESTMODEL_DIR
+				+ "AssignmentToValue.sct");
 		Diagnostic diagnostics = Diagnostician.INSTANCE.validate(statechart);
 		assertIssueCount(diagnostics, 2);
 		assertError(diagnostics, ASSIGNMENT_TO_VALUE);
 	}
-	
+
 	@Test
 	public void checkValueDefinitionExpression() {
-		Statechart statechart = AbstractTestModelsUtil
-				.loadStatechart(VALIDATION_TESTMODEL_DIR + "ValueWithVariable.sct");
+		Statechart statechart = AbstractTestModelsUtil.loadStatechart(VALIDATION_TESTMODEL_DIR
+				+ "ValueWithVariable.sct");
 		Diagnostic diagnostics = Diagnostician.INSTANCE.validate(statechart);
 		assertIssueCount(diagnostics, 2);
 		assertError(diagnostics, REFERENCE_TO_VARIABLE);
 	}
 
+	@Test
+	public void checkValueReferenedBeforeDefined() {
+		Statechart statechart = AbstractTestModelsUtil.loadStatechart(VALIDATION_TESTMODEL_DIR
+				+ "ReferenceBeforeDefined.sct");
+		Diagnostic diagnostics = Diagnostician.INSTANCE.validate(statechart);
+		assertIssueCount(diagnostics, 2);
+		assertError(diagnostics, REFERENCE_CONSTANT_BEFORE_DEFINED);
+	}
+
 	/**
 	 * Show warning when transition has no guard
 	 */
@@ -709,46 +641,39 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 
 		// transitions from entry point to State A -> valid model with no
 		// warnings
-		assertTrue(validator.validate(eToF, diagnostics,
-				new HashMap<Object, Object>()));
+		assertTrue(validator.validate(eToF, diagnostics, new HashMap<Object, Object>()));
 		assertIssueCount(diagnostics, 0);
 
 		// transitions from entry point to State A -> valid model with no
 		// warnings
-		assertTrue(validator.validate(entryToA, diagnostics,
-				new HashMap<Object, Object>()));
+		assertTrue(validator.validate(entryToA, diagnostics, new HashMap<Object, Object>()));
 		assertIssueCount(diagnostics, 0);
 
 		// transition from StateA to StateB -> valid model with warnings expect
 		// 1 warning in total
-		assertTrue(validator.validate(aToB, diagnostics,
-				new HashMap<Object, Object>()));
+		assertTrue(validator.validate(aToB, diagnostics, new HashMap<Object, Object>()));
 		assertIssueCount(diagnostics, 1);
 		resetDiagnostics();
 
 		// transition from EntryB to StateBB -> valid model with no warnings
 		// expect 1 warning in total
-		assertTrue(validator.validate(entryBToBB, diagnostics,
-				new HashMap<Object, Object>()));
+		assertTrue(validator.validate(entryBToBB, diagnostics, new HashMap<Object, Object>()));
 		assertIssueCount(diagnostics, 0);
 
 		// transition from BB to ExitB -> valid model with warnings expect 2
 		// warning in total
-		assertTrue(validator.validate(bbToExitB, diagnostics,
-				new HashMap<Object, Object>()));
+		assertTrue(validator.validate(bbToExitB, diagnostics, new HashMap<Object, Object>()));
 		assertIssueCount(diagnostics, 1);
 		resetDiagnostics();
 
 		// transition from B to C -> valid model with no warning warnings expect
 		// 2 warning in total
-		assertTrue(validator.validate(bToC, diagnostics,
-				new HashMap<Object, Object>()));
+		assertTrue(validator.validate(bToC, diagnostics, new HashMap<Object, Object>()));
 		assertIssueCount(diagnostics, 0);
 
 		// transition from C to D -> valid model with warning warning expect 3
 		// warning in total
-		assertTrue(validator.validate(cToD, diagnostics,
-				new HashMap<Object, Object>()));
+		assertTrue(validator.validate(cToD, diagnostics, new HashMap<Object, Object>()));
 		assertIssueCount(diagnostics, 1);
 		resetDiagnostics();
 
@@ -763,15 +688,13 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 	 */
 	@Test
 	public void validEmptyTransitionFromSync() {
-		statechart = AbstractTestModelsUtil
-				.loadStatechart(VALIDATION_TESTMODEL_DIR
-						+ "ValidEmptyTransitionFromSync.sct");
+		statechart = AbstractTestModelsUtil.loadStatechart(VALIDATION_TESTMODEL_DIR
+				+ "ValidEmptyTransitionFromSync.sct");
 		Iterator<EObject> iter = statechart.eAllContents();
 		while (iter.hasNext()) {
 			EObject element = iter.next();
 			if (element instanceof Transition) {
-				validator.validate(element, diagnostics,
-						new HashMap<Object, Object>());
+				validator.validate(element, diagnostics, new HashMap<Object, Object>());
 			}
 		}
 
@@ -780,12 +703,10 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 
 	@Test
 	public void checkImportExists() {
-		ImportScope importScope = (ImportScope) parseExpression(
-				"import: not.existing.*", null,
+		ImportScope importScope = (ImportScope) parseExpression("import: not.existing.*", null,
 				ImportScope.class.getSimpleName());
 
-		AssertableDiagnostics validationResult = tester.validate(importScope
-				.getImports().get(0));
+		AssertableDiagnostics validationResult = tester.validate(importScope.getImports().get(0));
 		validationResult.assertError(STextJavaValidator.IMPORT_NOT_RESOLVED);
 	}
 
@@ -800,24 +721,19 @@ public class STextJavaValidatorTest extends AbstractSTextTest implements STextVa
 
 	protected void assertError(Diagnostic diag, String message) {
 		Diagnostic d = issueByName(diag, message);
-		assertNotNull("Issue '" + message + "' does not exist.",
-				issueByName(diag, message));
-		assertEquals("Issue '" + message + "' is no error.", Diagnostic.ERROR,
-				d.getSeverity());
+		assertNotNull("Issue '" + message + "' does not exist.", issueByName(diag, message));
+		assertEquals("Issue '" + message + "' is no error.", Diagnostic.ERROR, d.getSeverity());
 	}
 
 	protected void assertWarning(Diagnostic diag, String message) {
 		Diagnostic d = issueByName(diag, message);
-		assertNotNull("Issue '" + message + "' does not exist.",
-				issueByName(diag, message));
-		assertEquals("Issue '" + message + "' is no warning.",
-				Diagnostic.WARNING, d.getSeverity());
+		assertNotNull("Issue '" + message + "' does not exist.", issueByName(diag, message));
+		assertEquals("Issue '" + message + "' is no warning.", Diagnostic.WARNING, d.getSeverity());
 	}
 
 	protected void assertIssueCount(Diagnostic diag, int count) {
 		int c = diag.getChildren().size();
-		assertEquals("expected " + count + " issue(s) but were " + c + " ["
-				+ diag.toString() + "]", count, c);
+		assertEquals("expected " + count + " issue(s) but were " + c + " [" + diag.toString() + "]", count, c);
 	}
 
 	protected Diagnostic issueByName(Diagnostic diag, String message) {

+ 72 - 0
test-plugins/org.yakindu.sct.test.models/testmodels/validation/ReferenceBeforeDefined.sct

@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:sgraph="http://www.yakindu.org/sct/sgraph/2.0.0">
+  <sgraph:Statechart xmi:id="_5VSggG_lEeSjUp1iSfPc3g" specification="internal:&#xD;&#xA;val x : integer = y&#xD;&#xA;val y :integer =10&#xD;&#xA;&#xD;&#xA;interface ABC:&#xD;&#xA;val x : string = ABC.y&#xD;&#xA;val y : string = ABC.x" name="ReferenceBeforeDefined">
+    <regions xmi:id="_5VU8wW_lEeSjUp1iSfPc3g" name="main region">
+      <vertices xsi:type="sgraph:Entry" xmi:id="_5VZOM2_lEeSjUp1iSfPc3g">
+        <outgoingTransitions xmi:id="_5VcRgW_lEeSjUp1iSfPc3g" target="_5VacVG_lEeSjUp1iSfPc3g"/>
+      </vertices>
+      <vertices xsi:type="sgraph:State" xmi:id="_5VacVG_lEeSjUp1iSfPc3g" name="A" incomingTransitions="_5VcRgW_lEeSjUp1iSfPc3g"/>
+    </regions>
+  </sgraph:Statechart>
+  <notation:Diagram xmi:id="_5VUVsG_lEeSjUp1iSfPc3g" type="org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor" element="_5VSggG_lEeSjUp1iSfPc3g" measurementUnit="Pixel">
+    <children xmi:id="_5VWx8G_lEeSjUp1iSfPc3g" type="Region" element="_5VU8wW_lEeSjUp1iSfPc3g">
+      <children xsi:type="notation:DecorationNode" xmi:id="_5VYnIG_lEeSjUp1iSfPc3g" type="RegionName">
+        <styles xsi:type="notation:ShapeStyle" xmi:id="_5VYnIW_lEeSjUp1iSfPc3g"/>
+        <layoutConstraint xsi:type="notation:Location" xmi:id="_5VYnIm_lEeSjUp1iSfPc3g"/>
+      </children>
+      <children xsi:type="notation:Shape" xmi:id="_5VZOMG_lEeSjUp1iSfPc3g" type="RegionCompartment" fontName="Verdana" lineColor="4210752">
+        <children xmi:id="_5VZ1QG_lEeSjUp1iSfPc3g" type="Entry" element="_5VZOM2_lEeSjUp1iSfPc3g">
+          <children xmi:id="_5VZ1Q2_lEeSjUp1iSfPc3g" type="BorderItemLabelContainer">
+            <children xsi:type="notation:DecorationNode" xmi:id="_5VacUG_lEeSjUp1iSfPc3g" type="BorderItemLabel">
+              <styles xsi:type="notation:ShapeStyle" xmi:id="_5VacUW_lEeSjUp1iSfPc3g"/>
+              <layoutConstraint xsi:type="notation:Location" xmi:id="_5VacUm_lEeSjUp1iSfPc3g"/>
+            </children>
+            <styles xsi:type="notation:ShapeStyle" xmi:id="_5VZ1RG_lEeSjUp1iSfPc3g" fontName="Verdana" lineColor="4210752"/>
+            <layoutConstraint xsi:type="notation:Bounds" xmi:id="_5VZ1RW_lEeSjUp1iSfPc3g"/>
+          </children>
+          <styles xsi:type="notation:ShapeStyle" xmi:id="_5VZ1QW_lEeSjUp1iSfPc3g" fontName="Verdana" lineColor="4210752"/>
+          <layoutConstraint xsi:type="notation:Bounds" xmi:id="_5VacU2_lEeSjUp1iSfPc3g" x="70" y="20"/>
+        </children>
+        <children xmi:id="_5VbDYW_lEeSjUp1iSfPc3g" type="State" element="_5VacVG_lEeSjUp1iSfPc3g">
+          <children xsi:type="notation:DecorationNode" xmi:id="_5VbDZW_lEeSjUp1iSfPc3g" type="StateName">
+            <styles xsi:type="notation:ShapeStyle" xmi:id="_5VbDZm_lEeSjUp1iSfPc3g"/>
+            <layoutConstraint xsi:type="notation:Location" xmi:id="_5VbDZ2_lEeSjUp1iSfPc3g"/>
+          </children>
+          <children xsi:type="notation:Compartment" xmi:id="_5VbqcG_lEeSjUp1iSfPc3g" type="StateTextCompartment">
+            <children xsi:type="notation:Shape" xmi:id="_5VbqcW_lEeSjUp1iSfPc3g" type="StateTextCompartmentExpression" fontName="Verdana" lineColor="4210752">
+              <layoutConstraint xsi:type="notation:Bounds" xmi:id="_5Vbqcm_lEeSjUp1iSfPc3g"/>
+            </children>
+          </children>
+          <children xsi:type="notation:Compartment" xmi:id="_5Vbqc2_lEeSjUp1iSfPc3g" type="StateFigureCompartment"/>
+          <styles xsi:type="notation:ShapeStyle" xmi:id="_5VbDYm_lEeSjUp1iSfPc3g" fontName="Verdana" fillColor="15981773" lineColor="12632256"/>
+          <styles xsi:type="notation:FontStyle" xmi:id="_5VbDY2_lEeSjUp1iSfPc3g"/>
+          <styles xsi:type="notation:BooleanValueStyle" xmi:id="_5VbqdG_lEeSjUp1iSfPc3g" name="isHorizontal" booleanValue="true"/>
+          <layoutConstraint xsi:type="notation:Bounds" xmi:id="_5VcRgG_lEeSjUp1iSfPc3g" x="40" y="80"/>
+        </children>
+        <layoutConstraint xsi:type="notation:Bounds" xmi:id="_5VZOMW_lEeSjUp1iSfPc3g"/>
+      </children>
+      <styles xsi:type="notation:ShapeStyle" xmi:id="_5VWx8W_lEeSjUp1iSfPc3g" fontName="Verdana" fillColor="15790320" lineColor="12632256"/>
+      <layoutConstraint xsi:type="notation:Bounds" xmi:id="_5VZOMm_lEeSjUp1iSfPc3g" x="220" y="10" width="400" height="400"/>
+    </children>
+    <children xsi:type="notation:Shape" xmi:id="_5VdfpG_lEeSjUp1iSfPc3g" type="StatechartText" fontName="Verdana" lineColor="4210752">
+      <children xsi:type="notation:DecorationNode" xmi:id="_5VeGsG_lEeSjUp1iSfPc3g" type="StatechartName">
+        <styles xsi:type="notation:ShapeStyle" xmi:id="_5VeGsW_lEeSjUp1iSfPc3g"/>
+        <layoutConstraint xsi:type="notation:Location" xmi:id="_5VeGsm_lEeSjUp1iSfPc3g"/>
+      </children>
+      <children xsi:type="notation:Shape" xmi:id="_5VeGs2_lEeSjUp1iSfPc3g" type="StatechartTextExpression" fontName="Verdana" lineColor="4210752">
+        <layoutConstraint xsi:type="notation:Bounds" xmi:id="_5VeGtG_lEeSjUp1iSfPc3g"/>
+      </children>
+      <layoutConstraint xsi:type="notation:Bounds" xmi:id="_5VetwG_lEeSjUp1iSfPc3g" x="10" y="10" width="200" height="400"/>
+    </children>
+    <styles xsi:type="notation:DiagramStyle" xmi:id="_5VU8wG_lEeSjUp1iSfPc3g"/>
+    <edges xmi:id="_5Vc4kG_lEeSjUp1iSfPc3g" type="Transition" element="_5VcRgW_lEeSjUp1iSfPc3g" source="_5VZ1QG_lEeSjUp1iSfPc3g" target="_5VbDYW_lEeSjUp1iSfPc3g">
+      <children xsi:type="notation:DecorationNode" xmi:id="_5VdfoW_lEeSjUp1iSfPc3g" type="TransitionExpression">
+        <styles xsi:type="notation:ShapeStyle" xmi:id="_5Vdfom_lEeSjUp1iSfPc3g"/>
+        <layoutConstraint xsi:type="notation:Location" xmi:id="_5Vdfo2_lEeSjUp1iSfPc3g" y="10"/>
+      </children>
+      <styles xsi:type="notation:ConnectorStyle" xmi:id="_5Vc4kW_lEeSjUp1iSfPc3g" lineColor="4210752"/>
+      <styles xsi:type="notation:FontStyle" xmi:id="_5VdfoG_lEeSjUp1iSfPc3g" fontName="Verdana"/>
+      <bendpoints xsi:type="notation:RelativeBendpoints" xmi:id="_5Vc4km_lEeSjUp1iSfPc3g" points="[0, 0, 0, 0]$[0, 0, 0, 0]"/>
+    </edges>
+  </notation:Diagram>
+</xmi:XMI>