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());
}
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());
}
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());
}
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());
}
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);
}
}
}
}
Aggregations