@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);
        }
      }
    }
  }
  private IScope getTypeIdScope(Program program) {
    // never return null, rather NULLSCOPE
    if (program == null) return IScope.NULLSCOPE;

    // build some scope to include all TypeID elements, simple names
    List<TypeId> allIds = EcoreUtil2.getAllContentsOfType(program, TypeId.class);
    return Scopes.scopeFor(allIds);
  }
Beispiel #3
0
        public Type getStringType(EObject object) {
          EObject model = EcoreUtil.getRootContainer(object);
          List<SimpleType> allSimpleTypes =
              EcoreUtil2.getAllContentsOfType(model, SimpleType.class);
          Predicate<SimpleType> stringTypePredicate =
              new Predicate<SimpleType>() {
                @Override
                public boolean apply(SimpleType input) {
                  return "String".equals(input.getName());
                }
              };

          try {
            return Iterables.getOnlyElement(Iterables.filter(allSimpleTypes, stringTypePredicate));
          } catch (NoSuchElementException ex) {
            return null;
          }
        }