Search in sources :

Example 6 with InternalScope

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);
            }
        }
    }
}
Also used : VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) EObject(org.eclipse.emf.ecore.EObject) AbstractSCTResource(org.yakindu.sct.model.sgraph.resource.AbstractSCTResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) Statechart(org.yakindu.sct.model.sgraph.Statechart) Declaration(org.yakindu.base.types.Declaration) EventDefinition(org.yakindu.sct.model.stext.stext.EventDefinition) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) OperationDefinition(org.yakindu.sct.model.stext.stext.OperationDefinition) Check(org.eclipse.xtext.validation.Check)

Example 7 with InternalScope

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);
        }
    }
}
Also used : InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Check(org.eclipse.xtext.validation.Check)

Example 8 with InternalScope

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);
}
Also used : FilteringScope(org.eclipse.xtext.scoping.impl.FilteringScope) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) Scope(org.yakindu.sct.model.sgraph.Scope) IScope(org.eclipse.xtext.scoping.IScope) SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) ImportScope(org.eclipse.xtext.scoping.impl.ImportScope) EObject(org.eclipse.emf.ecore.EObject) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) Statechart(org.yakindu.sct.model.sgraph.Statechart) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) IScope(org.eclipse.xtext.scoping.IScope)

Aggregations

InternalScope (org.yakindu.sct.model.stext.stext.InternalScope)8 Scope (org.yakindu.sct.model.sgraph.Scope)5 EObject (org.eclipse.emf.ecore.EObject)4 Statechart (org.yakindu.sct.model.sgraph.Statechart)4 InterfaceScope (org.yakindu.sct.model.stext.stext.InterfaceScope)4 Test (org.junit.Test)3 Check (org.eclipse.xtext.validation.Check)2 ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)2 Declaration (org.yakindu.base.types.Declaration)2 EventDefinition (org.yakindu.sct.model.stext.stext.EventDefinition)2 ArrayList (java.util.ArrayList)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 Diagram (org.eclipse.gmf.runtime.notation.Diagram)1 Keyword (org.eclipse.xtext.Keyword)1 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 IScope (org.eclipse.xtext.scoping.IScope)1 FilteringScope (org.eclipse.xtext.scoping.impl.FilteringScope)1 ImportScope (org.eclipse.xtext.scoping.impl.ImportScope)1 SimpleScope (org.eclipse.xtext.scoping.impl.SimpleScope)1