use of org.yakindu.base.expressions.expressions.FeatureCall in project statecharts by Yakindu.
the class StextTestFactory method _createOperationCall.
public static FeatureCall _createOperationCall(OperationDefinition o) {
// TODO add owner as TypedElementExpression
FeatureCall oc = ExpressionsFactory.eINSTANCE.createFeatureCall();
oc.setFeature(o);
oc.setOperationCall(true);
return oc;
}
use of org.yakindu.base.expressions.expressions.FeatureCall 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.base.expressions.expressions.FeatureCall in project statecharts by Yakindu.
the class Assert method assertAssignment.
public static void assertAssignment(Step step, String variableName, AssignmentOperator operator, String value) {
assertClass(Execution.class, step);
Execution exec = (Execution) step;
assertTrue(exec.getStatement() instanceof AssignmentExpression);
AssignmentExpression assignment = (AssignmentExpression) exec.getStatement();
assertEquals(operator, assignment.getOperator());
Expression varRef = assignment.getVarRef();
if (varRef instanceof ElementReferenceExpression) {
ElementReferenceExpression elementRef = (ElementReferenceExpression) varRef;
assertEquals(variableName, ((NamedElement) elementRef.getReference()).getName());
} else if (varRef instanceof FeatureCall) {
FeatureCall call = (FeatureCall) varRef;
assertEquals(variableName, ((NamedElement) call.getFeature()).getName());
}
assertExpressionEquals(value, assignment.getExpression());
}
use of org.yakindu.base.expressions.expressions.FeatureCall in project statecharts by Yakindu.
the class STextJavaValidator method checkValueDefinitionExpression.
@Check(CheckType.FAST)
public void checkValueDefinitionExpression(VariableDefinition definition) {
// applies only to constants
if (!definition.isConst())
return;
Expression initialValue = definition.getInitialValue();
if (initialValue == null) {
error(CONST_MUST_HAVE_VALUE_MSG, definition, null, CONST_MUST_HAVE_VALUE_CODE);
return;
}
List<Expression> toCheck = Lists.newArrayList(initialValue);
TreeIterator<EObject> eAllContents = initialValue.eAllContents();
while (eAllContents.hasNext()) {
EObject next = eAllContents.next();
if (next instanceof Expression)
toCheck.add((Expression) next);
}
for (Expression expression : toCheck) {
EObject referencedObject = null;
if (expression instanceof FeatureCall)
referencedObject = ((FeatureCall) expression).getFeature();
else if (expression instanceof ElementReferenceExpression)
referencedObject = ((ElementReferenceExpression) expression).getReference();
if (referencedObject instanceof VariableDefinition) {
if (!((VariableDefinition) referencedObject).isConst()) {
error(REFERENCE_TO_VARIABLE, StextPackage.Literals.VARIABLE_DEFINITION__INITIAL_VALUE);
}
}
}
}
use of org.yakindu.base.expressions.expressions.FeatureCall in project statecharts by Yakindu.
the class STextJavaValidator method checkValueReferenedBeforeDefined.
@Check(CheckType.NORMAL)
public void checkValueReferenedBeforeDefined(Scope scope) {
EList<Declaration> declarations = scope.getDeclarations();
Set<QualifiedName> defined = Sets.newHashSet();
for (Declaration declaration : declarations) {
if (declaration instanceof VariableDefinition) {
VariableDefinition definition = (VariableDefinition) declaration;
if (!definition.isConst())
return;
Expression initialValue = definition.getInitialValue();
List<Expression> toCheck = Lists.newArrayList(initialValue);
TreeIterator<EObject> eAllContents = initialValue.eAllContents();
while (eAllContents.hasNext()) {
EObject next = eAllContents.next();
if (next instanceof Expression)
toCheck.add((Expression) next);
}
for (Expression expression : toCheck) {
EObject referencedObject = null;
if (expression instanceof FeatureCall)
referencedObject = ((FeatureCall) expression).getFeature();
else if (expression instanceof ElementReferenceExpression)
referencedObject = ((ElementReferenceExpression) expression).getReference();
if (referencedObject instanceof VariableDefinition) {
if (!defined.contains(nameProvider.getFullyQualifiedName(referencedObject)))
error(REFERENCE_CONSTANT_BEFORE_DEFINED, definition, StextPackage.Literals.VARIABLE_DEFINITION__INITIAL_VALUE);
}
}
defined.add(nameProvider.getFullyQualifiedName(definition));
}
}
}
Aggregations