Browse Source

Move isDefault() method utils to model and trim whitespaces (#2133)

Fixes #1837
Thomas Kutz 7 years ago
parent
commit
5b53ccf8a0

+ 3 - 1
plugins/org.yakindu.sct.model.sgraph/model/emf/sgraph.ecore

@@ -2,7 +2,9 @@
 <ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 <ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="sgraph" nsURI="http://www.yakindu.org/sct/sgraph/2.0.0" nsPrefix="sgraph">
     xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="sgraph" nsURI="http://www.yakindu.org/sct/sgraph/2.0.0" nsPrefix="sgraph">
   <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"/>
   <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"/>
-  <eClassifiers xsi:type="ecore:EClass" name="Pseudostate" abstract="true" eSuperTypes="#//Vertex"/>
+  <eClassifiers xsi:type="ecore:EClass" name="Pseudostate" abstract="true" eSuperTypes="#//Vertex">
+    <eOperations name="isDefault" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
+  </eClassifiers>
   <eClassifiers xsi:type="ecore:EClass" name="Vertex" abstract="true" eSuperTypes="../../../org.yakindu.base.types/model/base.ecore#//NamedElement">
   <eClassifiers xsi:type="ecore:EClass" name="Vertex" abstract="true" eSuperTypes="../../../org.yakindu.base.types/model/base.ecore#//NamedElement">
     <eStructuralFeatures xsi:type="ecore:EReference" name="parentRegion" ordered="false"
     <eStructuralFeatures xsi:type="ecore:EReference" name="parentRegion" ordered="false"
         lowerBound="1" eType="#//Region" eOpposite="#//Region/vertices"/>
         lowerBound="1" eType="#//Region" eOpposite="#//Region/vertices"/>

+ 8 - 0
plugins/org.yakindu.sct.model.sgraph/src/org/yakindu/sct/model/sgraph/Pseudostate.java

@@ -29,4 +29,12 @@ public interface Pseudostate extends Vertex {
 	 */
 	 */
 	String copyright = "Copyright (c) 2011 committers of YAKINDU and others.\r\nAll rights reserved. This program and the accompanying materials\r\nare made available under the terms of the Eclipse Public License v1.0\r\nwhich accompanies this distribution, and is available at\r\nhttp://www.eclipse.org/legal/epl-v10.html\r\nContributors:\r\ncommitters of YAKINDU - initial API and implementation\r\n";
 	String copyright = "Copyright (c) 2011 committers of YAKINDU and others.\r\nAll rights reserved. This program and the accompanying materials\r\nare made available under the terms of the Eclipse Public License v1.0\r\nwhich accompanies this distribution, and is available at\r\nhttp://www.eclipse.org/legal/epl-v10.html\r\nContributors:\r\ncommitters of YAKINDU - initial API and implementation\r\n";
 
 
+	/**
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @model kind="operation"
+	 * @generated
+	 */
+	boolean isDefault();
+
 } // Pseudostate
 } // Pseudostate

+ 24 - 0
plugins/org.yakindu.sct.model.sgraph/src/org/yakindu/sct/model/sgraph/impl/PseudostateImpl.java

@@ -48,4 +48,28 @@ public abstract class PseudostateImpl extends VertexImpl implements Pseudostate
 		return SGraphPackage.Literals.PSEUDOSTATE;
 		return SGraphPackage.Literals.PSEUDOSTATE;
 	}
 	}
 
 
+	/**
+	 * Checks if the name of the given element matches the requirements to be a
+	 * 'default' element.
+	 *
+	 * @param element
+	 *            - the {@link NamedElement}
+	 * @return {@code true} if the name is null, empty or equals 'default' (ignoring
+	 *         case).
+	 */
+	
+	
+	/**
+	 * Checks if the name matches the requirements to be a 'default' element.
+	 *
+	 * @return {@code true} if the name is null, empty or equals 'default'
+	 *         (ignoring case and after whitespace trimming).
+	 * 
+	 * @generated NOT
+	 */
+	public boolean isDefault() {
+		return getName() == null
+				|| (getName() != null && (getName().trim().isEmpty() || getName().trim().equalsIgnoreCase("default")));
+	}
+
 } //PseudostateImpl
 } //PseudostateImpl

+ 3 - 1
plugins/org.yakindu.sct.model.sgraph/src/org/yakindu/sct/model/sgraph/impl/SGraphPackageImpl.java

@@ -947,6 +947,8 @@ public class SGraphPackageImpl extends EPackageImpl implements SGraphPackage {
 		// Initialize classes and features; add operations and parameters
 		// Initialize classes and features; add operations and parameters
 		initEClass(pseudostateEClass, Pseudostate.class, "Pseudostate", IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
 		initEClass(pseudostateEClass, Pseudostate.class, "Pseudostate", IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
 
 
+		addEOperation(pseudostateEClass, ecorePackage.getEBoolean(), "isDefault", 0, 1, IS_UNIQUE, IS_ORDERED);
+
 		initEClass(vertexEClass, Vertex.class, "Vertex", IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
 		initEClass(vertexEClass, Vertex.class, "Vertex", IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
 		initEReference(getVertex_ParentRegion(), this.getRegion(), this.getRegion_Vertices(), "parentRegion", null, 1, 1, Vertex.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, !IS_ORDERED);
 		initEReference(getVertex_ParentRegion(), this.getRegion(), this.getRegion_Vertices(), "parentRegion", null, 1, 1, Vertex.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, !IS_ORDERED);
 		initEReference(getVertex_IncomingTransitions(), this.getTransition(), this.getTransition_Target(), "incomingTransitions", null, 0, -1, Vertex.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, !IS_ORDERED);
 		initEReference(getVertex_IncomingTransitions(), this.getTransition(), this.getTransition_Target(), "incomingTransitions", null, 0, -1, Vertex.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, !IS_ORDERED);
@@ -994,7 +996,7 @@ public class SGraphPackageImpl extends EPackageImpl implements SGraphPackage {
 		initEReference(getScope_Declarations(), theTypesPackage.getDeclaration(), null, "declarations", null, 0, -1, Scope.class, IS_TRANSIENT, IS_VOLATILE, !IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, IS_DERIVED, IS_ORDERED);
 		initEReference(getScope_Declarations(), theTypesPackage.getDeclaration(), null, "declarations", null, 0, -1, Scope.class, IS_TRANSIENT, IS_VOLATILE, !IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, IS_DERIVED, IS_ORDERED);
 		initEReference(getScope_Events(), theTypesPackage.getEvent(), null, "events", null, 0, -1, Scope.class, IS_TRANSIENT, IS_VOLATILE, !IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, IS_DERIVED, IS_ORDERED);
 		initEReference(getScope_Events(), theTypesPackage.getEvent(), null, "events", null, 0, -1, Scope.class, IS_TRANSIENT, IS_VOLATILE, !IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, IS_DERIVED, IS_ORDERED);
 		initEReference(getScope_Variables(), theTypesPackage.getProperty(), null, "variables", null, 0, -1, Scope.class, IS_TRANSIENT, IS_VOLATILE, !IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, !IS_UNIQUE, IS_DERIVED, IS_ORDERED);
 		initEReference(getScope_Variables(), theTypesPackage.getProperty(), null, "variables", null, 0, -1, Scope.class, IS_TRANSIENT, IS_VOLATILE, !IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, !IS_UNIQUE, IS_DERIVED, IS_ORDERED);
-		initEReference(getScope_Reactions(), this.getReaction(), null, "reactions", null, 0, -1, Scope.class, IS_TRANSIENT, IS_VOLATILE, !IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
+		initEReference(getScope_Reactions(), this.getReaction(), null, "reactions", null, 0, -1, Scope.class, IS_TRANSIENT, IS_VOLATILE, !IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, IS_DERIVED, IS_ORDERED);
 		initEReference(getScope_Members(), ecorePackage.getEObject(), null, "members", null, 0, -1, Scope.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
 		initEReference(getScope_Members(), ecorePackage.getEObject(), null, "members", null, 0, -1, Scope.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
 
 
 		initEClass(scopedElementEClass, ScopedElement.class, "ScopedElement", IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
 		initEClass(scopedElementEClass, ScopedElement.class, "ScopedElement", IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);

+ 4 - 7
plugins/org.yakindu.sct.model.sgraph/src/org/yakindu/sct/model/sgraph/validation/RegionValidator.java

@@ -52,12 +52,9 @@ public class RegionValidator extends AbstractSGraphValidator {
 			for (Region r : regions) {
 			for (Region r : regions) {
 				Entry defaultEntry = null;
 				Entry defaultEntry = null;
 				for (Vertex v : r.getVertices()) {
 				for (Vertex v : r.getVertices()) {
-					if (v instanceof Entry) {
-						String name = v.getName().trim().toLowerCase();
-						if (name != null || "".equals(name) || "default".equals(name)) {
-							defaultEntry = (Entry) v;
-							break;
-						}
+					if (v instanceof Entry && ((Entry) v).isDefault()) {
+						defaultEntry = (Entry) v;
+						break;
 					}
 					}
 				}
 				}
 				if (defaultEntry == null) {
 				if (defaultEntry == null) {
@@ -76,7 +73,7 @@ public class RegionValidator extends AbstractSGraphValidator {
 		Region region = (Region) entry.eContainer();
 		Region region = (Region) entry.eContainer();
 		List<Entry> initialEntires = region.getVertices().stream().filter(Entry.class::isInstance)
 		List<Entry> initialEntires = region.getVertices().stream().filter(Entry.class::isInstance)
 				.map(Entry.class::cast).filter(v -> v.getKind() == EntryKind.INITIAL).collect(Collectors.toList());
 				.map(Entry.class::cast).filter(v -> v.getKind() == EntryKind.INITIAL).collect(Collectors.toList());
-		boolean unamedEntryExists = initialEntires.stream().filter(v -> v.getName().equals("")).count() > 0;
+		boolean unamedEntryExists = initialEntires.stream().filter(v -> v.getName().trim().equals("")).count() > 0;
 		boolean defaultNamedEntryExists = initialEntires.stream()
 		boolean defaultNamedEntryExists = initialEntires.stream()
 				.filter(v -> v.getName().trim().equalsIgnoreCase("default")).count() > 0;
 				.filter(v -> v.getName().trim().equalsIgnoreCase("default")).count() > 0;
 		if (unamedEntryExists && defaultNamedEntryExists) {
 		if (unamedEntryExists && defaultNamedEntryExists) {

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

@@ -206,7 +206,7 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements ST
 				&& entry.getIncomingTransitions().isEmpty()) {
 				&& entry.getIncomingTransitions().isEmpty()) {
 			org.yakindu.sct.model.sgraph.State state = (org.yakindu.sct.model.sgraph.State) entry.getParentRegion()
 			org.yakindu.sct.model.sgraph.State state = (org.yakindu.sct.model.sgraph.State) entry.getParentRegion()
 					.getComposite();
 					.getComposite();
-			if (!STextValidationModelUtils.isDefault(entry)) {
+			if (!entry.isDefault()) {
 				boolean hasIncomingTransition = false;
 				boolean hasIncomingTransition = false;
 				Iterator<Transition> transitionIt = state.getIncomingTransitions().iterator();
 				Iterator<Transition> transitionIt = state.getIncomingTransitions().iterator();
 				while (transitionIt.hasNext() && !hasIncomingTransition) {
 				while (transitionIt.hasNext() && !hasIncomingTransition) {
@@ -403,7 +403,7 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements ST
 			org.yakindu.sct.model.sgraph.State state = (org.yakindu.sct.model.sgraph.State) exit.getParentRegion()
 			org.yakindu.sct.model.sgraph.State state = (org.yakindu.sct.model.sgraph.State) exit.getParentRegion()
 					.getComposite();
 					.getComposite();
 
 
-			if (!STextValidationModelUtils.isDefault(exit)) {
+			if (!exit.isDefault()) {
 				boolean hasOutgoingTransition = false;
 				boolean hasOutgoingTransition = false;
 				boolean equalsOutgoingTransition = false;
 				boolean equalsOutgoingTransition = false;
 				Iterator<Transition> transitionIt = state.getOutgoingTransitions().iterator();
 				Iterator<Transition> transitionIt = state.getOutgoingTransitions().iterator();
@@ -589,9 +589,8 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements ST
 		Region parentRegion = entry.getParentRegion();
 		Region parentRegion = entry.getParentRegion();
 		// 1. check if is toplevel
 		// 1. check if is toplevel
 		if (isTopLevelRegion(parentRegion)) {
 		if (isTopLevelRegion(parentRegion)) {
-			boolean isDefaultEntry = STextValidationModelUtils.isDefault(entry);
 			// 2. check if is default entry
 			// 2. check if is default entry
-			if (!isDefaultEntry) {
+			if (!entry.isDefault()) {
 				Map<Region, List<Entry>> regionsWithoutDefaultEntry = STextValidationModelUtils
 				Map<Region, List<Entry>> regionsWithoutDefaultEntry = STextValidationModelUtils
 						.getRegionsWithoutDefaultEntry(Lists.newArrayList(parentRegion));
 						.getRegionsWithoutDefaultEntry(Lists.newArrayList(parentRegion));
 				List<Entry> list = regionsWithoutDefaultEntry.get(parentRegion);
 				List<Entry> list = regionsWithoutDefaultEntry.get(parentRegion);

+ 2 - 18
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/validation/STextValidationModelUtils.java

@@ -18,7 +18,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.EObject;
-import org.yakindu.base.base.NamedElement;
 import org.yakindu.sct.model.sgraph.Entry;
 import org.yakindu.sct.model.sgraph.Entry;
 import org.yakindu.sct.model.sgraph.Exit;
 import org.yakindu.sct.model.sgraph.Exit;
 import org.yakindu.sct.model.sgraph.ReactionProperty;
 import org.yakindu.sct.model.sgraph.ReactionProperty;
@@ -116,7 +115,7 @@ public final class STextValidationModelUtils {
 			boolean hasDefaultEntry = false;
 			boolean hasDefaultEntry = false;
 			final List<Entry> entries = getEntries(region.eContents());
 			final List<Entry> entries = getEntries(region.eContents());
 			for (Entry entry : entries) {
 			for (Entry entry : entries) {
-				if (isDefault(entry)) {
+				if (entry.isDefault()) {
 					hasDefaultEntry = true;
 					hasDefaultEntry = true;
 					break;
 					break;
 				}
 				}
@@ -145,7 +144,7 @@ public final class STextValidationModelUtils {
 			final List<Exit> exits = getExits(region.eContents());
 			final List<Exit> exits = getExits(region.eContents());
 			if (!exits.isEmpty()) {
 			if (!exits.isEmpty()) {
 				for (Exit exit : exits) {
 				for (Exit exit : exits) {
-					if (isDefault(exit)) {
+					if (exit.isDefault()) {
 						hasDefaultExit = true;
 						hasDefaultExit = true;
 						break;
 						break;
 					}
 					}
@@ -161,21 +160,6 @@ public final class STextValidationModelUtils {
 		return regions;
 		return regions;
 	}
 	}
 
 
-	/**
-	 * Checks if the name of the given element matches the requirements to be a
-	 * 'default' element.
-	 *
-	 * @param element
-	 *            - the {@link NamedElement}
-	 * @return {@code true} if the name is null, empty or equals 'default' (ignoring
-	 *         case).
-	 */
-	public static boolean isDefault(final NamedElement element) {
-		return element.getName() == null
-				|| (element.getName() != null && (element.getName().isEmpty() || element
-						.getName().equalsIgnoreCase("default")));
-	}
-
 	/**
 	/**
 	 * Validates if the a {@link Transition} has an {@link ExitPointSpec} with the
 	 * Validates if the a {@link Transition} has an {@link ExitPointSpec} with the
 	 * given name.
 	 * given name.