Search in sources :

Example 46 with Entry

use of org.yakindu.sct.model.sgraph.Entry in project statecharts by Yakindu.

the class STextValidationModelUtils method getRegionsWithoutDefaultEntry.

/**
 * If a {@link Region} contains no 'default' named {@link entry} it is added
 * as key to a map with a list of all entries of the region.
 *
 * @param elements
 *            - a list with {@link Region} elements.
 * @return a map with a region (key) which contains no default {@link entry}
 *         and a list of all {@link entry} elements of the {@link Region}
 *         (value).
 */
public static Map<Region, List<Entry>> getRegionsWithoutDefaultEntry(List<Region> elements) {
    Map<Region, List<Entry>> regions = new HashMap<Region, List<Entry>>();
    for (Region region : elements) {
        boolean hasDefaultEntry = false;
        final List<Entry> entries = getEntries(region.eContents());
        for (Entry entry : entries) {
            if (isDefault(entry)) {
                hasDefaultEntry = true;
                break;
            }
        }
        if (!hasDefaultEntry) {
            regions.put(region, entries);
        }
    }
    return regions;
}
Also used : Entry(org.yakindu.sct.model.sgraph.Entry) HashMap(java.util.HashMap) Region(org.yakindu.sct.model.sgraph.Region) ArrayList(java.util.ArrayList) List(java.util.List)

Example 47 with Entry

use of org.yakindu.sct.model.sgraph.Entry in project statecharts by Yakindu.

the class SGraphJavaValidator method vertexNotReachable.

@Check(CheckType.FAST)
public void vertexNotReachable(final Vertex vertex) {
    if (!(vertex instanceof Entry)) {
        final Set<Object> stateScopeSet = new HashSet<>();
        for (EObject obj : EcoreUtil2.eAllContents(vertex)) {
            stateScopeSet.add(obj);
        }
        stateScopeSet.add(vertex);
        final List<Object> externalPredecessors = new ArrayList<>();
        DFS dfs = new DFS() {

            @Override
            public Iterator<Object> getElementLinks(Object element) {
                List<Object> elements = new ArrayList<>();
                if (element instanceof org.yakindu.sct.model.sgraph.State) {
                    if (!stateScopeSet.contains(element)) {
                        externalPredecessors.add(element);
                    } else {
                        elements.addAll(((org.yakindu.sct.model.sgraph.State) element).getRegions());
                        elements.addAll(((org.yakindu.sct.model.sgraph.State) element).getIncomingTransitions());
                    }
                } else if (element instanceof Region) {
                    elements.addAll(((Region) element).getVertices());
                } else if (element instanceof Entry) {
                    if (!stateScopeSet.contains(element)) {
                        externalPredecessors.add(element);
                    } else {
                        elements.addAll(((Entry) element).getIncomingTransitions());
                    }
                } else if (element instanceof Vertex) {
                    elements.addAll(((Vertex) element).getIncomingTransitions());
                } else if (element instanceof Transition) {
                    elements.add(((Transition) element).getSource());
                }
                return elements.iterator();
            }
        };
        dfs.perform(vertex);
        if (externalPredecessors.size() == 0) {
            error(ISSUE_NODE_NOT_REACHABLE, vertex, null, -1);
        }
    }
}
Also used : Vertex(org.yakindu.sct.model.sgraph.Vertex) ArrayList(java.util.ArrayList) Entry(org.yakindu.sct.model.sgraph.Entry) FinalState(org.yakindu.sct.model.sgraph.FinalState) EObject(org.eclipse.emf.ecore.EObject) Transition(org.yakindu.sct.model.sgraph.Transition) Region(org.yakindu.sct.model.sgraph.Region) EObject(org.eclipse.emf.ecore.EObject) HashSet(java.util.HashSet) Check(org.eclipse.xtext.validation.Check)

Aggregations

Entry (org.yakindu.sct.model.sgraph.Entry)47 Test (org.junit.Test)38 Region (org.yakindu.sct.model.sgraph.Region)38 State (org.yakindu.sct.model.sgraph.State)30 Statechart (org.yakindu.sct.model.sgraph.Statechart)30 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)29 SGraphTestFactory._createEntry (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createEntry)29 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)29 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)29 SGraphTestFactory._createState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState)28 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)27 StextTestFactory._createVariableDefinition (org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition)27 StextTestFactory._createInterfaceScope (org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope)26 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)25 Sequence (org.yakindu.sct.model.sexec.Sequence)22 InterfaceScope (org.yakindu.sct.model.stext.stext.InterfaceScope)22 EnterState (org.yakindu.sct.model.sexec.EnterState)13 SCTTestUtil.findState (org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.findState)13 Reaction (org.yakindu.sct.model.sexec.Reaction)10 Transition (org.yakindu.sct.model.sgraph.Transition)10