Search in sources :

Example 36 with Expression

use of org.yakindu.base.expressions.expressions.Expression in project statecharts by Yakindu.

the class FoldIncomingActionsRefactoring method getLastActions.

private List<Expression> getLastActions(Transition transition, int number) {
    List<Expression> lastActions = new ArrayList<Expression>();
    Effect effect = transition.getEffect();
    if (effect instanceof ReactionEffect) {
        ReactionEffect reactionEffect = (ReactionEffect) effect;
        List<Expression> actions = reactionEffect.getActions();
        for (int i = 1; i <= number; i++) {
            lastActions.add(actions.get(actions.size() - i));
        }
    }
    return lastActions;
}
Also used : Expression(org.yakindu.base.expressions.expressions.Expression) ArrayList(java.util.ArrayList) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) Effect(org.yakindu.sct.model.sgraph.Effect) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect)

Example 37 with Expression

use of org.yakindu.base.expressions.expressions.Expression in project statecharts by Yakindu.

the class FoldIncomingActionsRefactoring method removeLastActions.

private void removeLastActions(EList<Transition> transitions, int number) {
    for (Transition transition : transitions) {
        List<Expression> actionsToRemove = getLastActions(transition, number);
        Effect effect = transition.getEffect();
        if (effect instanceof ReactionEffect && actionsToRemove.size() == ((ReactionEffect) effect).getActions().size()) {
            // we need to remove all actions, so just remove the effect
            // recursively which avoids serializer exceptions
            EcoreUtil.delete(effect, true);
        } else {
            for (Expression action : actionsToRemove) {
                EcoreUtil.delete(action);
            }
        }
    }
}
Also used : Expression(org.yakindu.base.expressions.expressions.Expression) Transition(org.yakindu.sct.model.sgraph.Transition) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) Effect(org.yakindu.sct.model.sgraph.Effect) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect)

Example 38 with Expression

use of org.yakindu.base.expressions.expressions.Expression in project statecharts by Yakindu.

the class FoldIncomingActionsRefactoring method getFoldableActions.

private List<Expression> getFoldableActions() {
    EList<Transition> transitions = getContextObject().getIncomingTransitions();
    List<Expression> foldableActions = new ArrayList<Expression>();
    Expression lastFoldableAction;
    int indexFromBack = 0;
    while ((lastFoldableAction = getLastFoldableAction(helper.getAllActions(transitions), indexFromBack)) != null) {
        foldableActions.add(0, lastFoldableAction);
        indexFromBack++;
    }
    removeLastActions(transitions, indexFromBack);
    return foldableActions;
}
Also used : Expression(org.yakindu.base.expressions.expressions.Expression) Transition(org.yakindu.sct.model.sgraph.Transition) ArrayList(java.util.ArrayList)

Example 39 with Expression

use of org.yakindu.base.expressions.expressions.Expression in project statecharts by Yakindu.

the class ArgumentSorter method getOrderedExpressions.

public static EList<Expression> getOrderedExpressions(List<Argument> arguments, Operation operation) {
    Expression[] result = new Expression[arguments.size()];
    for (int index = 0; index < arguments.size(); index++) {
        Argument argument = arguments.get(index);
        List<INode> nodes = NodeModelUtils.findNodesForFeature(argument, ExpressionsPackage.Literals.ARGUMENT__PARAMETER);
        if (nodes.isEmpty()) {
            result[index] = argument.getValue();
        } else {
            // EcoreUtil.equals.)
            for (Parameter param : operation.getParameters()) {
                if (param.getName().equals(nodes.get(0).getText())) {
                    int parameterIndex = operation.getParameters().indexOf(param);
                    if (parameterIndex < result.length)
                        result[parameterIndex] = argument.getValue();
                    break;
                }
            }
        }
    }
    EList<Expression> resultAsList = new BasicEList<Expression>();
    for (int i = 0; i < result.length; i++) {
        Expression expression = result[i];
        if (expression != null)
            resultAsList.add(expression);
    }
    return resultAsList;
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) Argument(org.yakindu.base.expressions.expressions.Argument) Expression(org.yakindu.base.expressions.expressions.Expression) BasicEList(org.eclipse.emf.common.util.BasicEList) Parameter(org.yakindu.base.types.Parameter)

Example 40 with Expression

use of org.yakindu.base.expressions.expressions.Expression in project statecharts by Yakindu.

the class AssignmentExpressionImpl method basicSetVarRef.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetVarRef(Expression newVarRef, NotificationChain msgs) {
    Expression oldVarRef = varRef;
    varRef = newVarRef;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ExpressionsPackage.ASSIGNMENT_EXPRESSION__VAR_REF, oldVarRef, newVarRef);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) Expression(org.yakindu.base.expressions.expressions.Expression) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Aggregations

Expression (org.yakindu.base.expressions.expressions.Expression)48 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)24 AssignmentExpression (org.yakindu.base.expressions.expressions.AssignmentExpression)11 ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)10 ReactionEffect (org.yakindu.sct.model.stext.stext.ReactionEffect)9 EObject (org.eclipse.emf.ecore.EObject)7 FeatureCall (org.yakindu.base.expressions.expressions.FeatureCall)6 PrimitiveValueExpression (org.yakindu.base.expressions.expressions.PrimitiveValueExpression)6 Effect (org.yakindu.sct.model.sgraph.Effect)6 ArrayList (java.util.ArrayList)5 ParenthesizedExpression (org.yakindu.base.expressions.expressions.ParenthesizedExpression)5 PostFixUnaryExpression (org.yakindu.base.expressions.expressions.PostFixUnaryExpression)5 ReactionTrigger (org.yakindu.sct.model.stext.stext.ReactionTrigger)5 Test (org.junit.Test)4 ConditionalExpression (org.yakindu.base.expressions.expressions.ConditionalExpression)4 LogicalAndExpression (org.yakindu.base.expressions.expressions.LogicalAndExpression)4 LogicalOrExpression (org.yakindu.base.expressions.expressions.LogicalOrExpression)4 NumericalMultiplyDivideExpression (org.yakindu.base.expressions.expressions.NumericalMultiplyDivideExpression)4 Scope (org.yakindu.sct.model.sgraph.Scope)4 Transition (org.yakindu.sct.model.sgraph.Transition)4