Browse Source

Added validation to check that only one default interface exists.

markus.muehlbrandt@itemis.de 13 years ago
parent
commit
1fad046d61

+ 1 - 1
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/GenerateExpressions.mwe2

@@ -59,7 +59,7 @@ Workflow {
 			// java-based API for validation 
 			fragment = validation.JavaValidatorFragment {
 				composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
-				 composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
+				composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
 				// registerForImportedPackages = true
 			}
 

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

@@ -120,14 +120,14 @@ public class STextJavaValidator extends AbstractSTextJavaValidator {
 
 	@Check(CheckType.FAST)
 	public void checkInterfaceScope(InterfaceScope interfaceScope) {
-		if (getInterfaceCount(interfaceScope) > 1) {
+		if (getNotNamedInterfaceCount(interfaceScope) > 1) {
 			error("It can only exist one default/unamed interface",
 					interfaceScope,
 					StextPackage.Literals.INTERFACE_SCOPE__NAME,
 					ValidationMessageAcceptor.INSIGNIFICANT_INDEX);
 		}
 	}
-
+	
 	private boolean isStatechartDefinitionChild(EObject element) {
 		while (element.eContainer() != null) {
 			if (element.eContainer() instanceof StatechartDefinition) {
@@ -137,14 +137,14 @@ public class STextJavaValidator extends AbstractSTextJavaValidator {
 		}
 		return false;
 	}
-
-	private int getInterfaceCount(InterfaceScope interfaceScope) {
-		int count = 1;
+	
+	private int getNotNamedInterfaceCount(InterfaceScope interfaceScope) {
+		int count = 0;
 		if (interfaceScope.eContainer() instanceof Statechart) {
 			Statechart statechart = (Statechart) interfaceScope.eContainer();
 
 			for (Scope scope : statechart.getScopes()) {
-				if (scope != interfaceScope && scope instanceof InterfaceScope
+				if (scope instanceof InterfaceScope
 						&& ((InterfaceScope) scope).getName() == null) {
 					count++;
 				}