Search in sources :

Example 16 with Expression

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

the class FoldOutgoingActionsRefactoring method getFoldableActions.

private List<Expression> getFoldableActions(EList<Transition> transitions) {
    List<Expression> foldableActions = new ArrayList<Expression>();
    Expression firstFoldableAction;
    int index = 0;
    while ((firstFoldableAction = getFirstFoldableAction(helper.getAllActions(transitions), index)) != null) {
        foldableActions.add(firstFoldableAction);
        index++;
    }
    removeFirstActions(transitions, index);
    return foldableActions;
}
Also used : Expression(org.yakindu.base.expressions.expressions.Expression) ArrayList(java.util.ArrayList)

Example 17 with Expression

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

the class FoldOutgoingActionsRefactoring method removeFirstActions.

private void removeFirstActions(EList<Transition> transitions, int number) {
    for (Transition transition : transitions) {
        List<Expression> actionsToRemove = getFirstActions(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 18 with Expression

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

the class ExpressionsJavaValidator method checkAssignmentToFinalVariable.

@Check(CheckType.FAST)
public void checkAssignmentToFinalVariable(AssignmentExpression exp) {
    Expression varRef = exp.getVarRef();
    EObject referencedObject = null;
    if (varRef instanceof FeatureCall)
        referencedObject = ((FeatureCall) varRef).getFeature();
    else if (varRef instanceof ElementReferenceExpression)
        referencedObject = ((ElementReferenceExpression) varRef).getReference();
    if (referencedObject instanceof Property) {
        if (((Property) referencedObject).isConst()) {
            error(ERROR_ASSIGNMENT_TO_CONST_MSG, ExpressionsPackage.Literals.ASSIGNMENT_EXPRESSION__VAR_REF, ERROR_ASSIGNMENT_TO_CONST_CODE);
        }
    }
}
Also used : PostFixUnaryExpression(org.yakindu.base.expressions.expressions.PostFixUnaryExpression) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) Expression(org.yakindu.base.expressions.expressions.Expression) ArgumentExpression(org.yakindu.base.expressions.expressions.ArgumentExpression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) EObject(org.eclipse.emf.ecore.EObject) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) Property(org.yakindu.base.types.Property) Check(org.eclipse.xtext.validation.Check)

Example 19 with Expression

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

the class STextScopeProvider method scope_FeatureCall_feature.

public IScope scope_FeatureCall_feature(final FeatureCall context, EReference reference) {
    Predicate<IEObjectDescription> predicate = calculateFilterPredicate(context, reference);
    Expression owner = context.getOwner();
    EObject element = null;
    if (owner instanceof ElementReferenceExpression) {
        element = ((ElementReferenceExpression) owner).getReference();
    } else if (owner instanceof FeatureCall) {
        element = ((FeatureCall) owner).getFeature();
    } else {
        return getDelegate().getScope(context, reference);
    }
    IScope scope = IScope.NULLSCOPE;
    InferenceResult result = typeInferrer.infer(owner);
    Type ownerType = result != null ? result.getType() : null;
    if (element instanceof Scope) {
        scope = Scopes.scopeFor(((Scope) element).getDeclarations());
        return new FilteringScope(scope, predicate);
    } else if (ownerType != null) {
        scope = Scopes.scopeFor(typeSystem.getPropertyExtensions(ownerType));
        scope = Scopes.scopeFor(typeSystem.getOperationExtensions(ownerType), scope);
    }
    if (ownerType instanceof ComplexType) {
        return addScopeForComplexType((ComplexType) ownerType, scope, predicate);
    }
    if (ownerType instanceof EnumerationType) {
        return addScopeForEnumType((EnumerationType) ownerType, scope, predicate);
    }
    return scope;
}
Also used : InferenceResult(org.yakindu.base.types.inferrer.ITypeSystemInferrer.InferenceResult) EnumerationType(org.yakindu.base.types.EnumerationType) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) ComplexType(org.yakindu.base.types.ComplexType) EnumerationType(org.yakindu.base.types.EnumerationType) Type(org.yakindu.base.types.Type) FilteringScope(org.eclipse.xtext.scoping.impl.FilteringScope) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) Scope(org.yakindu.sct.model.sgraph.Scope) IScope(org.eclipse.xtext.scoping.IScope) SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) ImportScope(org.eclipse.xtext.scoping.impl.ImportScope) Expression(org.yakindu.base.expressions.expressions.Expression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) ComplexType(org.yakindu.base.types.ComplexType) FilteringScope(org.eclipse.xtext.scoping.impl.FilteringScope)

Example 20 with Expression

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

the class FoldIncomingActionsRefactoring method createEntryBlock.

private EList<Expression> createEntryBlock(List<Expression> actionsToAdd) {
    EList<Expression> actionsOriginal;
    LocalReaction newLocalReaction = StextFactory.eINSTANCE.createLocalReaction();
    ReactionTrigger newReactionTrigger = StextFactory.eINSTANCE.createReactionTrigger();
    EntryEvent entryEvent = StextFactory.eINSTANCE.createEntryEvent();
    ReactionEffect newReactionEffect = StextFactory.eINSTANCE.createReactionEffect();
    newLocalReaction.setTrigger(newReactionTrigger);
    newReactionTrigger.getTriggers().add(entryEvent);
    newReactionEffect.getActions().addAll(actionsToAdd);
    newLocalReaction.setEffect(newReactionEffect);
    Scope scope = getContextObject().getScopes().get(0);
    scope.getReactions().add(newLocalReaction);
    actionsOriginal = newReactionEffect.getActions();
    return actionsOriginal;
}
Also used : LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) Scope(org.yakindu.sct.model.sgraph.Scope) Expression(org.yakindu.base.expressions.expressions.Expression) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) EntryEvent(org.yakindu.sct.model.stext.stext.EntryEvent) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect)

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