Search in sources :

Example 6 with FeatureCall

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;
}
Also used : FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall)

Example 7 with FeatureCall

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());
}
Also used : ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) StextTestFactory._createInterfaceScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) StextTestFactory._createReactionEffect(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionEffect) Step(org.yakindu.sct.model.sexec.Step) Execution(org.yakindu.sct.model.sexec.Execution) StextTestFactory._createReactionTrigger(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) SGraphTestFactory._createState(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState) State(org.yakindu.sct.model.sgraph.State) Transition(org.yakindu.sct.model.sgraph.Transition) SGraphTestFactory._createTransition(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createTransition) Statechart(org.yakindu.sct.model.sgraph.Statechart) SGraphTestFactory._createStatechart(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart) Region(org.yakindu.sct.model.sgraph.Region) SGraphTestFactory._createRegion(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion) OperationDefinition(org.yakindu.sct.model.stext.stext.OperationDefinition) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) If(org.yakindu.sct.model.sexec.If) Test(org.junit.Test)

Example 8 with FeatureCall

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());
}
Also used : Execution(org.yakindu.sct.model.sexec.Execution) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) Expression(org.yakindu.base.expressions.expressions.Expression) PrimitiveValueExpression(org.yakindu.base.expressions.expressions.PrimitiveValueExpression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) NamedElement(org.yakindu.base.base.NamedElement)

Example 9 with FeatureCall

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);
            }
        }
    }
}
Also used : VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) EventRaisingExpression(org.yakindu.sct.model.stext.stext.EventRaisingExpression) Expression(org.yakindu.base.expressions.expressions.Expression) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) EventValueReferenceExpression(org.yakindu.sct.model.stext.stext.EventValueReferenceExpression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) PostFixUnaryExpression(org.yakindu.base.expressions.expressions.PostFixUnaryExpression) EObject(org.eclipse.emf.ecore.EObject) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) Check(org.eclipse.xtext.validation.Check)

Example 10 with FeatureCall

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));
        }
    }
}
Also used : VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) EventRaisingExpression(org.yakindu.sct.model.stext.stext.EventRaisingExpression) Expression(org.yakindu.base.expressions.expressions.Expression) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) EventValueReferenceExpression(org.yakindu.sct.model.stext.stext.EventValueReferenceExpression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) PostFixUnaryExpression(org.yakindu.base.expressions.expressions.PostFixUnaryExpression) QualifiedName(org.eclipse.xtext.naming.QualifiedName) EObject(org.eclipse.emf.ecore.EObject) Declaration(org.yakindu.base.types.Declaration) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) Check(org.eclipse.xtext.validation.Check)

Aggregations

FeatureCall (org.yakindu.base.expressions.expressions.FeatureCall)11 ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)9 EObject (org.eclipse.emf.ecore.EObject)8 Expression (org.yakindu.base.expressions.expressions.Expression)6 AssignmentExpression (org.yakindu.base.expressions.expressions.AssignmentExpression)5 Check (org.eclipse.xtext.validation.Check)4 NamedElement (org.yakindu.base.base.NamedElement)4 PostFixUnaryExpression (org.yakindu.base.expressions.expressions.PostFixUnaryExpression)4 EventRaisingExpression (org.yakindu.sct.model.stext.stext.EventRaisingExpression)3 EventValueReferenceExpression (org.yakindu.sct.model.stext.stext.EventValueReferenceExpression)3 InterfaceScope (org.yakindu.sct.model.stext.stext.InterfaceScope)3 Execution (org.yakindu.sct.model.sexec.Execution)2 InternalScope (org.yakindu.sct.model.stext.stext.InternalScope)2 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)2 ArrayList (java.util.ArrayList)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Keyword (org.eclipse.xtext.Keyword)1 QualifiedName (org.eclipse.xtext.naming.QualifiedName)1 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)1 IScope (org.eclipse.xtext.scoping.IScope)1