Search in sources :

Example 1 with ExitEvent

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

the class SCTResourceTest method testStateSerializing.

@Test
public void testStateSerializing() throws Exception {
    res.setSerializerEnabled(true);
    State state = createState("entry / 3 * 3");
    res.getContents().add(state);
    LocalReaction reaction = (LocalReaction) state.getLocalReactions().get(0);
    ReactionTrigger trigger = (ReactionTrigger) reaction.getTrigger();
    ExitEvent exitEvent = stextFac.createExitEvent();
    trigger.getTriggers().add(exitEvent);
    assertEquals("entry , exit / 3 * 3", state.getSpecification());
    assertEquals("" + res.getErrors(), 0, res.getErrors().size());
}
Also used : LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) State(org.yakindu.sct.model.sgraph.State) ExitEvent(org.yakindu.sct.model.stext.stext.ExitEvent) Test(org.junit.Test)

Example 2 with ExitEvent

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

the class RefactoringHelper method getFirstExitActions.

/**
 * Returns the exit actions of a state. Returns null if no exit block is
 * defined. If multiple exit blocks are defined, only the actions of the first
 * one are returned.
 *
 * @param state
 * @return list of actions of the first exit block defined in the specified
 *         state
 */
public EList<Expression> getFirstExitActions(State state) {
    EList<Reaction> localReactions = state.getLocalReactions();
    for (Reaction reaction : localReactions) {
        Trigger trigger = reaction.getTrigger();
        if (trigger instanceof ReactionTrigger) {
            ReactionTrigger reactionTrigger = (ReactionTrigger) trigger;
            EList<EventSpec> triggers = reactionTrigger.getTriggers();
            for (EventSpec eventSpec : triggers) {
                if (eventSpec instanceof ExitEvent && reaction.getEffect() instanceof ReactionEffect) {
                    return ((ReactionEffect) reaction.getEffect()).getActions();
                }
            }
        }
    }
    return null;
}
Also used : ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) Trigger(org.yakindu.sct.model.sgraph.Trigger) EventSpec(org.yakindu.sct.model.stext.stext.EventSpec) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) Reaction(org.yakindu.sct.model.sgraph.Reaction) ExitEvent(org.yakindu.sct.model.stext.stext.ExitEvent)

Example 3 with ExitEvent

use of org.yakindu.sct.model.stext.stext.ExitEvent 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)

Aggregations

ExitEvent (org.yakindu.sct.model.stext.stext.ExitEvent)3 ReactionTrigger (org.yakindu.sct.model.stext.stext.ReactionTrigger)3 LocalReaction (org.yakindu.sct.model.stext.stext.LocalReaction)2 ReactionEffect (org.yakindu.sct.model.stext.stext.ReactionEffect)2 Test (org.junit.Test)1 Expression (org.yakindu.base.expressions.expressions.Expression)1 Reaction (org.yakindu.sct.model.sgraph.Reaction)1 Scope (org.yakindu.sct.model.sgraph.Scope)1 State (org.yakindu.sct.model.sgraph.State)1 Trigger (org.yakindu.sct.model.sgraph.Trigger)1 EventSpec (org.yakindu.sct.model.stext.stext.EventSpec)1