Search in sources :

Example 1 with RegularEventSpec

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

the class STextJavaValidator method checkReactionTriggerRegularEvent.

@Check(CheckType.FAST)
public void checkReactionTriggerRegularEvent(ReactionTrigger reactionTrigger) {
    for (int i = 0; i < reactionTrigger.getTriggers().size(); i++) {
        EventSpec eventSpec = reactionTrigger.getTriggers().get(i);
        if (eventSpec instanceof RegularEventSpec) {
            EObject element = unwrap(((RegularEventSpec) eventSpec).getEvent());
            if (element != null && (!(element instanceof Event))) {
                String elementName = "";
                if (element instanceof NamedElement) {
                    elementName = "'" + ((NamedElement) element).getName() + "' ";
                }
                error("Trigger " + elementName + "is no event.", StextPackage.Literals.REACTION_TRIGGER__TRIGGERS, i, TRIGGER_IS_NO_EVENT);
            }
        }
    }
}
Also used : TimeEventSpec(org.yakindu.sct.model.stext.stext.TimeEventSpec) RegularEventSpec(org.yakindu.sct.model.stext.stext.RegularEventSpec) EventSpec(org.yakindu.sct.model.stext.stext.EventSpec) EObject(org.eclipse.emf.ecore.EObject) ExitEvent(org.yakindu.sct.model.stext.stext.ExitEvent) EntryEvent(org.yakindu.sct.model.stext.stext.EntryEvent) Event(org.yakindu.base.types.Event) NamedElement(org.yakindu.base.base.NamedElement) RegularEventSpec(org.yakindu.sct.model.stext.stext.RegularEventSpec) Check(org.eclipse.xtext.validation.Check)

Example 2 with RegularEventSpec

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

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

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

the class StextTestFactory method _createRegularEventSpec.

public static RegularEventSpec _createRegularEventSpec(EventDefinition e1, ReactionTrigger rt) {
    RegularEventSpec e1Spec = StextFactory.eINSTANCE.createRegularEventSpec();
    e1Spec.setEvent(_createElementReferenceExpression(e1));
    if (rt != null)
        rt.getTriggers().add(e1Spec);
    return e1Spec;
}
Also used : RegularEventSpec(org.yakindu.sct.model.stext.stext.RegularEventSpec)

Aggregations

RegularEventSpec (org.yakindu.sct.model.stext.stext.RegularEventSpec)4 Test (org.junit.Test)2 ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)2 Statechart (org.yakindu.sct.model.sgraph.Statechart)2 Transition (org.yakindu.sct.model.sgraph.Transition)2 EventDefinition (org.yakindu.sct.model.stext.stext.EventDefinition)2 ReactionTrigger (org.yakindu.sct.model.stext.stext.ReactionTrigger)2 File (java.io.File)1 URI (org.eclipse.emf.common.util.URI)1 EObject (org.eclipse.emf.ecore.EObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 XMIResourceImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl)1 Check (org.eclipse.xtext.validation.Check)1 NamedElement (org.yakindu.base.base.NamedElement)1 Event (org.yakindu.base.types.Event)1 StextResource (org.yakindu.sct.model.stext.resource.StextResource)1 EntryEvent (org.yakindu.sct.model.stext.stext.EntryEvent)1 EventSpec (org.yakindu.sct.model.stext.stext.EventSpec)1 ExitEvent (org.yakindu.sct.model.stext.stext.ExitEvent)1 TimeEventSpec (org.yakindu.sct.model.stext.stext.TimeEventSpec)1