/** The transition action must be part of the reaction effect sequence */
  @Test
  public void testStateReaction_WithTransitionAction() {
    SimpleFlatTSC tsc = new SimpleFlatTSC();
    VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, tsc.s_scope);
    ReactionEffect effect = _createReactionEffect(tsc.t1);
    AssignmentExpression assign =
        _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), effect);

    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());

    assertClass(Sequence.class, seq.getSteps().get(1));
    Execution _exec = (Execution) ((Sequence) seq.getSteps().get(1)).getSteps().get(0);
    AssignmentExpression _assign = (AssignmentExpression) _exec.getStatement();
    assertNotSame(_assign, assign);
    assertNotSame(_assign.getVarRef(), assign.getVarRef());
    assertNotSame(_assign.getVarRef(), v1);

    assertCall(seq, 2, s2.getEnterSequences().get(0));
  }
예제 #2
0
 private String getVariableName(AssignmentExpression exp) {
   Expression varRef = exp.getVarRef();
   if (varRef instanceof ElementReferenceExpression
       && ((ElementReferenceExpression) varRef).getReference() instanceof Property) {
     Property reference = (Property) ((ElementReferenceExpression) varRef).getReference();
     return reference.getName();
   } else if (varRef instanceof FeatureCall
       && ((FeatureCall) varRef).getFeature() instanceof Property) {
     Property reference = (Property) ((FeatureCall) varRef).getFeature();
     return reference.getName();
   }
   return null;
 }
예제 #3
0
 @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 VariableDefinition) {
     if (((VariableDefinition) referencedObject).isConst()) {
       error(ASSIGNMENT_TO_VALUE, ExpressionsPackage.Literals.ASSIGNMENT_EXPRESSION__VAR_REF);
     }
   }
 }
예제 #4
0
  @Check(CheckType.FAST)
  public void checkLeftHandAssignment(final AssignmentExpression expression) {
    Expression varRef = expression.getVarRef();
    if (varRef instanceof FeatureCall) {
      EObject referencedObject = ((FeatureCall) varRef).getFeature();
      if (!(referencedObject instanceof Property) && !(referencedObject instanceof Property)) {
        error(LEFT_HAND_ASSIGNMENT, ExpressionsPackage.Literals.ASSIGNMENT_EXPRESSION__VAR_REF);
      }
    } else if (varRef instanceof ElementReferenceExpression) {
      EObject referencedObject = ((ElementReferenceExpression) varRef).getReference();
      if (!(referencedObject instanceof Property)) {
        error(LEFT_HAND_ASSIGNMENT, ExpressionsPackage.Literals.ASSIGNMENT_EXPRESSION__VAR_REF);
      }

    } else {
      error(LEFT_HAND_ASSIGNMENT, ExpressionsPackage.Literals.ASSIGNMENT_EXPRESSION__VAR_REF);
    }
  }