Search in sources :

Example 1 with ReactionTrigger

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

the class FoldIncomingActionsRefactoring method createEntryBlock.

private EList<Expression> createEntryBlock(List<Expression> actionsToAdd) {
    EList<Expression> actionsOriginal;
    LocalReaction newLocalReaction = StextFactory.eINSTANCE.createLocalReaction();
    ReactionTrigger newReactionTrigger = StextFactory.eINSTANCE.createReactionTrigger();
    EntryEvent entryEvent = StextFactory.eINSTANCE.createEntryEvent();
    ReactionEffect newReactionEffect = StextFactory.eINSTANCE.createReactionEffect();
    newLocalReaction.setTrigger(newReactionTrigger);
    newReactionTrigger.getTriggers().add(entryEvent);
    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) EntryEvent(org.yakindu.sct.model.stext.stext.EntryEvent) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect)

Example 2 with ReactionTrigger

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

the class SCTResourceTest method testLinkingSuccess.

@Test
public void testLinkingSuccess() throws Exception {
    Statechart statechart = createStatechart("internal: event Event1");
    res.getContents().add(statechart);
    Transition transition = createTransition("Event1 [true] / 3 * 3");
    res.getContents().add(transition);
    res.resolveLazyCrossReferences(CancelIndicator.NullImpl);
    assertEquals("" + res.getLinkingDiagnostics(), 0, res.getLinkingDiagnostics().size());
    ReactionTrigger trigger = (ReactionTrigger) transition.getTrigger();
    RegularEventSpec eventSpec = (RegularEventSpec) trigger.getTriggers().get(0);
    ElementReferenceExpression expression = (ElementReferenceExpression) eventSpec.getEvent();
    EventDefinition reference = (EventDefinition) expression.getReference();
    assertNotNull(reference);
    assertEquals("Event1", reference.getName());
}
Also used : ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) Transition(org.yakindu.sct.model.sgraph.Transition) Statechart(org.yakindu.sct.model.sgraph.Statechart) EventDefinition(org.yakindu.sct.model.stext.stext.EventDefinition) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) RegularEventSpec(org.yakindu.sct.model.stext.stext.RegularEventSpec) Test(org.junit.Test)

Example 3 with ReactionTrigger

use of org.yakindu.sct.model.stext.stext.ReactionTrigger 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 4 with ReactionTrigger

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

the class ModelSequencerStateReactionTest method testAlwaysTriggerCondition.

/**
 * The 'always' trigger event will be converted to a simple 'true'
 * condition.
 */
@Test
public void testAlwaysTriggerCondition() {
    ReactionTrigger tr1 = _createReactionTrigger(null);
    _createAlwaysEventSpec(tr1);
    Expression s = behaviorMapping.buildCondition(tr1);
    assertNotNull(s);
    assertTrue(s instanceof PrimitiveValueExpression);
    assertBoolLiteral(true, ((PrimitiveValueExpression) s).getValue());
}
Also used : StextTestFactory._createReactionTrigger(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) LogicalAndExpression(org.yakindu.base.expressions.expressions.LogicalAndExpression) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) LogicalOrExpression(org.yakindu.base.expressions.expressions.LogicalOrExpression) NumericalMultiplyDivideExpression(org.yakindu.base.expressions.expressions.NumericalMultiplyDivideExpression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) StextTestFactory.createGuardExpression(org.yakindu.sct.model.stext.test.util.StextTestFactory.createGuardExpression) Expression(org.yakindu.base.expressions.expressions.Expression) ParenthesizedExpression(org.yakindu.base.expressions.expressions.ParenthesizedExpression) PrimitiveValueExpression(org.yakindu.base.expressions.expressions.PrimitiveValueExpression) PrimitiveValueExpression(org.yakindu.base.expressions.expressions.PrimitiveValueExpression) Test(org.junit.Test)

Example 5 with ReactionTrigger

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

the class ModelSequencerStateReactionTest method testSingleRegularEventTriggerCondition.

/**
 * Single trigger events of a Reaction Trigger will be converted into a
 * single condition that consists of a ElementReferenceExpression to the
 * corresponding event definition.
 */
@Test
public void testSingleRegularEventTriggerCondition() {
    EventDefinition e1 = _createEventDefinition("e1", null);
    ReactionTrigger tr1 = _createReactionTrigger(null);
    _createRegularEventSpec(e1, tr1);
    Expression s = behaviorMapping.buildCondition(tr1);
    assertClass(ElementReferenceExpression.class, s);
}
Also used : StextTestFactory._createReactionTrigger(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) LogicalAndExpression(org.yakindu.base.expressions.expressions.LogicalAndExpression) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) LogicalOrExpression(org.yakindu.base.expressions.expressions.LogicalOrExpression) NumericalMultiplyDivideExpression(org.yakindu.base.expressions.expressions.NumericalMultiplyDivideExpression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) StextTestFactory.createGuardExpression(org.yakindu.sct.model.stext.test.util.StextTestFactory.createGuardExpression) Expression(org.yakindu.base.expressions.expressions.Expression) ParenthesizedExpression(org.yakindu.base.expressions.expressions.ParenthesizedExpression) PrimitiveValueExpression(org.yakindu.base.expressions.expressions.PrimitiveValueExpression) StextTestFactory._createEventDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createEventDefinition) EventDefinition(org.yakindu.sct.model.stext.stext.EventDefinition) Test(org.junit.Test)

Aggregations

ReactionTrigger (org.yakindu.sct.model.stext.stext.ReactionTrigger)26 Test (org.junit.Test)20 StextTestFactory._createReactionTrigger (org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger)16 LocalReaction (org.yakindu.sct.model.stext.stext.LocalReaction)14 Statechart (org.yakindu.sct.model.sgraph.Statechart)13 Region (org.yakindu.sct.model.sgraph.Region)12 Transition (org.yakindu.sct.model.sgraph.Transition)12 ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)11 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)11 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)11 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)10 If (org.yakindu.sct.model.sexec.If)10 ReactionEffect (org.yakindu.sct.model.stext.stext.ReactionEffect)10 StextTestFactory._createLocalReaction (org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction)10 State (org.yakindu.sct.model.sgraph.State)9 SGraphTestFactory._createTransition (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createTransition)9 EventDefinition (org.yakindu.sct.model.stext.stext.EventDefinition)9 AssignmentExpression (org.yakindu.base.expressions.expressions.AssignmentExpression)8 PrimitiveValueExpression (org.yakindu.base.expressions.expressions.PrimitiveValueExpression)8 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)8