Search in sources :

Example 1 with AssignmentExpression

use of org.yakindu.base.expressions.expressions.AssignmentExpression in project statecharts by Yakindu.

the class ExpressionsJavaValidator method checkAssignmentToFinalVariable.

@Check(CheckType.FAST)
public void checkAssignmentToFinalVariable(AssignmentExpression exp) {
    Expression varRef = exp.getVarRef();
    EObject referencedObject = null;
    if (varRef instanceof FeatureCall)
        referencedObject = ((FeatureCall) varRef).getFeature();
    else if (varRef instanceof ElementReferenceExpression)
        referencedObject = ((ElementReferenceExpression) varRef).getReference();
    if (referencedObject instanceof Property) {
        if (((Property) referencedObject).isConst()) {
            error(ERROR_ASSIGNMENT_TO_CONST_MSG, ExpressionsPackage.Literals.ASSIGNMENT_EXPRESSION__VAR_REF, ERROR_ASSIGNMENT_TO_CONST_CODE);
        }
    }
}
Also used : PostFixUnaryExpression(org.yakindu.base.expressions.expressions.PostFixUnaryExpression) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) Expression(org.yakindu.base.expressions.expressions.Expression) ArgumentExpression(org.yakindu.base.expressions.expressions.ArgumentExpression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) EObject(org.eclipse.emf.ecore.EObject) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) Property(org.yakindu.base.types.Property) Check(org.eclipse.xtext.validation.Check)

Example 2 with AssignmentExpression

use of org.yakindu.base.expressions.expressions.AssignmentExpression in project statecharts by Yakindu.

the class ModelSequencerStateReactionTest method testAlwaysLocalReaction.

/**
 * Local reactions must be created for behavior with 'always' trigger
 */
@SuppressWarnings("unused")
@Test
public void testAlwaysLocalReaction() {
    Statechart sc = _createStatechart("test");
    Scope scope = _createInterfaceScope("interface", sc);
    VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, scope);
    Region r = _createRegion("main", sc);
    State s = _createState("s", r);
    LocalReaction timeTriggeredReaction = _createLocalReaction(s, StextFactory.eINSTANCE.createAlwaysEvent());
    AssignmentExpression assign = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), (ReactionEffect) timeTriggeredReaction.getEffect());
    ExecutionFlow flow = sequencer.transform(sc);
    ExecutionState _s = flow.getStates().get(0);
    // assert that a local reaction is created
    Reaction reaction = _s.getReactions().get(0);
    PrimitiveValueExpression pve = (PrimitiveValueExpression) reaction.getCheck().getCondition();
    assertBoolLiteral(true, pve.getValue());
}
Also used : LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) StextTestFactory._createLocalReaction(org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction) ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) Scope(org.yakindu.sct.model.sgraph.Scope) StextTestFactory._createInterfaceScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) SGraphTestFactory._createState(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState) ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) State(org.yakindu.sct.model.sgraph.State) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) Statechart(org.yakindu.sct.model.sgraph.Statechart) SGraphTestFactory._createStatechart(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart) Region(org.yakindu.sct.model.sgraph.Region) SGraphTestFactory._createRegion(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion) LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) StextTestFactory._createTimeTriggeredReaction(org.yakindu.sct.model.stext.test.util.StextTestFactory._createTimeTriggeredReaction) StextTestFactory._createLocalReaction(org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction) Reaction(org.yakindu.sct.model.sexec.Reaction) PrimitiveValueExpression(org.yakindu.base.expressions.expressions.PrimitiveValueExpression) Test(org.junit.Test)

Example 3 with AssignmentExpression

use of org.yakindu.base.expressions.expressions.AssignmentExpression in project statecharts by Yakindu.

the class ModelSequencerStateTest method testStateReaction_WithExitAction.

/**
 * The exit action must be part of the reaction effect sequence
 */
@SuppressWarnings("unused")
@Test
public void testStateReaction_WithExitAction() {
    SimpleFlatTSC tsc = new SimpleFlatTSC();
    VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, tsc.s_scope);
    LocalReaction exitAction = _createExitAction(tsc.s1);
    AssignmentExpression assign = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(21), (ReactionEffect) exitAction.getEffect());
    ExecutionFlow flow = sequencer.transform(tsc.sc);
    // test state with one outgoing transition
    ExecutionState _s1 = flow.getStates().get(0);
    ExecutionState _s2 = flow.getStates().get(1);
    assertEquals(tsc.s1.getName(), _s1.getSimpleName());
    assertEquals(tsc.s2.getName(), _s2.getSimpleName());
    assertEquals(1, _s1.getReactions().size());
    Reaction reaction = _s1.getReactions().get(0);
    assertNotNull(reaction.getCheck());
    assertNotNull(reaction.getEffect());
    Sequence seq = (Sequence) reaction.getEffect();
    assertCall(seq, 0, _s1.getExitSequence());
    assertCall(_s1.getExitSequence(), 1, _s1.getExitAction());
}
Also used : LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) StextTestFactory._createLocalReaction(org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction) ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) SimpleFlatTSC(org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.SimpleFlatTSC) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) Sequence(org.yakindu.sct.model.sexec.Sequence) LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) StextTestFactory._createLocalReaction(org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction) Reaction(org.yakindu.sct.model.sexec.Reaction) Test(org.junit.Test)

Example 4 with AssignmentExpression

use of org.yakindu.base.expressions.expressions.AssignmentExpression in project statecharts by Yakindu.

the class ModelSequencerStateTest method testStateCycle_EntryActionExclusion.

/**
 * Entry action behaviors are not directly part of the states cycle steps
 */
@SuppressWarnings("unused")
@Test
public void testStateCycle_EntryActionExclusion() {
    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);
    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(0, s1.getReactions().size());
    assertNotNull(s1.getReactSequence());
    assertEquals(1, s1.getReactSequence().getSteps().size());
}
Also used : LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) StextTestFactory._createLocalReaction(org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction) ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) MinimalTSC(org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.MinimalTSC) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) StextTestFactory._createReactionEffect(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionEffect) Test(org.junit.Test)

Example 5 with AssignmentExpression

use of org.yakindu.base.expressions.expressions.AssignmentExpression in project statecharts by Yakindu.

the class ModelSequencerStateTest method testStateReaction_WithEntryAction.

/**
 * The exit action must be part of the reaction effect sequence
 */
@SuppressWarnings("unused")
@Test
public void testStateReaction_WithEntryAction() {
    SimpleFlatTSC tsc = new SimpleFlatTSC();
    VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, tsc.s_scope);
    LocalReaction entryAction = _createEntryAction(tsc.s2);
    AssignmentExpression assign = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(21), (ReactionEffect) entryAction.getEffect());
    ExecutionFlow flow = sequencer.transform(tsc.sc);
    // test state with one outgoing transition
    ExecutionState _s1 = flow.getStates().get(0);
    ExecutionState _s2 = flow.getStates().get(1);
    assertEquals(tsc.s1.getName(), _s1.getSimpleName());
    assertEquals(tsc.s2.getName(), _s2.getSimpleName());
    assertEquals(1, _s1.getReactions().size());
    Reaction reaction = _s1.getReactions().get(0);
    assertNotNull(reaction.getCheck());
    assertNotNull(reaction.getEffect());
    Sequence seq = (Sequence) reaction.getEffect();
    assertEquals(2, seq.getSteps().size());
    assertCall(seq, 0, _s1.getExitSequence());
    assertCall(seq, 1, _s2.getEnterSequences().get(0));
    assertCall(_s2.getEnterSequences().get(0), 0, _s2.getEntryAction());
}
Also used : LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) StextTestFactory._createLocalReaction(org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction) ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) SimpleFlatTSC(org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.SimpleFlatTSC) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) Sequence(org.yakindu.sct.model.sexec.Sequence) LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) StextTestFactory._createLocalReaction(org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction) Reaction(org.yakindu.sct.model.sexec.Reaction) Test(org.junit.Test)

Aggregations

AssignmentExpression (org.yakindu.base.expressions.expressions.AssignmentExpression)17 Test (org.junit.Test)13 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)13 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)13 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)13 StextTestFactory._createVariableDefinition (org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition)13 LocalReaction (org.yakindu.sct.model.stext.stext.LocalReaction)12 StextTestFactory._createLocalReaction (org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction)12 Sequence (org.yakindu.sct.model.sexec.Sequence)10 ReactionEffect (org.yakindu.sct.model.stext.stext.ReactionEffect)8 StextTestFactory._createReactionEffect (org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionEffect)8 If (org.yakindu.sct.model.sexec.If)6 ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)5 PrimitiveValueExpression (org.yakindu.base.expressions.expressions.PrimitiveValueExpression)5 Region (org.yakindu.sct.model.sgraph.Region)5 State (org.yakindu.sct.model.sgraph.State)5 Statechart (org.yakindu.sct.model.sgraph.Statechart)5 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)5 SGraphTestFactory._createState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState)5 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)5