예제 #1
0
 protected void checkElementReferenceEffect(ElementReferenceExpression refExp) {
   if (!(refExp.getReference() instanceof Operation)) {
     if (refExp.getReference() instanceof Property) {
       error(
           "Access to property '"
               + nameProvider.getFullyQualifiedName(refExp.getReference())
               + "' has no effect.",
           refExp,
           ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE,
           INSIGNIFICANT_INDEX,
           FEATURE_CALL_HAS_NO_EFFECT);
     } else if (refExp.getReference() instanceof Event) {
       error(
           "Access to event '"
               + nameProvider.getFullyQualifiedName(refExp.getReference())
               + "' has no effect.",
           refExp,
           ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE,
           INSIGNIFICANT_INDEX,
           FEATURE_CALL_HAS_NO_EFFECT);
     } else {
       error(
           "Access to feature '"
               + nameProvider.getFullyQualifiedName(refExp.getReference())
               + "' has no effect.",
           refExp,
           ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE,
           INSIGNIFICANT_INDEX,
           FEATURE_CALL_HAS_NO_EFFECT);
     }
   }
 }
예제 #2
0
 @Check(CheckType.FAST)
 public void checkOperationArguments_TypedElementReferenceExpression(
     final ElementReferenceExpression call) {
   if (call.getReference() instanceof Operation) {
     Operation operation = (Operation) call.getReference();
     EList<Parameter> parameters = operation.getParameters();
     EList<Expression> args = call.getArgs();
     if (parameters.size() != args.size()) {
       error("Wrong number of arguments, expected " + parameters, null);
     }
   }
 }
예제 #3
0
 @Check(CheckType.FAST)
 public void checkFeatureCall(ElementReferenceExpression call) {
   if (call.eContainer() instanceof FeatureCall) {
     return;
   }
   if (call.getReference() instanceof Scope) {
     error(
         "A variable, event or operation is required",
         ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE,
         INSIGNIFICANT_INDEX,
         FEATURE_CALL_TO_SCOPE);
   }
 }
예제 #4
0
  @Check(CheckType.NORMAL)
  public void checkUnusedVariablesInInternalScope(InternalScope internalScope) {
    EList<Declaration> internalScopeDeclarations = internalScope.getDeclarations();

    EObject rootContainer = EcoreUtil.getRootContainer(internalScope);
    Resource rootRes = getResource(rootContainer);
    EList<EObject> contents = rootRes.getContents();
    Statechart sct = null;
    for (EObject eObject : contents) {
      if (eObject instanceof Statechart) {
        sct = (Statechart) eObject;
        break;
      }
    }
    List<ElementReferenceExpression> allUsedElementReferences =
        EcoreUtil2.getAllContentsOfType(sct, ElementReferenceExpression.class);

    if (sct.getSpecification() != null) {
      for (Declaration internalDeclaration : internalScopeDeclarations) {
        boolean internalDeclarationUsed = false;
        for (ElementReferenceExpression elementReference : allUsedElementReferences) {
          if (elementReference.getReference().eContainer() instanceof InternalScope) {
            if (elementReference.getReference() instanceof VariableDefinition) {
              if (((VariableDefinition) elementReference.getReference())
                      .getName()
                      .equals(internalDeclaration.getName())
                  && internalDeclaration instanceof VariableDefinition) {
                internalDeclarationUsed = true;
                break;
              }
            } else if (elementReference.getReference() instanceof EventDefinition) {
              if (((EventDefinition) elementReference.getReference())
                      .getName()
                      .equals(internalDeclaration.getName())
                  && internalDeclaration instanceof EventDefinition) {
                internalDeclarationUsed = true;
                break;
              }
            } else if (elementReference.getReference() instanceof OperationDefinition) {
              if (((OperationDefinition) elementReference.getReference())
                      .getName()
                      .equals(internalDeclaration.getName())
                  && internalDeclaration instanceof OperationDefinition) {
                internalDeclarationUsed = true;
                break;
              }
            }
          }
        }
        if (!internalDeclarationUsed) {

          if (internalDeclaration instanceof VariableDefinition
              || internalDeclaration instanceof EventDefinition
              || internalDeclaration instanceof OperationDefinition)
            warning(INTERNAL_DECLARATION_UNUSED, internalDeclaration, null, -1);
        }
      }
    }
  }
  /**
   * The cycle sequence of a state that only consists of local reactions includes sequential
   * processing of the local reactions.
   */
  @SuppressWarnings("unused")
  @Test
  public void testStateCycle_WithLocalReactionsOnly() {
    MinimalTSC tsc = new MinimalTSC();

    VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, tsc.s_scope);

    // the first local reaction conforms to "e1 / x=42;"
    LocalReaction lr1 = _createLocalReaction(tsc.s1, null);
    _createRegularEventSpec(tsc.e1, (ReactionTrigger) lr1.getTrigger());
    ReactionEffect lr1_eff = _createReactionEffect(lr1);
    AssignmentExpression assign1 =
        _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), lr1_eff);

    // the secont local reaction conforms to "e1 [x==42] / x=0;"
    LocalReaction lr2 = _createLocalReaction(tsc.s1, null);
    _createRegularEventSpec(tsc.e1, (ReactionTrigger) lr2.getTrigger());
    LogicalRelationExpression lr2_equals =
        ExpressionsFactory.eINSTANCE.createLogicalRelationExpression();
    lr2_equals.setOperator(RelationalOperator.EQUALS);
    ElementReferenceExpression lr2_varRef =
        ExpressionsFactory.eINSTANCE.createElementReferenceExpression();
    lr2_varRef.setReference(v1);
    PrimitiveValueExpression lr2_value = _createValue(42);
    lr2_equals.setLeftOperand(lr2_varRef);
    lr2_equals.setRightOperand(lr2_value);
    ((ReactionTrigger) lr2.getTrigger()).setGuard(createGuardExpression(lr2_equals));
    ReactionEffect lr2_eff = _createReactionEffect(lr2);
    AssignmentExpression assign2 =
        _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(0), lr2_eff);

    // the third local reaction conforms to: "[x==0] / x=1;"
    LocalReaction lr3 = _createLocalReaction(tsc.s1, null);
    LogicalRelationExpression lr3_equals =
        ExpressionsFactory.eINSTANCE.createLogicalRelationExpression();
    lr3_equals.setOperator(RelationalOperator.EQUALS);
    ElementReferenceExpression lr3_varRef =
        ExpressionsFactory.eINSTANCE.createElementReferenceExpression();
    lr3_varRef.setReference(v1);
    PrimitiveValueExpression lr3_value = _createValue(0);
    lr3_equals.setLeftOperand(lr3_varRef);
    lr3_equals.setRightOperand(lr3_value);
    ((ReactionTrigger) lr3.getTrigger()).setGuard(createGuardExpression(lr3_equals));
    ReactionEffect lr3_eff = _createReactionEffect(lr3);
    AssignmentExpression assign3 =
        _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(1), lr3_eff);

    ExecutionFlow flow = sequencer.transform(tsc.sc);

    // test state with one outgoing transition
    ExecutionState s1 = flow.getStates().get(0);
    assertEquals(tsc.s1.getName(), s1.getSimpleName());

    assertEquals(3, s1.getReactions().size());

    assertNotNull(s1.getReactSequence());

    Step step = s1.getReactSequence().getSteps().get(0);
    Sequence _seq =
        (Sequence) assertedSequence(assertedSequence(step).getSteps().get(0)).getSteps().get(0);
    assertEquals(3, _seq.getSteps().size());

    // check first local reaction
    If _lr1 = (If) _seq.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());

    // check second local reaction
    If _lr2 = (If) _seq.getSteps().get(1);
    assertClass(LogicalAndExpression.class, _lr2.getCheck().getCondition());
    assertSame(s1.getReactions().get(1).getCheck().getCondition(), _lr2.getCheck().getCondition());
    Call _lr2_eff_call = (Call) _lr2.getThenStep();
    assertSame(s1.getReactions().get(1).getEffect(), _lr2_eff_call.getStep());

    // check the third local reaction
    If _lr3 = (If) _seq.getSteps().get(2);
    assertClass(LogicalRelationExpression.class, _lr3.getCheck().getCondition());
    assertSame(s1.getReactions().get(2).getCheck().getCondition(), _lr3.getCheck().getCondition());
    Call _lr3_eff_call = (Call) _lr3.getThenStep();
    assertSame(s1.getReactions().get(2).getEffect(), _lr3_eff_call.getStep());
  }
예제 #6
0
  /**
   * Validates if a keyword should be viewed by the proposal view.
   *
   * <p>Builds dependent on the ContentAssistContext a list with keywords which shouldn't be
   * displayed by the proposal view.
   */
  @Override
  public void completeKeyword(
      Keyword keyword,
      ContentAssistContext contentAssistContext,
      ICompletionProposalAcceptor acceptor) {
    List<Keyword> suppressKeywords = new ArrayList<Keyword>();
    // context Transition
    if (contentAssistContext.getRootModel() instanceof TransitionSpecification) {
      suppressKeywords.addAll(
          getKeywords(grammarAccess.getEntryEventAccess().getGroup().eContents()));
      suppressKeywords.addAll(
          getKeywords(grammarAccess.getExitEventAccess().getGroup().eContents()));
    }
    // context States
    else if (contentAssistContext.getRootModel() instanceof SimpleScope) {
      suppressKeywords.addAll(
          getKeywords(grammarAccess.getVariableDefinitionAccess().getGroup().eContents()));
      suppressKeywords.addAll(
          getKeywords(grammarAccess.getEventDefinitionAccess().getGroup().eContents()));
      // suppressKeywords.addAll(getKeywords(grammarAccess.getExitpointAccess()
      // .getGroup().eContents()));
      // suppressKeywords.addAll(getKeywords(grammarAccess.getEntrypointAccess()
      // .getGroup().eContents()));
      suppressKeywords.addAll(
          getKeywords(grammarAccess.getDirectionAccess().getAlternatives().eContents()));
      suppressKeywords.addAll(
          getKeywords(grammarAccess.getOperationDefinitionAccess().getGroup().eContents()));
    }
    // context Statechart
    else if (contentAssistContext.getRootModel() instanceof StatechartSpecification) {
      suppressKeywords.addAll(
          getKeywords(grammarAccess.getExitEventAccess().getGroup().eContents()));
      suppressKeywords.addAll(
          getKeywords(grammarAccess.getEntryEventAccess().getGroup().eContents()));

      if (!atLeastOnePackageExistsInIndex(getSctResource(contentAssistContext.getRootModel()))) {
        suppressKeywords.addAll(
            getKeywords(grammarAccess.getImportScopeAccess().getGroup().eContents()));
      }
    }

    EObject currentModel = contentAssistContext.getCurrentModel();
    if (currentModel instanceof InterfaceScope) {
      suppressKeywords.addAll(
          getKeywords(grammarAccess.getLocalReactionAccess().getGroup().eContents()));
      suppressKeywords.addAll(
          getKeywords(grammarAccess.getAlwaysEventAccess().getGroup().eContents()));
      // suppressKeywords.addAll(getKeywords(grammarAccess.getOnCycleEventAccess()
      // .getGroup().eContents()));
      suppressKeywords.addAll(
          getKeywords(grammarAccess.getTimeEventTypeAccess().getAlternatives().eContents()));
      suppressKeywords.add(grammarAccess.getDirectionAccess().getLOCALLocalKeyword_0_0());
    }

    if (currentModel instanceof FeatureCall) {
      FeatureCall featureCall = (FeatureCall) currentModel;
      if (!(featureCall.getFeature() instanceof Operation)) {
        suppressKeywords.add(
            grammarAccess.getFeatureCallAccess().getOperationCallLeftParenthesisKeyword_1_3_0_0());
      }
    }
    if (currentModel instanceof ElementReferenceExpression) {
      ElementReferenceExpression referenceExpression = (ElementReferenceExpression) currentModel;
      if (!(referenceExpression.getReference() instanceof Operation)) {
        suppressKeywords.add(
            grammarAccess
                .getElementReferenceExpressionAccess()
                .getOperationCallLeftParenthesisKeyword_2_0_0());
      }
    }
    if (currentModel instanceof InternalScope) {
      suppressKeywords.add(grammarAccess.getDirectionAccess().getINInKeyword_1_0());
      suppressKeywords.add(grammarAccess.getDirectionAccess().getOUTOutKeyword_2_0());
    }

    if (!suppressKeywords.contains(keyword)) {
      super.completeKeyword(keyword, contentAssistContext, new AcceptorDelegate(acceptor));
    }
  }