Search in sources :

Example 1 with Effect

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

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

the class RefactoringHelper method hasAtLeastOneAction.

/**
 * Checks if the effect definition of a transition contains at least one action.
 *
 * @param transition
 * @return true if the condition is satisfied, false otherwise
 */
public boolean hasAtLeastOneAction(Transition transition) {
    Effect effect = transition.getEffect();
    if (effect instanceof ReactionEffect) {
        ReactionEffect reactionEffect = (ReactionEffect) effect;
        EList<Expression> actions = reactionEffect.getActions();
        return !actions.isEmpty();
    }
    return false;
}
Also used : Expression(org.yakindu.base.expressions.expressions.Expression) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) Effect(org.yakindu.sct.model.sgraph.Effect) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect)

Example 3 with Effect

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

the class FoldOutgoingActionsRefactoring method getFirstActions.

private List<Expression> getFirstActions(Transition transition, int number) {
    List<Expression> firstActions = new ArrayList<Expression>();
    Effect effect = transition.getEffect();
    if (effect instanceof ReactionEffect) {
        ReactionEffect reactionEffect = (ReactionEffect) effect;
        List<Expression> actions = reactionEffect.getActions();
        for (int i = 0; i < number; i++) {
            firstActions.add(actions.get(i));
        }
    }
    return firstActions;
}
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 4 with Effect

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

the class FoldOutgoingActionsRefactoring method removeFirstActions.

private void removeFirstActions(EList<Transition> transitions, int number) {
    for (Transition transition : transitions) {
        List<Expression> actionsToRemove = getFirstActions(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 5 with Effect

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

the class UnfoldEntryActionsRefactoring method addActionsToTransition.

private void addActionsToTransition(final Transition transition, final Collection<Expression> actionsToAdd) {
    Effect effect = transition.getEffect();
    ReactionEffect reactionEffect;
    if (effect instanceof ReactionEffect) {
        reactionEffect = (ReactionEffect) effect;
        reactionEffect.getActions().addAll(actionsToAdd);
    } else {
        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

Effect (org.yakindu.sct.model.sgraph.Effect)10 ReactionEffect (org.yakindu.sct.model.stext.stext.ReactionEffect)8 Expression (org.yakindu.base.expressions.expressions.Expression)6 ArrayList (java.util.ArrayList)3 Transition (org.yakindu.sct.model.sgraph.Transition)3 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)2 List (java.util.List)1 EList (org.eclipse.emf.common.util.EList)1