Search in sources :

Example 61 with Transition

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

the class FoldIncomingActionsRefactoring method getFoldableActions.

private List<Expression> getFoldableActions() {
    EList<Transition> transitions = getContextObject().getIncomingTransitions();
    List<Expression> foldableActions = new ArrayList<Expression>();
    Expression lastFoldableAction;
    int indexFromBack = 0;
    while ((lastFoldableAction = getLastFoldableAction(helper.getAllActions(transitions), indexFromBack)) != null) {
        foldableActions.add(0, lastFoldableAction);
        indexFromBack++;
    }
    removeLastActions(transitions, indexFromBack);
    return foldableActions;
}
Also used : Expression(org.yakindu.base.expressions.expressions.Expression) Transition(org.yakindu.sct.model.sgraph.Transition) ArrayList(java.util.ArrayList)

Example 62 with Transition

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

the class STextValidationModelUtils method getEntrySpecSortedTransitions.

/**
 * Sorts the given elements in transition without and with
 * {@link EntryPointSpec}s
 *
 * @param elements
 *            list of transitions to sort
 * @return an array with the sorted elements. The first index contains a
 *         list of the transitions without {@link EntryPointSpec}s. The
 *         second index contains a list of the transitions with
 *         {@link EntryPointSpec}s.
 */
public static List<Transition>[] getEntrySpecSortedTransitions(List<Transition> elements) {
    @SuppressWarnings("unchecked") final List<Transition>[] transitions = new ArrayList[2];
    // first list contains Transitions without entry spec
    transitions[0] = new ArrayList<Transition>();
    // second list contains Transitions with entry spec
    transitions[1] = new ArrayList<Transition>();
    for (Transition transition : elements) {
        boolean hasEntrySpec = false;
        for (ReactionProperty property : transition.getProperties()) {
            if (property instanceof EntryPointSpec) {
                transitions[1].add(transition);
                hasEntrySpec = true;
                break;
            }
        }
        if (!hasEntrySpec) {
            transitions[0].add(transition);
        }
    }
    return transitions;
}
Also used : ArrayList(java.util.ArrayList) Transition(org.yakindu.sct.model.sgraph.Transition) ArrayList(java.util.ArrayList) List(java.util.List) EntryPointSpec(org.yakindu.sct.model.stext.stext.EntryPointSpec) ReactionProperty(org.yakindu.sct.model.sgraph.ReactionProperty)

Example 63 with Transition

use of org.yakindu.sct.model.sgraph.Transition 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

Transition (org.yakindu.sct.model.sgraph.Transition)63 Test (org.junit.Test)34 Region (org.yakindu.sct.model.sgraph.Region)26 State (org.yakindu.sct.model.sgraph.State)23 Statechart (org.yakindu.sct.model.sgraph.Statechart)19 FinalState (org.yakindu.sct.model.sgraph.FinalState)13 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)13 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)13 SGraphTestFactory._createTransition (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createTransition)13 ReactionTrigger (org.yakindu.sct.model.stext.stext.ReactionTrigger)13 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)10 Entry (org.yakindu.sct.model.sgraph.Entry)10 SGraphTestFactory._createState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState)10 StextTestFactory._createReactionTrigger (org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger)9 EventDefinition (org.yakindu.sct.model.stext.stext.EventDefinition)8 LocalReaction (org.yakindu.sct.model.stext.stext.LocalReaction)8 ReactionEffect (org.yakindu.sct.model.stext.stext.ReactionEffect)8 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)7 If (org.yakindu.sct.model.sexec.If)7 Vertex (org.yakindu.sct.model.sgraph.Vertex)7