Search in sources :

Example 1 with ArgumentedAnnotation

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

the class CycleBasedSimulationEngine method scheduleCycleEvent.

private void scheduleCycleEvent() {
    Long cyclePeriod = DEFAULT_CYCLE_PERIOD;
    ArgumentedAnnotation cycleBased = (ArgumentedAnnotation) getStatechart().getAnnotationOfType(CYCLE_BASED_ANNOTATION);
    if (cycleBased != null) {
        cyclePeriod = (Long) statementInterpreter.evaluate(cycleBased.getExpressions().get(0), SRuntimeFactory.eINSTANCE.createExecutionContext());
    }
    TimeTask cycleTask = new TimeTask("$cycle", () -> {
        try {
            interpreter.runCycle();
        } catch (Exception e) {
            handleException(e);
        }
    }, Priority.LOW);
    timeTaskScheduler.scheduleTimeTask(cycleTask, true, cyclePeriod);
}
Also used : ArgumentedAnnotation(org.yakindu.sct.model.stext.stext.ArgumentedAnnotation) TimeTask(org.yakindu.sct.simulation.core.engine.scheduling.ITimeTaskScheduler.TimeTask)

Example 2 with ArgumentedAnnotation

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

the class AbstractExecutionFlowTest method getCyclePeriod.

protected long getCyclePeriod() {
    ArgumentedAnnotation annotation = (ArgumentedAnnotation) ((Statechart) flow.getSourceElement()).getAnnotationOfType(CYCLE_BASED_ANNOTATION);
    long cyclePeriod = 200;
    if (annotation != null) {
        cyclePeriod = (Long) stmtInterpreter.evaluate(annotation.getExpressions().get(0), context);
    }
    return cyclePeriod;
}
Also used : ArgumentedAnnotation(org.yakindu.sct.model.stext.stext.ArgumentedAnnotation)

Example 3 with ArgumentedAnnotation

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

the class StextResource method parseStatechart.

protected void parseStatechart(Statechart statechart) {
    IParseResult parseResult = parse(statechart, StatechartSpecification.class.getSimpleName());
    StatechartSpecification rootASTElement = (StatechartSpecification) parseResult.getRootASTElement();
    statechart.setNamespace(rootASTElement.getNamespace());
    statechart.getScopes().clear();
    EList<Scope> definitionScopes = rootASTElement.getScopes();
    if (definitionScopes != null) {
        statechart.getScopes().addAll(definitionScopes);
    }
    statechart.getAnnotations().clear();
    EList<ArgumentedAnnotation> annotations = rootASTElement.getAnnotations();
    if (annotations != null) {
        statechart.getAnnotations().addAll(annotations);
    }
}
Also used : Scope(org.yakindu.sct.model.sgraph.Scope) StatechartSpecification(org.yakindu.sct.model.stext.stext.StatechartSpecification) ArgumentedAnnotation(org.yakindu.sct.model.stext.stext.ArgumentedAnnotation) IParseResult(org.eclipse.xtext.parser.IParseResult)

Aggregations

ArgumentedAnnotation (org.yakindu.sct.model.stext.stext.ArgumentedAnnotation)3 IParseResult (org.eclipse.xtext.parser.IParseResult)1 Scope (org.yakindu.sct.model.sgraph.Scope)1 StatechartSpecification (org.yakindu.sct.model.stext.stext.StatechartSpecification)1 TimeTask (org.yakindu.sct.simulation.core.engine.scheduling.ITimeTaskScheduler.TimeTask)1