Search in sources :

Example 11 with EventDefinition

use of org.yakindu.sct.model.stext.stext.EventDefinition 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 12 with EventDefinition

use of org.yakindu.sct.model.stext.stext.EventDefinition in project statecharts by Yakindu.

the class SCTResourceTest method testParsingOnLoad.

@Test
public void testParsingOnLoad() throws Exception {
    File tmpFile = File.createTempFile("SCTResource", "test.test");
    tmpFile.deleteOnExit();
    URI uri = URI.createFileURI(tmpFile.getPath().toString());
    Resource resource = new XMIResourceImpl(uri);
    Statechart statechart = createStatechart("internal: event Event1");
    resource.getContents().add(statechart);
    Transition transition = createTransition("Event1 [true] / 3 * 3");
    resource.getContents().add(transition);
    resource.save(Collections.EMPTY_MAP);
    res.setURI(uri);
    res.load(Collections.EMPTY_MAP);
    statechart = (Statechart) res.getContents().get(0);
    transition = (Transition) res.getContents().get(1);
    assertEquals("" + res.getErrors(), 0, res.getErrors().size());
    ReactionTrigger trigger = (ReactionTrigger) transition.getTrigger();
    RegularEventSpec eventSpec = (RegularEventSpec) trigger.getTriggers().get(0);
    ElementReferenceExpression expression = (ElementReferenceExpression) eventSpec.getEvent();
    EventDefinition reference = (EventDefinition) expression.getReference();
    assertNotNull(reference);
    assertEquals("Event1", reference.getName());
}
Also used : ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) StextResource(org.yakindu.sct.model.stext.resource.StextResource) Resource(org.eclipse.emf.ecore.resource.Resource) Transition(org.yakindu.sct.model.sgraph.Transition) Statechart(org.yakindu.sct.model.sgraph.Statechart) EventDefinition(org.yakindu.sct.model.stext.stext.EventDefinition) File(java.io.File) URI(org.eclipse.emf.common.util.URI) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) XMIResourceImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl) RegularEventSpec(org.yakindu.sct.model.stext.stext.RegularEventSpec) Test(org.junit.Test)

Example 13 with EventDefinition

use of org.yakindu.sct.model.stext.stext.EventDefinition in project statecharts by Yakindu.

the class ModelSequencerStateReactionTest method testMultipleRegularEventTriggerCondition.

/**
 * Multiple trigger events of a ReactionTrigger will be converted to a
 * condition that consists of a ElementReferenceExpressions connected by
 * LogicalOrExpressions.
 *
 * e1, e1 -> e1 || e2
 */
@Test
public void testMultipleRegularEventTriggerCondition() {
    EventDefinition e1 = _createEventDefinition("e1", null);
    EventDefinition e2 = _createEventDefinition("e2", null);
    ReactionTrigger tr1 = _createReactionTrigger(null);
    _createRegularEventSpec(e1, tr1);
    _createRegularEventSpec(e2, tr1);
    Expression s = behaviorMapping.buildCondition(tr1);
    assertTrue(s instanceof LogicalOrExpression);
    assertClass(ElementReferenceExpression.class, ((LogicalOrExpression) s).getLeftOperand());
    assertClass(ElementReferenceExpression.class, ((LogicalOrExpression) s).getRightOperand());
}
Also used : StextTestFactory._createReactionTrigger(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) LogicalAndExpression(org.yakindu.base.expressions.expressions.LogicalAndExpression) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) LogicalOrExpression(org.yakindu.base.expressions.expressions.LogicalOrExpression) NumericalMultiplyDivideExpression(org.yakindu.base.expressions.expressions.NumericalMultiplyDivideExpression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) StextTestFactory.createGuardExpression(org.yakindu.sct.model.stext.test.util.StextTestFactory.createGuardExpression) Expression(org.yakindu.base.expressions.expressions.Expression) ParenthesizedExpression(org.yakindu.base.expressions.expressions.ParenthesizedExpression) PrimitiveValueExpression(org.yakindu.base.expressions.expressions.PrimitiveValueExpression) LogicalOrExpression(org.yakindu.base.expressions.expressions.LogicalOrExpression) StextTestFactory._createEventDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createEventDefinition) EventDefinition(org.yakindu.sct.model.stext.stext.EventDefinition) Test(org.junit.Test)

Example 14 with EventDefinition

use of org.yakindu.sct.model.stext.stext.EventDefinition in project statecharts by Yakindu.

the class ModelSequencertDeclarationsTest method testTriggerEventDeclarationIntegrity.

/**
 * The event refs used in the trigger condition must refer to the event
 * declarations in the flow model and not the sc source model.
 */
@Test
public void testTriggerEventDeclarationIntegrity() {
    Statechart sc = _createStatechart("test");
    InterfaceScope s_scope = _createInterfaceScope("Interface", sc);
    EventDefinition e1 = _createEventDefinition("e1", s_scope);
    Region r = _createRegion("main", sc);
    State s1 = _createState("S1", r);
    State s2 = _createState("S2", r);
    Transition t = _createTransition(s1, s2);
    ReactionTrigger tr1 = _createReactionTrigger(t);
    _createRegularEventSpec(e1, tr1);
    ExecutionFlow flow = sequencer.transform(sc);
    EventDefinition _e1 = (EventDefinition) flow.getScopes().get(0).getDeclarations().get(0);
    assertNotSame(e1, _e1);
    assertEquals(e1.getName(), _e1.getName());
    assertEquals(2, flow.getStates().size());
    assertEquals(s1.getName(), flow.getStates().get(0).getSimpleName());
    Step step = flow.getStates().get(0).getReactSequence().getSteps().get(0);
    If _if = (If) assertedSequence(assertedSequence(assertedSequence(step).getSteps().get(0)).getSteps().get(0)).getSteps().get(0);
    ElementReferenceExpression _ere = (ElementReferenceExpression) _if.getCheck().getCondition();
    assertSame(_e1, _ere.getReference());
}
Also used : StextTestFactory._createReactionTrigger(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) SGraphTestFactory._createState(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState) State(org.yakindu.sct.model.sgraph.State) Transition(org.yakindu.sct.model.sgraph.Transition) SGraphTestFactory._createTransition(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createTransition) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) Statechart(org.yakindu.sct.model.sgraph.Statechart) SGraphTestFactory._createStatechart(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) StextTestFactory._createInterfaceScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope) Region(org.yakindu.sct.model.sgraph.Region) SGraphTestFactory._createRegion(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion) Step(org.yakindu.sct.model.sexec.Step) StextTestFactory._createEventDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createEventDefinition) EventDefinition(org.yakindu.sct.model.stext.stext.EventDefinition) If(org.yakindu.sct.model.sexec.If) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) Test(org.junit.Test)

Example 15 with EventDefinition

use of org.yakindu.sct.model.stext.stext.EventDefinition 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

EventDefinition (org.yakindu.sct.model.stext.stext.EventDefinition)15 Test (org.junit.Test)13 Statechart (org.yakindu.sct.model.sgraph.Statechart)11 StextTestFactory._createEventDefinition (org.yakindu.sct.model.stext.test.util.StextTestFactory._createEventDefinition)10 ReactionTrigger (org.yakindu.sct.model.stext.stext.ReactionTrigger)9 ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)8 Transition (org.yakindu.sct.model.sgraph.Transition)8 Region (org.yakindu.sct.model.sgraph.Region)7 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)7 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)7 StextTestFactory._createReactionTrigger (org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger)7 SGraphTestFactory._createTransition (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createTransition)6 InterfaceScope (org.yakindu.sct.model.stext.stext.InterfaceScope)6 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)6 StextTestFactory._createInterfaceScope (org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope)6 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)5 State (org.yakindu.sct.model.sgraph.State)5 SGraphTestFactory._createState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState)5 StextTestFactory._createVariableDefinition (org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition)5 AssignmentExpression (org.yakindu.base.expressions.expressions.AssignmentExpression)4