use of org.yakindu.sct.model.stext.stext.ReactionEffect in project statecharts by Yakindu.
the class ModelSequencerStateTest method testStateCycle_LocalReactionWithMixedRegularAndEntryTrigger.
/**
* Local reactions that define regular and entry triggers side by side must
* also be part of the cycle steps.
*/
@SuppressWarnings("unused")
@Test
public void testStateCycle_LocalReactionWithMixedRegularAndEntryTrigger() {
MinimalTSC tsc = new MinimalTSC();
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, tsc.s_scope);
// add a simple entry action: "entry / x=42;"
LocalReaction lr = _createEntryAction(tsc.s1);
_createRegularEventSpec(tsc.e1, (ReactionTrigger) lr.getTrigger());
ReactionEffect lr_eff = _createReactionEffect(lr);
AssignmentExpression assign1 = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), lr_eff);
// TRANSFORM
ExecutionFlow flow = sequencer.transform(tsc.sc);
// test state with one outgoing transition
ExecutionState s1 = flow.getStates().get(0);
assertEquals(1, s1.getReactions().size());
assertNotNull(s1.getReactSequence());
assertEquals(1, s1.getReactSequence().getSteps().size());
Sequence _seq = (Sequence) s1.getReactSequence().getSteps().get(0);
If _lr1 = (If) assertedSequence(assertedSequence(assertedSequence(assertedSequence(_seq.getSteps().get(0)).getSteps().get(0)).getSteps().get(0)).getSteps().get(0)).getSteps().get(0);
assertClass(ElementReferenceExpression.class, _lr1.getCheck().getCondition());
assertSame(s1.getReactions().get(0).getCheck().getCondition(), _lr1.getCheck().getCondition());
Call _lr1_eff_call = (Call) _lr1.getThenStep();
assertSame(s1.getReactions().get(0).getEffect(), _lr1_eff_call.getStep());
}
use of org.yakindu.sct.model.stext.stext.ReactionEffect in project statecharts by Yakindu.
the class ModelSequencertDeclarationsTest method testOperationMapping.
/**
* The OperationCalls must map to Operations in Scopes inside the Flow..
*/
@Test
public void testOperationMapping() {
Statechart sc = _createStatechart("test");
InterfaceScope s_scope = _createInterfaceScope("Interface", sc);
OperationDefinition _operation = _createOperation("value", s_scope);
Region r = _createRegion("main", sc);
State s1 = _createState("S1", r);
State s2 = _createState("S2", r);
Transition t = _createTransition(s1, s2);
ReactionTrigger tr = _createReactionTrigger(t);
tr.setGuard(createGuardExpression(_createValue(true)));
ReactionEffect tr1 = _createReactionEffect(t);
FeatureCall _operationCall = _createOperationCall(_operation);
tr1.getActions().add(_operationCall);
ExecutionFlow flow = sequencer.transform(sc);
OperationDefinition _o1 = (OperationDefinition) flow.getScopes().get(0).getDeclarations().get(0);
assertNotSame(_operation, _o1);
assertEquals(_operation.getName(), _o1.getName());
Step step = flow.getStates().get(0).getReactSequence().getSteps().get(0);
If _if = (If) assertedSequence(assertedSequence(assertedSequence(step).getSteps().get(0)).getSteps().get(0)).getSteps().get(0);
Step thenSequence = assertedSequence(((Call) _if.getThenStep()).getStep()).getSteps().get(1);
Execution call = (Execution) assertedSequence(thenSequence).getSteps().get(0);
assertNotSame(_operationCall, call.getStatement());
assertSame(_o1, ((FeatureCall) call.getStatement()).getFeature());
}
use of org.yakindu.sct.model.stext.stext.ReactionEffect in project statecharts by Yakindu.
the class StatechartEnterExistActionTest method testSCLocalReaction.
/**
* The transition sequence must contain all exit actions for parent states
* that will be left by a transition.
*/
@SuppressWarnings("unused")
@Test
public void testSCLocalReaction() {
Statechart sc = _createStatechart("sc");
{
VariableDefinition v = _createVariableDefinition("v", TYPE_INTEGER, getOrCreateInternalScope(sc));
LocalReaction entryAction = _createEntryAction(sc);
ReactionEffect effect = _createReactionEffect(entryAction);
_createVariableAssignment(v, AssignmentOperator.ADD_ASSIGN, _createValue(1), effect);
LocalReaction exitAction = _createExitAction(sc);
effect = _createReactionEffect(exitAction);
_createVariableAssignment(v, AssignmentOperator.ADD_ASSIGN, _createValue(1), effect);
Region r = _createRegion("r", sc);
{
Entry e = _createEntry(EntryKind.INITIAL, null, r);
State s1 = _createState("s1", r);
Transition t = _createTransition(e, s1);
}
}
ExecutionFlow flow = sequencer.transform(sc);
ExecutionRegion region = flow.getRegions().get(0);
assertEquals(0, flow.getReactions().size());
assertedOrder(flow.getEnterSequences().get(0), null, Lists.newArrayList(new StepLeaf(flow.getEntryAction()), new StepLeaf(region.getEnterSequences().get(0))));
assertedOrder(flow.getExitSequence(), null, Lists.newArrayList(new StepLeaf(region.getExitSequence()), new StepLeaf(flow.getExitAction())));
}
use of org.yakindu.sct.model.stext.stext.ReactionEffect in project statecharts by Yakindu.
the class RefactoringHelper method getFirstEntryActions.
/**
* Returns the entry actions of a state. Returns null if no entry block is
* defined. If multiple entry blocks are defined, only the actions of the first
* one are returned.
*
* @param state
* @return list of actions of the first entry block defined in the specified
* state
*/
public EList<Expression> getFirstEntryActions(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 EntryEvent && reaction.getEffect() instanceof ReactionEffect) {
return ((ReactionEffect) reaction.getEffect()).getActions();
}
}
}
}
return null;
}
use of org.yakindu.sct.model.stext.stext.ReactionEffect 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;
}
Aggregations