예제 #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.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);
        }
      }
    }
  }
예제 #4
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);
   }
 }
예제 #5
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));
    }
  }