Search in sources :

Example 21 with ReactionEffect

use of org.yakindu.sct.model.stext.stext.ReactionEffect in project statecharts by Yakindu.

the class FoldOutgoingActionsRefactoring method createExitBlock.

private EList<Expression> createExitBlock(List<Expression> actionsToAdd) {
    EList<Expression> actionsOriginal;
    LocalReaction newLocalReaction = StextFactory.eINSTANCE.createLocalReaction();
    ReactionTrigger newReactionTrigger = StextFactory.eINSTANCE.createReactionTrigger();
    ExitEvent exitEvent = StextFactory.eINSTANCE.createExitEvent();
    ReactionEffect newReactionEffect = StextFactory.eINSTANCE.createReactionEffect();
    newLocalReaction.setTrigger(newReactionTrigger);
    newReactionTrigger.getTriggers().add(exitEvent);
    newReactionEffect.getActions().addAll(actionsToAdd);
    newLocalReaction.setEffect(newReactionEffect);
    Scope scope = getContextObject().getScopes().get(0);
    scope.getReactions().add(newLocalReaction);
    actionsOriginal = newReactionEffect.getActions();
    return actionsOriginal;
}
Also used : LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) Scope(org.yakindu.sct.model.sgraph.Scope) Expression(org.yakindu.base.expressions.expressions.Expression) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) ExitEvent(org.yakindu.sct.model.stext.stext.ExitEvent)

Example 22 with ReactionEffect

use of org.yakindu.sct.model.stext.stext.ReactionEffect in project statecharts by Yakindu.

the class FoldIncomingActionsRefactoring method getLastActions.

private List<Expression> getLastActions(Transition transition, int number) {
    List<Expression> lastActions = new ArrayList<Expression>();
    Effect effect = transition.getEffect();
    if (effect instanceof ReactionEffect) {
        ReactionEffect reactionEffect = (ReactionEffect) effect;
        List<Expression> actions = reactionEffect.getActions();
        for (int i = 1; i <= number; i++) {
            lastActions.add(actions.get(actions.size() - i));
        }
    }
    return lastActions;
}
Also used : Expression(org.yakindu.base.expressions.expressions.Expression) ArrayList(java.util.ArrayList) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) Effect(org.yakindu.sct.model.sgraph.Effect) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect)

Example 23 with ReactionEffect

use of org.yakindu.sct.model.stext.stext.ReactionEffect in project statecharts by Yakindu.

the class FoldIncomingActionsRefactoring method removeLastActions.

private void removeLastActions(EList<Transition> transitions, int number) {
    for (Transition transition : transitions) {
        List<Expression> actionsToRemove = getLastActions(transition, number);
        Effect effect = transition.getEffect();
        if (effect instanceof ReactionEffect && actionsToRemove.size() == ((ReactionEffect) effect).getActions().size()) {
            // we need to remove all actions, so just remove the effect
            // recursively which avoids serializer exceptions
            EcoreUtil.delete(effect, true);
        } else {
            for (Expression action : actionsToRemove) {
                EcoreUtil.delete(action);
            }
        }
    }
}
Also used : Expression(org.yakindu.base.expressions.expressions.Expression) Transition(org.yakindu.sct.model.sgraph.Transition) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) Effect(org.yakindu.sct.model.sgraph.Effect) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect)

Example 24 with ReactionEffect

use of org.yakindu.sct.model.stext.stext.ReactionEffect in project statecharts by Yakindu.

the class UnfoldExitActionsRefactoring method addActionsToTransition.

private void addActionsToTransition(final Transition transition, final Collection<Expression> actionsToAdd) {
    Effect effect = transition.getEffect();
    if (effect instanceof ReactionEffect) {
        ReactionEffect reactionEffect = (ReactionEffect) effect;
        reactionEffect.getActions().addAll(0, actionsToAdd);
    } else {
        ReactionEffect reactionEffect = StextFactory.eINSTANCE.createReactionEffect();
        reactionEffect.getActions().addAll(actionsToAdd);
        transition.setEffect(reactionEffect);
    }
}
Also used : ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) Effect(org.yakindu.sct.model.sgraph.Effect) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect)

Aggregations

ReactionEffect (org.yakindu.sct.model.stext.stext.ReactionEffect)24 LocalReaction (org.yakindu.sct.model.stext.stext.LocalReaction)13 Test (org.junit.Test)11 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)11 ReactionTrigger (org.yakindu.sct.model.stext.stext.ReactionTrigger)10 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)10 StextTestFactory._createReactionEffect (org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionEffect)10 StextTestFactory._createVariableDefinition (org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition)10 Expression (org.yakindu.base.expressions.expressions.Expression)9 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)9 StextTestFactory._createLocalReaction (org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction)9 AssignmentExpression (org.yakindu.base.expressions.expressions.AssignmentExpression)8 Effect (org.yakindu.sct.model.sgraph.Effect)8 Transition (org.yakindu.sct.model.sgraph.Transition)8 If (org.yakindu.sct.model.sexec.If)7 Sequence (org.yakindu.sct.model.sexec.Sequence)7 Step (org.yakindu.sct.model.sexec.Step)6 StextTestFactory._createReactionTrigger (org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger)6 Region (org.yakindu.sct.model.sgraph.Region)5 State (org.yakindu.sct.model.sgraph.State)5