use of org.yakindu.sct.model.stext.stext.InternalScope in project statecharts by Yakindu.
the class STextJavaValidator method checkUnusedVariablesInInternalScope.
@Check(CheckType.FAST)
public void checkUnusedVariablesInInternalScope(InternalScope internalScope) {
EList<Declaration> internalScopeDeclarations = internalScope.getDeclarations();
EObject rootContainer = EcoreUtil.getRootContainer(internalScope);
Resource rootRes = getResource(rootContainer);
Statechart statechart = (Statechart) EcoreUtil.getObjectByType(rootRes.getContents(), SGraphPackage.Literals.STATECHART);
if (statechart == null)
return;
List<ElementReferenceExpression> allUsedElementReferences = EcoreUtil2.getAllContentsOfType(statechart, ElementReferenceExpression.class);
if (statechart.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);
}
}
}
}
use of org.yakindu.sct.model.stext.stext.InternalScope in project statecharts by Yakindu.
the class STextJavaValidator method checkDeprecatedLocalEventDefinition.
@Check(CheckType.FAST)
public void checkDeprecatedLocalEventDefinition(EventDefinition event) {
// applies only for local event definitions
if (event.eContainer() instanceof InternalScope && event.getDirection() == Direction.LOCAL) {
ICompositeNode definitionNode = NodeModelUtils.getNode(event);
String tokenText = NodeModelUtils.getTokenText(definitionNode);
if (tokenText == null || tokenText.isEmpty())
return;
if (tokenText.contains(Direction.LOCAL.getLiteral())) {
warning(String.format(STextValidationMessages.DECLARATION_DEPRECATED, Direction.LOCAL.getLiteral()), event, TypesPackage.Literals.EVENT__DIRECTION);
}
}
}
use of org.yakindu.sct.model.stext.stext.InternalScope in project statecharts by Yakindu.
the class STextScopeProvider method getUnnamedTopLevelScope.
/**
* Returns a scope with all toplevel declarations of unnamed scope
*/
protected IScope getUnnamedTopLevelScope(final EObject context, EReference reference) {
List<EObject> scopeCandidates = Lists.newArrayList();
Statechart statechart = getStatechart(context);
if (statechart == null)
return IScope.NULLSCOPE;
EList<Scope> scopes = statechart.getScopes();
for (Scope scope : scopes) {
if (scope instanceof InterfaceScope) {
String name = ((InterfaceScope) scope).getName();
if (name == null || name.trim().length() == 0) {
scopeCandidates.addAll(scope.getDeclarations());
}
} else if (scope instanceof InternalScope) {
scopeCandidates.addAll(scope.getDeclarations());
}
}
// Add import scope
IScope scope = getDelegate().getScope(context, reference);
return Scopes.scopeFor(scopeCandidates, scope);
}
Aggregations