@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); } } } }
protected void _declareContents(final InternalScope scope) throws NumberFormatException { EList<Declaration> _declarations = scope.getDeclarations(); for (final Declaration declaration : _declarations) { this.addToScope(declaration); } }