Search in sources :

Example 1 with Transition

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

the class RefactoringHelper method getAllActions.

/**
 * Collects all actions of the specified transitions and returns them.
 *
 * @param transitions
 * @return list of list of actions for the specified transitions
 */
public List<List<Expression>> getAllActions(List<Transition> transitions) {
    List<List<Expression>> allActions = new ArrayList<List<Expression>>();
    for (Transition transition : transitions) {
        Effect effect = transition.getEffect();
        if (effect instanceof ReactionEffect) {
            ReactionEffect reactionEffect = (ReactionEffect) effect;
            allActions.add(reactionEffect.getActions());
        } else {
            allActions.add(Collections.<Expression>emptyList());
        }
    }
    return allActions;
}
Also used : Expression(org.yakindu.base.expressions.expressions.Expression) ArrayList(java.util.ArrayList) Transition(org.yakindu.sct.model.sgraph.Transition) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) List(java.util.List) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) Effect(org.yakindu.sct.model.sgraph.Effect) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect)

Example 2 with Transition

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

the class RefactoringHelper method oneOutgoingTransitionLeavesCompositeWithExitActions.

/**
 * Checks if at least one of the outgoing transitions of the specified state
 * leaves a parent composite of this state which has exit actions.
 *
 * @param state
 * @return true if condition is satisfied, false otherwise
 */
public boolean oneOutgoingTransitionLeavesCompositeWithExitActions(State state) {
    Set<State> sourceParentStates = new HashSet<State>(getParentStates(state));
    for (Transition transition : state.getOutgoingTransitions()) {
        // all parent states of target need to be contained in the set of
        // the source's parent states
        Set<State> targetParentStates = getParentStates(transition.getTarget());
        Set<State> crossedStates = new HashSet<State>(sourceParentStates);
        crossedStates.removeAll(targetParentStates);
        for (State crossedCompositeState : crossedStates) {
            if (hasExitAction(crossedCompositeState))
                return true;
        }
    }
    return false;
}
Also used : State(org.yakindu.sct.model.sgraph.State) Transition(org.yakindu.sct.model.sgraph.Transition) HashSet(java.util.HashSet)

Example 3 with Transition

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

the class RefactoringHelper method oneIncomingTransitionEntersCompositeWithEntryActions.

/**
 * Checks if at least one of the incoming transitions of the specified state
 * enters a parent composite of this state which has entry actions.
 *
 * @param state
 * @return true if condition is satisfied, false otherwise
 */
public boolean oneIncomingTransitionEntersCompositeWithEntryActions(State state) {
    Set<State> targetParentStates = new HashSet<State>(getParentStates(state));
    for (Transition transition : state.getIncomingTransitions()) {
        // all parent states of source need to be contained in the set of
        // the target's parent states
        Set<State> sourceParentStates = getParentStates(transition.getSource());
        Set<State> crossedStates = new HashSet<State>(targetParentStates);
        crossedStates.removeAll(sourceParentStates);
        for (State crossedCompositeState : crossedStates) {
            if (hasEntryAction(crossedCompositeState))
                return true;
        }
    }
    return false;
}
Also used : State(org.yakindu.sct.model.sgraph.State) Transition(org.yakindu.sct.model.sgraph.Transition) HashSet(java.util.HashSet)

Example 4 with Transition

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

the class ExtractSubdiagramRefactoring method createEntryPoint.

protected void createEntryPoint(Edge edge, Diagram subdiagram) {
    Transition transition = (Transition) edge.getElement();
    Region entryPointContainer = getEntryPointContainer(transition);
    Entry entryPoint = createSemanticEntryPoint(transition);
    // re-wire old transition to targeting the selected state
    transition.setTarget((State) subdiagram.getElement());
    View oldTarget = edge.getTarget();
    edge.setTarget(getContextObject());
    // create node for entry point
    View entryPointContainerView = helper.getViewForSemanticElement(entryPointContainer, subdiagram);
    View entryPointRegionCompartment = ViewUtil.getChildBySemanticHint(entryPointContainerView, SemanticHints.REGION_COMPARTMENT);
    Node entryNode = ViewService.createNode(entryPointRegionCompartment, entryPoint, SemanticHints.ENTRY, preferencesHint);
    ViewService.createEdge(entryNode, oldTarget, entryPoint.getOutgoingTransitions().get(0), SemanticHints.TRANSITION, preferencesHint);
    addEntryPointSpec(transition, entryPoint);
}
Also used : Entry(org.yakindu.sct.model.sgraph.Entry) Node(org.eclipse.gmf.runtime.notation.Node) Transition(org.yakindu.sct.model.sgraph.Transition) Region(org.yakindu.sct.model.sgraph.Region) View(org.eclipse.gmf.runtime.notation.View)

Example 5 with Transition

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

the class ExtractSubdiagramRefactoring method createSemanticEntryPoint.

protected Entry createSemanticEntryPoint(Transition transition) {
    Region entryPointTarget = getEntryPointContainer(transition);
    String name = getEntryPointName(transition);
    Entry entryPoint = null;
    Iterator<Vertex> iterator = entryPointTarget.getVertices().iterator();
    while (iterator.hasNext()) {
        Vertex next = iterator.next();
        if (next instanceof Entry) {
            Entry current = (Entry) next;
            if (name.equals(current.getName())) {
                // Do nothing, there already exists an entry point
                return current;
            }
        }
    }
    entryPoint = SGraphFactory.eINSTANCE.createEntry();
    entryPoint.setName(name);
    entryPointTarget.getVertices().add(entryPoint);
    Transition entryPointTransition = SGraphFactory.eINSTANCE.createTransition();
    entryPointTransition.setSource(entryPoint);
    entryPointTransition.setTarget(transition.getTarget());
    return entryPoint;
}
Also used : Vertex(org.yakindu.sct.model.sgraph.Vertex) Entry(org.yakindu.sct.model.sgraph.Entry) Transition(org.yakindu.sct.model.sgraph.Transition) Region(org.yakindu.sct.model.sgraph.Region)

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