Search in sources :

Example 1 with Declaration

use of org.yakindu.base.types.Declaration in project statecharts by Yakindu.

the class RenameElementHandler method findElementForFakeInStatechart.

private NamedElement findElementForFakeInStatechart(NamedElement fakeElement) {
    Resource resource = fakeElement.eResource();
    // only do something if element is really from fake resource
    if (resource instanceof LazyLinkingResource) {
        Statechart sct = getStatechartFromFakeResource((LazyLinkingResource) resource);
        EList<Scope> scopes = sct.getScopes();
        for (Scope scope : scopes) {
            // check all declarations
            EList<Declaration> declarations = scope.getDeclarations();
            for (Declaration decl : declarations) {
                if (decl.eClass().getName().equals(fakeElement.eClass().getName()) && decl.getName().equals(fakeElement.getName())) {
                    return decl;
                }
            }
            // check scope itself it is a named one
            if (scope instanceof NamedElement) {
                NamedElement namedScope = (NamedElement) scope;
                if (namedScope.eClass().getName().equals(fakeElement.eClass().getName()) && namedScope.getName().equals(fakeElement.getName())) {
                    return namedScope;
                }
            }
        }
    }
    return fakeElement;
}
Also used : Scope(org.yakindu.sct.model.sgraph.Scope) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) Resource(org.eclipse.emf.ecore.resource.Resource) Statechart(org.yakindu.sct.model.sgraph.Statechart) Declaration(org.yakindu.base.types.Declaration) NamedElement(org.yakindu.base.base.NamedElement)

Example 2 with Declaration

use of org.yakindu.base.types.Declaration in project statecharts by Yakindu.

the class ModelSequencertDeclarationsTest method testMapScope.

@SuppressWarnings("unused")
@Test
public void testMapScope() {
    InterfaceScope scope = _createInterfaceScope(null, null);
    EventDefinition e1 = _createEventDefinition("e1", scope);
    EventDefinition e2 = _createEventDefinition("e2", scope);
    VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, scope);
    Scope _scope = structureMapping.mapScope(scope);
    assertTrue(_scope instanceof InterfaceScope);
    assertEquals(3, _scope.getDeclarations().size());
    for (int i = 0; i < _scope.getDeclarations().size(); i++) {
        Declaration s_decl = scope.getDeclarations().get(i);
        Declaration r_decl = _scope.getDeclarations().get(i);
        assertNotSame(s_decl, r_decl);
        assertEquals(s_decl.getName(), r_decl.getName());
        assertEquals(s_decl.getClass(), r_decl.getClass());
    }
}
Also used : VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) StextTestFactory._createInternalScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInternalScope) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) StextTestFactory._createInterfaceScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope) Scope(org.yakindu.sct.model.sgraph.Scope) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) StextTestFactory._createInterfaceScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope) Declaration(org.yakindu.base.types.Declaration) StextTestFactory._createEventDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createEventDefinition) EventDefinition(org.yakindu.sct.model.stext.stext.EventDefinition) Test(org.junit.Test)

Example 3 with Declaration

use of org.yakindu.base.types.Declaration in project statecharts by Yakindu.

the class SCTResourceTest method testStatechartParsing.

@Test
public void testStatechartParsing() {
    Statechart statechart = createStatechart("internal: event Event1");
    assertEquals(0, statechart.getScopes().size());
    res.getContents().add(statechart);
    assertEquals(1, statechart.getScopes().size());
    Scope scope = statechart.getScopes().get(0);
    assertTrue(scope instanceof InternalScope);
    EList<Declaration> declarations = ((InternalScope) scope).getDeclarations();
    Declaration declaration = declarations.get(0);
    assertTrue(declaration instanceof EventDefinition);
    assertEquals("" + res.getSyntaxDiagnostics(), 0, res.getSyntaxDiagnostics().size());
}
Also used : Scope(org.yakindu.sct.model.sgraph.Scope) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) 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) Test(org.junit.Test)

Example 4 with Declaration

use of org.yakindu.base.types.Declaration in project statecharts by Yakindu.

the class ImportDeclarationImpl method setDeclaration.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setDeclaration(Declaration newDeclaration) {
    Declaration oldDeclaration = declaration;
    declaration = newDeclaration;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, SGraphPackage.IMPORT_DECLARATION__DECLARATION, oldDeclaration, declaration));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) ImportDeclaration(org.yakindu.sct.model.sgraph.ImportDeclaration) Declaration(org.yakindu.base.types.Declaration)

Example 5 with Declaration

use of org.yakindu.base.types.Declaration 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)

Aggregations

Declaration (org.yakindu.base.types.Declaration)6 Scope (org.yakindu.sct.model.sgraph.Scope)3 Statechart (org.yakindu.sct.model.sgraph.Statechart)3 EventDefinition (org.yakindu.sct.model.stext.stext.EventDefinition)3 InternalScope (org.yakindu.sct.model.stext.stext.InternalScope)3 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)3 EObject (org.eclipse.emf.ecore.EObject)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 Check (org.eclipse.xtext.validation.Check)2 Test (org.junit.Test)2 ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)2 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 LazyLinkingResource (org.eclipse.xtext.linking.lazy.LazyLinkingResource)1 QualifiedName (org.eclipse.xtext.naming.QualifiedName)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 NamedElement (org.yakindu.base.base.NamedElement)1 AssignmentExpression (org.yakindu.base.expressions.expressions.AssignmentExpression)1 Expression (org.yakindu.base.expressions.expressions.Expression)1 FeatureCall (org.yakindu.base.expressions.expressions.FeatureCall)1 PostFixUnaryExpression (org.yakindu.base.expressions.expressions.PostFixUnaryExpression)1