use of org.yakindu.sct.model.stext.stext.OperationDefinition in project statecharts by Yakindu.
the class StextTestFactory method _createOperation.
public static OperationDefinition _createOperation(String name, Scope scope) {
OperationDefinition e = StextFactory.eINSTANCE.createOperationDefinition();
e.setName(name);
if (scope != null)
scope.getDeclarations().add(e);
return e;
}
use of org.yakindu.sct.model.stext.stext.OperationDefinition in project statecharts by Yakindu.
the class ModelSequencertDeclarationsTest method testOperationMapping.
/**
* The OperationCalls must map to Operations in Scopes inside the Flow..
*/
@Test
public void testOperationMapping() {
Statechart sc = _createStatechart("test");
InterfaceScope s_scope = _createInterfaceScope("Interface", sc);
OperationDefinition _operation = _createOperation("value", s_scope);
Region r = _createRegion("main", sc);
State s1 = _createState("S1", r);
State s2 = _createState("S2", r);
Transition t = _createTransition(s1, s2);
ReactionTrigger tr = _createReactionTrigger(t);
tr.setGuard(createGuardExpression(_createValue(true)));
ReactionEffect tr1 = _createReactionEffect(t);
FeatureCall _operationCall = _createOperationCall(_operation);
tr1.getActions().add(_operationCall);
ExecutionFlow flow = sequencer.transform(sc);
OperationDefinition _o1 = (OperationDefinition) flow.getScopes().get(0).getDeclarations().get(0);
assertNotSame(_operation, _o1);
assertEquals(_operation.getName(), _o1.getName());
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);
Step thenSequence = assertedSequence(((Call) _if.getThenStep()).getStep()).getSteps().get(1);
Execution call = (Execution) assertedSequence(thenSequence).getSteps().get(0);
assertNotSame(_operationCall, call.getStatement());
assertSame(_o1, ((FeatureCall) call.getStatement()).getFeature());
}
use of org.yakindu.sct.model.stext.stext.OperationDefinition in project statecharts by Yakindu.
the class TypeInferrerTest method testOperationCallWithOptionalParameter.
@Test
public void testOperationCallWithOptionalParameter() {
OperationDefinition opDef = StextTestFactory._createOperation("opWithOptionals", StextFactory.eINSTANCE.createInternalScope());
Parameter pReq = typesFactory.createParameter("pReq", ITypeSystem.INTEGER, false);
Parameter pOpt = typesFactory.createParameter("pOpt", ITypeSystem.INTEGER, true);
opDef.getParameters().add(pReq);
opDef.getParameters().add(pOpt);
Argument boolArg = (Argument) parseExpression("true", Argument.class.getSimpleName());
Argument intArg = (Argument) parseExpression("17", Argument.class.getSimpleName());
// opWithOptionals(17, 17) => valid
ElementReferenceExpression opCall1 = StextTestFactory._createOperationCall(opDef, intArg, intArg);
expectNoErrors(opCall1);
// opWithOptionals(17) => valid, because of optional parameter
ElementReferenceExpression opCall2 = StextTestFactory._createOperationCall(opDef, intArg);
expectNoErrors(opCall2);
// opWithOptionals(true) => invalid
ElementReferenceExpression opCall3 = StextTestFactory._createOperationCall(opDef, boolArg);
expectError(opCall3, ITypeSystemInferrer.NOT_COMPATIBLE_CODE);
}
use of org.yakindu.sct.model.stext.stext.OperationDefinition in project statecharts by Yakindu.
the class STextJavaValidatorTest method checkOptionalArgumentsAreLast.
@Test
public void checkOptionalArgumentsAreLast() {
Scope scope = (Scope) super.parseExpression("internal: ", InternalScope.class.getSimpleName());
OperationDefinition op = StextTestFactory._createOperation("op", scope);
tester.validate(scope).assertOK();
// optional parameter last => no error
op.getParameters().add(typesTestFactory.createParameter("p1", ITypeSystem.INTEGER, false));
op.getParameters().add(typesTestFactory.createParameter("p2", ITypeSystem.INTEGER, true));
tester.validate(op).assertOK();
// optional parameter not last anymore => error
op.getParameters().add(typesTestFactory.createParameter("p3", ITypeSystem.INTEGER, false));
tester.validate(op).assertError(ERROR_OPTIONAL_MUST_BE_LAST_CODE);
}
use of org.yakindu.sct.model.stext.stext.OperationDefinition 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