|
@@ -10,20 +10,11 @@
|
|
|
*/
|
|
|
package org.yakindu.sct.model.sgraph.validation;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
import org.eclipse.xtext.validation.Check;
|
|
|
import org.eclipse.xtext.validation.CheckType;
|
|
|
-import org.yakindu.sct.model.sgraph.CompositeElement;
|
|
|
import org.yakindu.sct.model.sgraph.Entry;
|
|
|
import org.yakindu.sct.model.sgraph.EntryKind;
|
|
|
-import org.yakindu.sct.model.sgraph.Exit;
|
|
|
-import org.yakindu.sct.model.sgraph.Region;
|
|
|
-import org.yakindu.sct.model.sgraph.Statechart;
|
|
|
import org.yakindu.sct.model.sgraph.Transition;
|
|
|
-import org.yakindu.sct.model.sgraph.Vertex;
|
|
|
|
|
|
/**
|
|
|
*
|
|
@@ -33,15 +24,6 @@ import org.yakindu.sct.model.sgraph.Vertex;
|
|
|
public class EntryValidator extends AbstractSGraphValidator {
|
|
|
|
|
|
|
|
|
- private static final String REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NO_DEFAULT_ENTRY_MSG = "The region can't be entered using the shallow history. Add a default entry node.";
|
|
|
- public static final String REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NO_DEFAULT_ENTRY_CODE = "entry.region.default";
|
|
|
-
|
|
|
- private static final String REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NON_CONNECTED_DEFAULT_ENTRY_MSG = "The region can't be entered using the shallow history. Add a transition from default entry to a state.";
|
|
|
- public static final String REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NON_CONNECTED_DEFAULT_ENTRY_CODE = "entry.in.transition";
|
|
|
-
|
|
|
- private final static String REGION_MULTIPLE_DEFAULT_ENTRIES_MSG = "There are multiple default entry nodes (one without a name and one named 'default') in this region.";
|
|
|
- public final static String REGION_MULTIPLE_DEFAULT_ENTRIES_CODE = "region.duplicate.entry";
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
@@ -78,7 +60,7 @@ public class EntryValidator extends AbstractSGraphValidator {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private static final String ENTRY_TRANSITIONS_NO_TRIGGER_ON_OUT_MSG = "Outgoing transitions from entry points must not have a trigger or guard.";
|
|
|
+ private static final String ENTRY_TRANSITIONS_NO_TRIGGER_ON_OUT_MSG = "The outgoing transitions of an entry must not have a trigger or guard.";
|
|
|
public static final String ENTRY_TRANSITIONS_NO_TRIGGER_ON_OUT_CODE = "entry.transitions.NoTriggerOnOut";
|
|
|
|
|
|
@Check(CheckType.FAST)
|
|
@@ -90,50 +72,5 @@ public class EntryValidator extends AbstractSGraphValidator {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Check(CheckType.FAST)
|
|
|
- public void regionCantBeEnteredUsingShallowHistory(Entry e) {
|
|
|
- if (e.getKind() == EntryKind.SHALLOW_HISTORY) {
|
|
|
- List<Region> regions = new ArrayList<>();
|
|
|
- for (Vertex v : e.getParentRegion().getVertices()) {
|
|
|
- if (v instanceof CompositeElement) {
|
|
|
- regions.addAll(((CompositeElement) v).getRegions());
|
|
|
- }
|
|
|
- }
|
|
|
- for (Region r : regions) {
|
|
|
- Entry defaultEntry = null;
|
|
|
- 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 (defaultEntry == null) {
|
|
|
- error(REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NO_DEFAULT_ENTRY_MSG, r, null, -1,
|
|
|
- REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NO_DEFAULT_ENTRY_CODE);
|
|
|
- } else if (defaultEntry.getOutgoingTransitions().size() != 1) {
|
|
|
- error(REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NON_CONNECTED_DEFAULT_ENTRY_MSG, r, null, -1,
|
|
|
- REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NON_CONNECTED_DEFAULT_ENTRY_CODE);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Check
|
|
|
- public void checkOnlyOneDefaultEntryPermitted(Entry entry) {
|
|
|
- Region region = (Region) entry.eContainer();
|
|
|
- List<Entry> initialEntires = region.getVertices().stream().filter(Entry.class::isInstance)
|
|
|
- .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 defaultNamedEntryExists = initialEntires.stream()
|
|
|
- .filter(v -> v.getName().trim().equalsIgnoreCase("default")).count() > 0;
|
|
|
- if (unamedEntryExists && defaultNamedEntryExists) {
|
|
|
- error(REGION_MULTIPLE_DEFAULT_ENTRIES_MSG, region, null, -1, REGION_MULTIPLE_DEFAULT_ENTRIES_CODE);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
}
|