Search in sources :

Example 16 with Statechart

use of org.yakindu.sct.model.sgraph.Statechart in project statecharts by Yakindu.

the class STextExpressionParser method parseExpression.

public EObject parseExpression(String expression, String ruleName, String specification) {
    StextResource resource = getResource();
    resource.setURI(URI.createURI(getUri(), true));
    ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
    parserRule.setName(ruleName);
    IParseResult result = parser.parse(parserRule, new StringReader(expression));
    EObject rootASTElement = result.getRootASTElement();
    resource.getContents().add(rootASTElement);
    ListBasedDiagnosticConsumer diagnosticsConsumer = new ListBasedDiagnosticConsumer();
    Statechart sc = SGraphFactory.eINSTANCE.createStatechart();
    sc.setDomainID(domainId);
    sc.setName("sc");
    if (specification != null) {
        sc.setSpecification(specification);
    }
    resource.getContents().add(sc);
    resource.getLinkingDiagnostics().clear();
    linker.linkModel(sc, diagnosticsConsumer);
    linker.linkModel(rootASTElement, diagnosticsConsumer);
    resource.resolveLazyCrossReferences(CancelIndicator.NullImpl);
    resource.resolveLazyCrossReferences(CancelIndicator.NullImpl);
    Multimap<SpecificationElement, Diagnostic> diagnostics = resource.getLinkingDiagnostics();
    if (diagnostics.size() > 0) {
        throw new LinkingException(diagnostics.toString());
    }
    if (result.hasSyntaxErrors()) {
        StringBuilder errorMessages = new StringBuilder();
        Iterable<INode> syntaxErrors = result.getSyntaxErrors();
        for (INode iNode : syntaxErrors) {
            errorMessages.append(iNode.getSyntaxErrorMessage());
            errorMessages.append("\n");
        }
        throw new SyntaxException("Could not parse expression, syntax errors: " + errorMessages);
    }
    if (diagnosticsConsumer.hasConsumedDiagnostics(Severity.ERROR)) {
        throw new LinkingException("Error during linking: " + diagnosticsConsumer.getResult(Severity.ERROR));
    }
    return rootASTElement;
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) INode(org.eclipse.xtext.nodemodel.INode) StextResource(org.yakindu.sct.model.stext.resource.StextResource) SpecificationElement(org.yakindu.sct.model.sgraph.SpecificationElement) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) EObject(org.eclipse.emf.ecore.EObject) StringReader(java.io.StringReader) ListBasedDiagnosticConsumer(org.eclipse.xtext.resource.impl.ListBasedDiagnosticConsumer) Statechart(org.yakindu.sct.model.sgraph.Statechart) IParseResult(org.eclipse.xtext.parser.IParseResult)

Example 17 with Statechart

use of org.yakindu.sct.model.sgraph.Statechart in project statecharts by Yakindu.

the class SCTResourceTest method testRemoveOrphanedLinkingDiagnostics.

@Test
public void testRemoveOrphanedLinkingDiagnostics() throws Exception {
    Statechart statechart = createStatechart("internal: event Event1");
    res.getContents().add(statechart);
    Transition transition = createTransition("Event2 [true] / 3 * 3");
    res.getContents().add(transition);
    res.resolveLazyCrossReferences(CancelIndicator.NullImpl);
    assertEquals(1, res.getLinkingDiagnostics().size());
    transition.setSpecification("Event1 [true] / 3 * 3");
    res.resolveLazyCrossReferences(CancelIndicator.NullImpl);
    assertEquals(0, res.getLinkingDiagnostics().size());
}
Also used : Transition(org.yakindu.sct.model.sgraph.Transition) Statechart(org.yakindu.sct.model.sgraph.Statechart) Test(org.junit.Test)

Example 18 with Statechart

use of org.yakindu.sct.model.sgraph.Statechart in project statecharts by Yakindu.

the class SCTResourceTest method testLinkingSuccess.

@Test
public void testLinkingSuccess() throws Exception {
    Statechart statechart = createStatechart("internal: event Event1");
    res.getContents().add(statechart);
    Transition transition = createTransition("Event1 [true] / 3 * 3");
    res.getContents().add(transition);
    res.resolveLazyCrossReferences(CancelIndicator.NullImpl);
    assertEquals("" + res.getLinkingDiagnostics(), 0, res.getLinkingDiagnostics().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) Transition(org.yakindu.sct.model.sgraph.Transition) Statechart(org.yakindu.sct.model.sgraph.Statechart) EventDefinition(org.yakindu.sct.model.stext.stext.EventDefinition) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) RegularEventSpec(org.yakindu.sct.model.stext.stext.RegularEventSpec) Test(org.junit.Test)

Example 19 with Statechart

use of org.yakindu.sct.model.sgraph.Statechart in project statecharts by Yakindu.

the class ModelSequencerOrthogonalityTest method testSiblingRegionEntryOnComposite.

/**
 * For all and-states that a on the entry path of a transition the enter
 * sequences for all orthogonal parts must be called.
 */
@Test
public void testSiblingRegionEntryOnComposite() {
    Statechart sc = _createStatechart("sc");
    {
        InterfaceScope s_scope = _createInterfaceScope("Interface", sc);
        VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, s_scope);
        Region r = _createRegion("r", sc);
        {
            Entry r_entry = _createEntry(EntryKind.INITIAL, null, r);
            State s1 = _createState("s1", r);
            {
                Region r2 = _createRegion("r2", s1);
                {
                    Entry r2_entry = _createEntry(EntryKind.INITIAL, null, r2);
                    State s2 = _createState("s2", r2);
                    _createTransition(r2_entry, s2);
                }
                Region r3 = _createRegion("r3", s1);
                {
                    Entry r3_entry = _createEntry(EntryKind.INITIAL, null, r3);
                    State s3 = _createState("s3", r3);
                    {
                        Region r3a = _createRegion("r3a", s3);
                        {
                            Entry r3a_entry = _createEntry(EntryKind.INITIAL, null, r3a);
                            State s3a = _createState("s3a", r3a);
                            _createTransition(r3a_entry, s3a);
                        }
                        Region r3b = _createRegion("r3b", s3);
                        {
                            Entry r3b_entry = _createEntry(EntryKind.INITIAL, null, r3b);
                            State s3b = _createState("s3b", r3b);
                            _createTransition(r3b_entry, s3b);
                        }
                        Region r3c = _createRegion("r3c", s3);
                        {
                            Entry r3c_entry = _createEntry(EntryKind.INITIAL, null, r3c);
                            State s3c = _createState("s3c", r3c);
                            _createTransition(r3c_entry, s3c);
                        }
                    }
                    _createEntryAssignment(v1, s3, 42);
                    _createTransition(r3_entry, s3);
                }
                Region r4 = _createRegion("r4", s1);
                {
                    Entry r4_entry = _createEntry(EntryKind.INITIAL, null, r4);
                    State s4 = _createState("s4", r4);
                    _createTransition(r4_entry, s4);
                }
            }
            _createTransition(r_entry, s1);
            State s5 = _createState("s5", r);
            _createTransition(s5, findState(sc, "s3b"));
        }
    }
    ExecutionFlow flow = sequencer.transform(sc);
    ExecutionState _s2 = flow.getStates().get(1);
    assertEquals("sc.r.s1.r2.s2", _s2.getName());
    ExecutionState _s3 = flow.getStates().get(2);
    assertEquals("sc.r.s1.r3.s3", _s3.getName());
    ExecutionState _s3a = flow.getStates().get(3);
    assertEquals("sc.r.s1.r3.s3.r3a.s3a", _s3a.getName());
    ExecutionState _s3b = flow.getStates().get(4);
    assertEquals("sc.r.s1.r3.s3.r3b.s3b", _s3b.getName());
    ExecutionState _s3c = flow.getStates().get(5);
    assertEquals("sc.r.s1.r3.s3.r3c.s3c", _s3c.getName());
    ExecutionState _s4 = flow.getStates().get(6);
    assertEquals("sc.r.s1.r4.s4", _s4.getName());
    ExecutionState _s5 = flow.getStates().get(7);
    assertEquals("sc.r.s5", _s5.getName());
    Reaction _t = _s5.getReactions().get(0);
    assertTrue(_t.isTransition());
    Sequence _effect = (Sequence) _t.getEffect();
    assertEquals("wrong sequence: " + stepListAsString(_effect), 7, _effect.getSteps().size());
    assertCall(_effect, 0, _s5.getExitSequence());
    assertCall(_effect, 1, _s2.getSuperScope().getEnterSequences().get(0));
    assertCall(_s2.getSuperScope().getEnterSequences().get(0), 0, flow.getNodes().get(1).getReactSequence());
    assertCall(_effect, 2, _s3.getEntryAction());
    assertCall(_effect, 3, _s3a.getSuperScope().getEnterSequences().get(0));
    assertCall(_s3a.getSuperScope().getEnterSequences().get(0), 0, flow.getNodes().get(3).getReactSequence());
    assertCall(_effect, 4, _s3b.getEnterSequences().get(0));
    assertCall(_effect, 5, _s3c.getSuperScope().getEnterSequences().get(0));
    assertCall(_s3c.getSuperScope().getEnterSequences().get(0), 0, flow.getNodes().get(5).getReactSequence());
    assertCall(_effect, 6, _s4.getSuperScope().getEnterSequences().get(0));
    assertCall(_s4.getSuperScope().getEnterSequences().get(0), 0, flow.getNodes().get(6).getReactSequence());
}
Also used : ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) Entry(org.yakindu.sct.model.sgraph.Entry) SGraphTestFactory._createEntry(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createEntry) VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) SGraphTestFactory._createState(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState) ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) EnterState(org.yakindu.sct.model.sexec.EnterState) SCTTestUtil.findState(org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.findState) State(org.yakindu.sct.model.sgraph.State) 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) Sequence(org.yakindu.sct.model.sexec.Sequence) Reaction(org.yakindu.sct.model.sexec.Reaction) Test(org.junit.Test)

Example 20 with Statechart

use of org.yakindu.sct.model.sgraph.Statechart in project statecharts by Yakindu.

the class ModelSequencerOrthogonalityTest method testBottomUpTransitionExitSequence_C.

/**
 * A transition that exits from a deep orthogonal state structure should not
 * contain multiple calls to exit actions
 */
@Test
public void testBottomUpTransitionExitSequence_C() {
    Statechart sc = setUpDeepExitSC();
    _createTransition(findStateFullyQualified(sc, "sc.r.s.1.a.2.a"), findStateFullyQualified(sc, "sc.r.b"));
    ExecutionFlow flow = sequencer.transform(sc);
    ExecutionState _s = assertedState(flow, 0, "sc.r.s");
    ExecutionState _s1a = assertedState(flow, 1, "sc.r.s._1.a");
    ExecutionState _s1a1a = assertedState(flow, 2, "sc.r.s._1.a._1.a");
    ExecutionState _s1a1a1a = assertedState(flow, 3, "sc.r.s._1.a._1.a._1.a");
    ExecutionState _s1a1a2a = assertedState(flow, 4, "sc.r.s._1.a._1.a._2.a");
    ExecutionState _s1a2a = assertedState(flow, 5, "sc.r.s._1.a._2.a");
    ExecutionState _s1a2a1a = assertedState(flow, 6, "sc.r.s._1.a._2.a._1.a");
    ExecutionState _s1a2a2a = assertedState(flow, 7, "sc.r.s._1.a._2.a._2.a");
    ExecutionState _s2a = assertedState(flow, 8, "sc.r.s._2.a");
    ExecutionState _s2a1a = assertedState(flow, 9, "sc.r.s._2.a._1.a");
    ExecutionState _s2a1a1a = assertedState(flow, 10, "sc.r.s._2.a._1.a._1.a");
    ExecutionState _s2a1a2a = assertedState(flow, 11, "sc.r.s._2.a._1.a._2.a");
    ExecutionState _s2a2a = assertedState(flow, 12, "sc.r.s._2.a._2.a");
    ExecutionState _s2a2a1a = assertedState(flow, 13, "sc.r.s._2.a._2.a._1.a");
    ExecutionState _s2a2a2a = assertedState(flow, 14, "sc.r.s._2.a._2.a._2.a");
    ExecutionState _b = assertedState(flow, 15, "sc.r.b");
    // check the transition reaction ...
    Reaction _t = _s1a2a.getReactions().get(0);
    assertTrue(_t.isTransition());
    // check the exit sequence of _s
    Sequence _exit = assertedSequence(_t.getEffect());
    assertEquals("wrong steps: " + stepListAsString(_exit), 2, _exit.getSteps().size());
    assertedOrder(_exit, Lists.newArrayList(_s1a1a1a, _s1a1a2a, _s1a2a1a, _s1a2a2a, _s2a1a1a, _s2a1a2a, _s2a2a1a, _s2a2a2a), Lists.newArrayList(new StepLeaf(_s1a1a1a.getExitSequence()), // 
    new StepLeaf(_s1a1a2a.getExitSequence()), // 
    new StepLeaf(_s1a1a.getExitAction()), // 
    new StepLeaf(_s1a2a1a.getExitSequence()), // 
    new StepLeaf(_s1a2a2a.getExitSequence()), // 
    new StepLeaf(_s1a2a.getExitAction()), // 
    new StepLeaf(_s1a.getExitAction()), // 
    new StepLeaf(_s2a1a1a.getExitSequence()), // 
    new StepLeaf(_s2a1a2a.getExitSequence()), // 
    new StepLeaf(_s2a1a.getExitAction()), // 
    new StepLeaf(_s2a2a1a.getExitSequence()), // 
    new StepLeaf(_s2a2a2a.getExitSequence()), // 
    new StepLeaf(_s2a2a.getExitAction()), // 
    new StepLeaf(_s2a.getExitAction()), // 
    new StepLeaf(_s.getExitAction()), new StepLeaf(_b.getEnterSequences().get(0))));
    assertCall(_exit, 1, _b.getEnterSequences().get(0));
}
Also used : ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) 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) Sequence(org.yakindu.sct.model.sexec.Sequence) Reaction(org.yakindu.sct.model.sexec.Reaction) Test(org.junit.Test)

Aggregations

Statechart (org.yakindu.sct.model.sgraph.Statechart)132 Test (org.junit.Test)89 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)65 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)63 Region (org.yakindu.sct.model.sgraph.Region)59 State (org.yakindu.sct.model.sgraph.State)59 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)57 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)57 SGraphTestFactory._createState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState)51 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)48 StextTestFactory._createInterfaceScope (org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope)48 InterfaceScope (org.yakindu.sct.model.stext.stext.InterfaceScope)47 StextTestFactory._createVariableDefinition (org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition)47 Sequence (org.yakindu.sct.model.sexec.Sequence)40 Entry (org.yakindu.sct.model.sgraph.Entry)30 SCTTestUtil.findState (org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.findState)29 SGraphTestFactory._createEntry (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createEntry)29 Reaction (org.yakindu.sct.model.sexec.Reaction)25 Scope (org.yakindu.sct.model.sgraph.Scope)25 EnterState (org.yakindu.sct.model.sexec.EnterState)21